c_controlInterface.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/engineAPI.h"
  25. #include "console/simSet.h"
  26. #include "app/mainLoop.h"
  27. #include "windowManager/platformWindow.h"
  28. #include "windowManager/platformWindowMgr.h"
  29. #ifdef TORQUE_OS_WIN
  30. #include "windowManager/win32/win32Window.h"
  31. #include "windowManager/win32/winDispatch.h"
  32. extern void createFontInit(void);
  33. extern void createFontShutdown(void);
  34. #endif
  35. #if defined(TORQUE_SDL)
  36. #include "SDL.h"
  37. #endif
  38. #if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE )
  39. extern S32 CreateMiniDump(LPEXCEPTION_POINTERS ExceptionInfo);
  40. #endif
  41. extern bool LinkConsoleFunctions;
  42. extern "C" {
  43. // reset the engine, unloading any current level and returning to the main menu
  44. void torque_reset()
  45. {
  46. Con::executef("disconnect");
  47. }
  48. // initialize Torque 3D including argument handling
  49. bool torque_engineinit(S32 argc, const char **argv)
  50. {
  51. #if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE )
  52. __try {
  53. #endif
  54. LinkConsoleFunctions = true;
  55. #if defined(_MSC_VER)
  56. createFontInit();
  57. #endif
  58. // Initialize the subsystems.
  59. StandardMainLoop::init();
  60. // Handle any command line args.
  61. if (!StandardMainLoop::handleCommandLine(argc, argv))
  62. {
  63. Platform::AlertOK("Error", "Failed to initialize game, shutting down.");
  64. return false;
  65. }
  66. #if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE )
  67. }
  68. __except (CreateMiniDump(GetExceptionInformation()))
  69. {
  70. _exit(0);
  71. }
  72. #endif
  73. return true;
  74. }
  75. // tick Torque 3D's main loop
  76. S32 torque_enginetick()
  77. {
  78. #if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE )
  79. __try {
  80. #endif
  81. bool ret = StandardMainLoop::doMainLoop();
  82. return ret;
  83. #if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE )
  84. }
  85. __except (CreateMiniDump(GetExceptionInformation()))
  86. {
  87. _exit(0);
  88. }
  89. #endif
  90. }
  91. S32 torque_getreturnstatus()
  92. {
  93. return StandardMainLoop::getReturnStatus();
  94. }
  95. // signal an engine shutdown (as with the quit(); console command)
  96. void torque_enginesignalshutdown()
  97. {
  98. Con::executef("quit");
  99. }
  100. // shutdown the engine
  101. S32 torque_engineshutdown()
  102. {
  103. #if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE )
  104. __try {
  105. #endif
  106. // Clean everything up.
  107. StandardMainLoop::shutdown();
  108. #if defined(_MSC_VER)
  109. createFontShutdown();
  110. #endif
  111. #if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE )
  112. }
  113. __except (CreateMiniDump(GetExceptionInformation()))
  114. {
  115. _exit(0);
  116. }
  117. #endif
  118. // Return.
  119. return true;
  120. }
  121. bool torque_isdebugbuild()
  122. {
  123. #ifdef _DEBUG
  124. return true;
  125. #else
  126. return false;
  127. #endif
  128. }
  129. // set Torque 3D into web deployment mode (disable fullscreen exlusive mode, etc)
  130. void torque_setwebdeployment()
  131. {
  132. Platform::setWebDeployment(true);
  133. }
  134. // resize the Torque 3D child window to the specified width and height
  135. void torque_resizewindow(S32 width, S32 height)
  136. {
  137. if (PlatformWindowManager::get() && PlatformWindowManager::get()->getFirstWindow())
  138. PlatformWindowManager::get()->getFirstWindow()->setSize(Point2I(width, height));
  139. }
  140. #if defined(TORQUE_OS_WIN) && !defined(TORQUE_SDL)
  141. // retrieve the hwnd of our render window
  142. void* torque_gethwnd()
  143. {
  144. if (PlatformWindowManager::get() && PlatformWindowManager::get()->getFirstWindow())
  145. {
  146. Win32Window* w = (Win32Window*)PlatformWindowManager::get()->getFirstWindow();
  147. return (void *)w->getHWND();
  148. }
  149. return NULL;
  150. }
  151. // directly add a message to the Torque 3D event queue, bypassing the Windows event queue
  152. // this is useful in the case of the IE plugin, where we are hooking into an application
  153. // level message, and posting to the windows queue would cause a hang
  154. void torque_directmessage(U32 message, U32 wparam, U32 lparam)
  155. {
  156. if (PlatformWindowManager::get() && PlatformWindowManager::get()->getFirstWindow())
  157. {
  158. Win32Window* w = (Win32Window*)PlatformWindowManager::get()->getFirstWindow();
  159. Dispatch(DelayedDispatch, w->getHWND(), message, wparam, lparam);
  160. }
  161. }
  162. #endif
  163. #ifdef TORQUE_OS_WIN
  164. void torque_inputevent(S32 type, S32 value1, S32 value2)
  165. {
  166. if (PlatformWindowManager::get() && PlatformWindowManager::get()->getFirstWindow())
  167. {
  168. Win32Window* w = (Win32Window*)PlatformWindowManager::get()->getFirstWindow();
  169. WindowId devId = w->getWindowId();
  170. switch (type)
  171. {
  172. case 0:
  173. w->mouseEvent.trigger(devId, 0, value1, value2, w->isMouseLocked());
  174. break;
  175. case 1:
  176. if (value2)
  177. w->buttonEvent.trigger(devId, 0, IA_MAKE, value1);
  178. else
  179. w->buttonEvent.trigger(devId, 0, IA_BREAK, value1);
  180. break;
  181. }
  182. }
  183. }
  184. #endif
  185. static char* gExecutablePath = NULL;
  186. const char* torque_getexecutablepath()
  187. {
  188. #if defined(TORQUE_SDL)
  189. return gExecutablePath ? gExecutablePath : SDL_GetBasePath();
  190. #elif
  191. return gExecutablePath;
  192. #endif
  193. }
  194. void torque_setexecutablepath(const char* directory)
  195. {
  196. dsize_t pathLen = dStrlen(directory) + 1;
  197. gExecutablePath = new char[pathLen];
  198. dStrcpy(gExecutablePath, directory, pathLen);
  199. }
  200. }