c_controlInterface.cpp
Engine/source/cinterface/c_controlInterface.cpp
Public Variables
char *
bool
Public Functions
bool
torque_engineinit(S32 argc, const char ** argv)
const char *
bool
torque_resizewindow(S32 width, S32 height)
torque_setexecutablepath(const char * directory)
Detailed Description
Public Variables
char * gExecutablePath
bool LinkConsoleFunctions
Public Functions
torque_engineinit(S32 argc, const char ** argv)
torque_engineshutdown()
torque_enginesignalshutdown()
torque_enginetick()
torque_getexecutablepath()
torque_getreturnstatus()
torque_isdebugbuild()
torque_reset()
torque_resizewindow(S32 width, S32 height)
torque_setexecutablepath(const char * directory)
torque_setwebdeployment()
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "c_controlInterface.h" 25 26#include "console/consoleInternal.h" 27#include "console/simSet.h" 28#include "app/mainLoop.h" 29#include "windowManager/platformWindow.h" 30#include "windowManager/platformWindowMgr.h" 31 32#ifdef TORQUE_OS_WIN 33#include "windowManager/win32/win32Window.h" 34#include "windowManager/win32/winDispatch.h" 35extern void createFontInit(void); 36extern void createFontShutdown(void); 37#endif 38 39#if defined(TORQUE_SDL) 40#include "SDL.h" 41#endif 42 43#if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE ) 44extern S32 CreateMiniDump(LPEXCEPTION_POINTERS ExceptionInfo); 45#endif 46 47extern bool LinkConsoleFunctions; 48 49extern "C" { 50 51 // reset the engine, unloading any current level and returning to the main menu 52 void torque_reset() 53 { 54 Con::evaluate("disconnect();"); 55 } 56 57 // initialize Torque 3D including argument handling 58 bool torque_engineinit(S32 argc, const char **argv) 59 { 60 61#if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE ) 62 __try { 63#endif 64 65 LinkConsoleFunctions = true; 66 67#if defined(_MSC_VER) 68 createFontInit(); 69#endif 70 71 // Initialize the subsystems. 72 StandardMainLoop::init(); 73 74 // Handle any command line args. 75 if (!StandardMainLoop::handleCommandLine(argc, argv)) 76 { 77 Platform::AlertOK("Error", "Failed to initialize game, shutting down."); 78 return false; 79 } 80 81#if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE ) 82 } 83 84 __except (CreateMiniDump(GetExceptionInformation())) 85 { 86 _exit(0); 87 } 88#endif 89 90 return true; 91 92 } 93 94 // tick Torque 3D's main loop 95 S32 torque_enginetick() 96 { 97 98#if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE ) 99 __try { 100#endif 101 102 bool ret = StandardMainLoop::doMainLoop(); 103 return ret; 104 105#if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE ) 106 } 107 __except (CreateMiniDump(GetExceptionInformation())) 108 { 109 _exit(0); 110 } 111#endif 112 113 } 114 115 S32 torque_getreturnstatus() 116 { 117 return StandardMainLoop::getReturnStatus(); 118 } 119 120 // signal an engine shutdown (as with the quit(); console command) 121 void torque_enginesignalshutdown() 122 { 123 Con::evaluate("quit();"); 124 } 125 126 // shutdown the engine 127 S32 torque_engineshutdown() 128 { 129 130#if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE ) 131 __try { 132#endif 133 134 // Clean everything up. 135 StandardMainLoop::shutdown(); 136 137#if defined(_MSC_VER) 138 createFontShutdown(); 139#endif 140 141#if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE ) 142 } 143 144 __except (CreateMiniDump(GetExceptionInformation())) 145 { 146 _exit(0); 147 } 148#endif 149 150 // Return. 151 return true; 152 153 } 154 155 bool torque_isdebugbuild() 156 { 157#ifdef _DEBUG 158 return true; 159#else 160 return false; 161#endif 162 163 } 164 165 // set Torque 3D into web deployment mode (disable fullscreen exlusive mode, etc) 166 void torque_setwebdeployment() 167 { 168 Platform::setWebDeployment(true); 169 } 170 171 // resize the Torque 3D child window to the specified width and height 172 void torque_resizewindow(S32 width, S32 height) 173 { 174 if (PlatformWindowManager::get() && PlatformWindowManager::get()->getFirstWindow()) 175 PlatformWindowManager::get()->getFirstWindow()->setSize(Point2I(width, height)); 176 } 177 178#if defined(TORQUE_OS_WIN) && !defined(TORQUE_SDL) 179 // retrieve the hwnd of our render window 180 void* torque_gethwnd() 181 { 182 if (PlatformWindowManager::get() && PlatformWindowManager::get()->getFirstWindow()) 183 { 184 Win32Window* w = (Win32Window*)PlatformWindowManager::get()->getFirstWindow(); 185 return (void *)w->getHWND(); 186 } 187 188 return NULL; 189 } 190 191 // directly add a message to the Torque 3D event queue, bypassing the Windows event queue 192 // this is useful in the case of the IE plugin, where we are hooking into an application 193 // level message, and posting to the windows queue would cause a hang 194 void torque_directmessage(U32 message, U32 wparam, U32 lparam) 195 { 196 if (PlatformWindowManager::get() && PlatformWindowManager::get()->getFirstWindow()) 197 { 198 Win32Window* w = (Win32Window*)PlatformWindowManager::get()->getFirstWindow(); 199 Dispatch(DelayedDispatch, w->getHWND(), message, wparam, lparam); 200 } 201 } 202 203#endif 204 205#ifdef TORQUE_OS_WIN 206 void torque_inputevent(S32 type, S32 value1, S32 value2) 207 { 208 if (PlatformWindowManager::get() && PlatformWindowManager::get()->getFirstWindow()) 209 { 210 Win32Window* w = (Win32Window*)PlatformWindowManager::get()->getFirstWindow(); 211 WindowId devId = w->getWindowId(); 212 213 switch (type) 214 { 215 case 0: 216 w->mouseEvent.trigger(devId, 0, value1, value2, w->isMouseLocked()); 217 break; 218 case 1: 219 if (value2) 220 w->buttonEvent.trigger(devId, 0, IA_MAKE, value1); 221 else 222 w->buttonEvent.trigger(devId, 0, IA_BREAK, value1); 223 break; 224 225 } 226 } 227 } 228#endif 229 230 static char* gExecutablePath = NULL; 231 232 const char* torque_getexecutablepath() 233 { 234#if defined(TORQUE_SDL) 235 return gExecutablePath ? gExecutablePath : SDL_GetBasePath(); 236#elif 237 return gExecutablePath; 238#endif 239 } 240 241 void torque_setexecutablepath(const char* directory) 242 { 243 dsize_t pathLen = dStrlen(directory) + 1; 244 gExecutablePath = new char[pathLen]; 245 dStrcpy(gExecutablePath, directory, pathLen); 246 } 247} 248