c_controlInterface.cpp 6.6 KB

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