c_controlInterface.cpp 6.4 KB

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