defaultGame.cc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 "game/defaultGame.h"
  23. #include "platform/types.h"
  24. #include "platform/Tickable.h"
  25. #include "platform/platform.h"
  26. #include "platform/platformVideo.h"
  27. #include "platform/platformInput.h"
  28. #include "platform/platformAudio.h"
  29. #include "platform/event.h"
  30. #include "game/gameInterface.h"
  31. #include "collection/vector.h"
  32. #include "math/mMath.h"
  33. #include "graphics/dgl.h"
  34. #include "graphics/gBitmap.h"
  35. #include "io/resource/resourceManager.h"
  36. #include "io/fileStream.h"
  37. #include "graphics/TextureManager.h"
  38. #include "console/console.h"
  39. #include "sim/simBase.h"
  40. #include "gui/guiCanvas.h"
  41. #include "input/actionMap.h"
  42. #include "network/connectionProtocol.h"
  43. #include "io/bitStream.h"
  44. #include "network/telnetConsole.h"
  45. #include "debug/telnetDebugger.h"
  46. #include "console/consoleTypes.h"
  47. #include "math/mathTypes.h"
  48. #include "graphics/TextureManager.h"
  49. #include "io/resource/resourceManager.h"
  50. #include "platform/platformVideo.h"
  51. #include "network/netStringTable.h"
  52. #include "memory/frameAllocator.h"
  53. #include "game/version.h"
  54. #include "debug/profiler.h"
  55. #include "network/serverQuery.h"
  56. #include "game/defaultGame.h"
  57. #include "platform/nativeDialogs/msgBox.h"
  58. #include "platform/nativeDialogs/fileDialog.h"
  59. #include "memory/safeDelete.h"
  60. #include <stdio.h>
  61. #ifndef _NETWORK_PROCESS_LIST_H_
  62. #include "network/networkProcessList.h"
  63. #endif
  64. #ifndef _REMOTE_DEBUGGER_BRIDGE_H_
  65. #include "debug/remote/RemoteDebuggerBridge.h"
  66. #endif
  67. #ifndef _MODULE_MANAGER_H
  68. #include "module/moduleManager.h"
  69. #endif
  70. #ifndef _ASSET_MANAGER_H_
  71. #include "assets/assetManager.h"
  72. #endif
  73. #ifndef _PARTICLE_SYSTEM_H_
  74. #include "2d/core/particleSystem.h"
  75. #endif
  76. #ifdef TORQUE_OS_IOS
  77. #include "platformiOS/iOSProfiler.h"
  78. #endif
  79. // Script binding.
  80. #include "platform/platform_ScriptBinding.h"
  81. //-----------------------------------------------------------------------------
  82. DefaultGame GameObject;
  83. DemoNetInterface GameNetInterface;
  84. NetworkProcessList gServerProcessList(true);
  85. StringTableEntry gMasterAddress;
  86. static F32 gTimeScale = 1.0;
  87. static U32 gTimeAdvance = 0;
  88. static U32 gFrameSkip = 0;
  89. static U32 gFrameCount = 0;
  90. // Reset frames stats.
  91. static F32 framePeriod = 0.0f;
  92. static F32 frameTotalTime = 0.0f;
  93. static F32 frameTotalLastTime = 0.0f;
  94. static U32 frameTotalCount = 0;
  95. //-----------------------------------------------------------------------------
  96. bool initializeLibraries()
  97. {
  98. PlatformAssert::create();
  99. Con::init();
  100. Sim::init();
  101. if(!Net::init())
  102. {
  103. printf("Network Error : Unable to initialize the network... aborting.");
  104. return false;
  105. }
  106. gMasterAddress = StringTable->EmptyString;
  107. Con::addVariable( "MasterServerAddress", TypeString, &gMasterAddress );
  108. // Create the stock colors.
  109. StockColor::create();
  110. #if defined(TORQUE_OS_IOS) || defined(TORQUE_OS_ANDROID)
  111. //3MB default is way too big for iPhone!!!
  112. #ifdef TORQUE_SHIPPING
  113. FrameAllocator::init(256 * 1024); //256KB for now... but let's test and see!
  114. #else
  115. FrameAllocator::init(512 * 1024); //512KB for now... but let's test and see!
  116. #endif //TORQUE_SHIPPING
  117. #else
  118. FrameAllocator::init(3 << 20); // 3 meg frame allocator buffer
  119. #endif //TORQUE_OS_IOS
  120. TextureManager::create();
  121. ResManager::create();
  122. // Register known file types here
  123. ResourceManager->registerExtension(".jpg", constructBitmapJPEG);
  124. ResourceManager->registerExtension(".jpeg", constructBitmapJPEG);
  125. ResourceManager->registerExtension(".png", constructBitmapPNG);
  126. ResourceManager->registerExtension(".uft", constructNewFont);
  127. #ifdef TORQUE_OS_IOS
  128. ResourceManager->registerExtension(".pvr", constructBitmapPVR);
  129. #endif
  130. Platform::initConsole();
  131. NetStringTable::create();
  132. TelnetConsole::create();
  133. TelnetDebugger::create();
  134. Processor::init();
  135. Math::init();
  136. Platform::init(); // platform specific initialization
  137. // Initialize the particle system.
  138. ParticleSystem::Init();
  139. #if defined(TORQUE_OS_IOS) && defined(_USE_STORE_KIT)
  140. storeInit();
  141. #endif // TORQUE_OS_IOS && _USE_STORE_KIT
  142. return true;
  143. }
  144. //--------------------------------------------------------------------------
  145. void shutdownLibraries()
  146. {
  147. // Purge any resources on the timeout list...
  148. if (ResourceManager)
  149. ResourceManager->purge();
  150. TelnetDebugger::destroy();
  151. TelnetConsole::destroy();
  152. Sim::shutdown();
  153. Platform::shutdown();
  154. NetStringTable::destroy();
  155. Con::shutdown();
  156. ResManager::destroy();
  157. TextureManager::destroy();
  158. // Destroy the stock colors.
  159. StockColor::destroy();
  160. _StringTable::destroy();
  161. // asserts should be destroyed LAST
  162. FrameAllocator::destroy();
  163. PlatformAssert::destroy();
  164. Net::shutdown();
  165. // Destroy the particle system.
  166. ParticleSystem::destroy();
  167. #ifdef _USE_STORE_KIT
  168. storeCleanup();
  169. #endif // _USE_STORE_KIT
  170. }
  171. //--------------------------------------------------------------------------
  172. bool initializeGame(int argc, const char **argv)
  173. {
  174. Con::addVariable("timeScale", TypeF32, &gTimeScale);
  175. Con::addVariable("timeAdvance", TypeS32, &gTimeAdvance);
  176. Con::addVariable("frameSkip", TypeS32, &gFrameSkip);
  177. initMessageBoxVars();
  178. // Register the module manager.
  179. ModuleDatabase.registerObject( "ModuleDatabase" );
  180. // Register the asset database.
  181. AssetDatabase.registerObject( "AssetDatabase" );
  182. // Register the asset database as a module listener.
  183. ModuleDatabase.addListener( &AssetDatabase );
  184. ActionMap* globalMap = new ActionMap;
  185. globalMap->registerObject("GlobalActionMap");
  186. Sim::getActiveActionMapSet()->pushObject(globalMap);
  187. // Let the remote debugger process the command-line.
  188. RemoteDebuggerBridge::processCommandLine( argc, argv );
  189. if(argc > 2 && dStricmp(argv[1], "-project") == 0)
  190. {
  191. char playerPath[1024];
  192. Platform::makeFullPathName(argv[2], playerPath, sizeof(playerPath));
  193. Platform::setCurrentDirectory(playerPath);
  194. argv += 2;
  195. argc -= 2;
  196. }
  197. // Scan executable location and all sub-directories.
  198. ResourceManager->setWriteablePath(Platform::getCurrentDirectory());
  199. ResourceManager->addPath( Platform::getCurrentDirectory() );
  200. FileStream scriptFileStream;
  201. Stream* scriptStream;
  202. const char* defaultScriptName = "main.cs";
  203. bool useDefaultScript = true;
  204. // Check if any command-line parameters were passed (the first is just the app name).
  205. if (argc > 1)
  206. {
  207. // If so, check if the first parameter is a file to open.
  208. if ( (scriptFileStream.open(argv[1], FileStream::Read)) && dStrncmp(argv[1], "", 1) )
  209. {
  210. // If it opens, we assume it is the script to run.
  211. useDefaultScript = false;
  212. scriptStream = &scriptFileStream;
  213. }
  214. }
  215. if (useDefaultScript)
  216. {
  217. bool success = false;
  218. success = scriptFileStream.open(defaultScriptName, FileStream::Read);
  219. if( !success )
  220. {
  221. char msg[1024];
  222. dSprintf(msg, sizeof(msg), "Failed to open \"%s\".", defaultScriptName);
  223. printf(" Error : %s", msg);
  224. return false;
  225. }
  226. scriptStream = &scriptFileStream;
  227. }
  228. // Create a script buffer.
  229. const U32 size = scriptStream->getStreamSize();
  230. char* pScriptBuffer = new char[size + 1];
  231. // Read script.
  232. scriptStream->read(size, pScriptBuffer);
  233. scriptFileStream.close();
  234. pScriptBuffer[size] = 0;
  235. char buffer[1024], *ptr;
  236. Platform::makeFullPathName(useDefaultScript ? defaultScriptName : argv[1], buffer, sizeof(buffer), Platform::getCurrentDirectory());
  237. ptr = dStrrchr( buffer, '/' );
  238. if ( ptr )
  239. *ptr = 0;
  240. Platform::setMainDotCsDir(buffer);
  241. Platform::setCurrentDirectory(buffer);
  242. const S32 errorHash = Con::getIntVariable("$ScriptErrorHash");
  243. Con::evaluate(pScriptBuffer, false, useDefaultScript ? defaultScriptName : argv[1]);
  244. delete[] pScriptBuffer;
  245. // Did an error occur?
  246. if ( errorHash != Con::getIntVariable("$ScriptErrorHash") )
  247. {
  248. printf( "Quitting as an error occurred parsing the root script '%s'.", useDefaultScript ? defaultScriptName : argv[1] );
  249. return false;
  250. }
  251. return true;
  252. }
  253. //--------------------------------------------------------------------------
  254. void shutdownGame()
  255. {
  256. // Perform pre-exit callback.
  257. if( Con::isFunction("onPreExit") )
  258. Con::executef(1, "onPreExit");
  259. // Perform the exit callback.
  260. if( Con::isFunction("onExit") )
  261. Con::executef(1, "onExit");
  262. // Unregister the module database.
  263. ModuleDatabase.unregisterObject();
  264. // Unregister the asset database.
  265. AssetDatabase.unregisterObject();
  266. }
  267. //--------------------------------------------------------------------------
  268. bool DefaultGame::mainInitialize(int argc, const char **argv)
  269. {
  270. if(!initializeLibraries())
  271. return false;
  272. // Set up the command line args for the console scripts...
  273. Con::setIntVariable("$GameProject::argc", argc);
  274. U32 i;
  275. for (i = 0; i < (U32)argc; i++)
  276. Con::setVariable(avar("$GameProject::argv%d", i), argv[i]);
  277. if (initializeGame(argc, argv) == false)
  278. {
  279. //Using printf cos Con:: is not around here.
  280. printf("\nApplication failed to start! Make sure your resources are in the correct place.");
  281. shutdownGame();
  282. shutdownLibraries();
  283. return false;
  284. }
  285. // Start processing ticks.
  286. setProcessTicks( true );
  287. #ifdef TORQUE_OS_IOS
  288. // Torque 2D does not have true, GameKit networking support.
  289. // The old socket network code is untested, undocumented and likely broken.
  290. // This will eventually be replaced with GameKit.
  291. // For now, it is confusing to even have a checkbox in the editor that no one uses or understands.
  292. // If you are one of the few that uses this, just replace the false; with the commented line. -MP 1.5
  293. //-Mat this is a bit of a hack, but if we don't want the network, we shut it off now.
  294. // We can't do it until we've run the entry script, otherwise the script variable will not have ben loaded
  295. bool usesNet = false; //dAtob( Con::getVariable( "$pref::iOS::UseNetwork" ) );
  296. if( !usesNet ) {
  297. Net::shutdown();
  298. }
  299. #ifdef TORQUE_OS_IOS_PROFILE
  300. iPhoneProfilerProfilerInit();
  301. #endif
  302. #endif
  303. #ifdef TORQUE_OS_ANDROID
  304. //-Mat this is a bit of a hack, but if we don't want the network, we shut it off now.
  305. // We can't do it until we've run the entry script, otherwise the script variable will not have ben loaded
  306. bool usesNet = false; //dAtob( Con::getVariable( "$pref::iOS::UseNetwork" ) );
  307. if( !usesNet ) {
  308. Net::shutdown();
  309. }
  310. #ifdef TORQUE_OS_ANDROID_PROFILE
  311. AndroidProfilerProfilerInit();
  312. #endif
  313. #endif
  314. return true;
  315. }
  316. //--------------------------------------------------------------------------
  317. void DefaultGame::processTick( void )
  318. {
  319. Con::setVariable( "Sim::Time", avar("%4.1f", (F32)Platform::getVirtualMilliseconds() / 1000.0f ) );
  320. // Update the frame variables periodically.
  321. static F32 lastFrameUpdate = frameTotalTime;
  322. if ( (frameTotalTime - lastFrameUpdate) > 0.25f )
  323. {
  324. Con::setVariable( "fps::framePeriod", avar("%4.1f", 1.0f / framePeriod) );
  325. Con::setVariable( "fps::frameCount", avar("%u", frameTotalCount) );
  326. lastFrameUpdate = frameTotalTime;
  327. }
  328. }
  329. //--------------------------------------------------------------------------
  330. void DefaultGame::advanceTime( F32 timeDelta )
  331. {
  332. // Update total frame time.
  333. frameTotalTime += timeDelta;
  334. // Update frame total count.
  335. frameTotalCount++;
  336. // Have we already processed a single frame?
  337. if ( frameTotalCount > 1 )
  338. {
  339. // Yes, so set the time-bias to use.
  340. const F32 timeBias = 0.01f;
  341. // Calculate the current frame period.
  342. framePeriod = framePeriod * ( 1.0f - timeBias ) + ( frameTotalTime - frameTotalLastTime ) * timeBias;
  343. }
  344. // Update last total frame time.
  345. frameTotalLastTime = frameTotalTime;
  346. }
  347. //--------------------------------------------------------------------------
  348. void DefaultGame::mainLoop( void )
  349. {
  350. #ifdef TORQUE_OS_IOS_PROFILE
  351. iPhoneProfilerStart("MAIN_LOOP");
  352. #endif
  353. #ifdef TORQUE_OS_ANDROID_PROFILE
  354. AndroidProfilerStart("MAIN_LOOP");
  355. #endif
  356. PROFILE_START(MainLoop);
  357. #ifdef TORQUE_ALLOW_JOURNALING
  358. PROFILE_START(JournalMain);
  359. Game->journalProcess();
  360. PROFILE_END();
  361. #endif // TORQUE_ALLOW_JOURNALING
  362. PROFILE_START(NetProcessMain);
  363. Net::process(); // read in all events
  364. PROFILE_END();
  365. PROFILE_START(PlatformProcessMain);
  366. Platform::process(); // keys, etc.
  367. PROFILE_END();
  368. PROFILE_START(TelconsoleProcessMain);
  369. TelConsole->process();
  370. PROFILE_END();
  371. PROFILE_START(TelDebuggerProcessMain);
  372. TelDebugger->process();
  373. PROFILE_END();
  374. PROFILE_START(TimeManagerProcessMain);
  375. TimeManager::process(); // guaranteed to produce an event
  376. PROFILE_END();
  377. PROFILE_START(GameProcessEvents);
  378. Game->processEvents(); // process all non-sim posted events.
  379. PROFILE_END();
  380. PROFILE_END();
  381. #ifdef TORQUE_OS_IOS_PROFILE
  382. iPhoneProfilerEnd("MAIN_LOOP");
  383. if(iPhoneProfilerGetCount() >= 60){
  384. iPhoneProfilerPrintAllResults();
  385. iPhoneProfilerProfilerInit();
  386. }
  387. #endif
  388. #ifdef TORQUE_OS_ANDROID_PROFILE
  389. AndroidProfilerEnd("MAIN_LOOP");
  390. if(AndroidProfilerGetCount() >= 60){
  391. AndroidProfilerPrintAllResults();
  392. AndroidProfilerProfilerInit();
  393. }
  394. #endif
  395. }
  396. //-----------------------------------------------------------------------------
  397. void DefaultGame::mainShutdown( void )
  398. {
  399. // Stop processing ticks.
  400. setProcessTicks( false );
  401. shutdownGame();
  402. shutdownLibraries();
  403. if( Game->requiresRestart() )
  404. Platform::restartInstance();
  405. }
  406. //--------------------------------------------------------------------------
  407. void DefaultGame::gameReactivate( void )
  408. {
  409. if ( !Input::isEnabled() )
  410. Input::enable();
  411. if ( !Input::isActive() )
  412. Input::reactivate();
  413. TextureManager::mDGLRender = true;
  414. if ( Canvas )
  415. Canvas->resetUpdateRegions();
  416. }
  417. //--------------------------------------------------------------------------
  418. void DefaultGame::gameDeactivate( const bool noRender )
  419. {
  420. if ( Input::isActive() )
  421. Input::deactivate();
  422. if ( Input::isEnabled() )
  423. Input::disable();
  424. if ( noRender )
  425. TextureManager::mDGLRender = false;
  426. }
  427. //--------------------------------------------------------------------------
  428. void DefaultGame::textureKill()
  429. {
  430. TextureManager::killManager();
  431. }
  432. //--------------------------------------------------------------------------
  433. void DefaultGame::textureResurrect()
  434. {
  435. TextureManager::resurrectManager();
  436. }
  437. //--------------------------------------------------------------------------
  438. void DefaultGame::refreshWindow()
  439. {
  440. if(Canvas)
  441. Canvas->resetUpdateRegions();
  442. }
  443. //--------------------------------------------------------------------------
  444. void DefaultGame::processQuitEvent()
  445. {
  446. setRunning(false);
  447. }
  448. //--------------------------------------------------------------------------
  449. void DefaultGame::processTimeEvent(TimeEvent *event)
  450. {
  451. PROFILE_START(ProcessTimeEvent);
  452. U32 elapsedTime = event->elapsedTime;
  453. if(elapsedTime > 1024)
  454. {
  455. elapsedTime = 0;
  456. }
  457. if(gTimeAdvance)
  458. {
  459. elapsedTime = gTimeAdvance;
  460. }
  461. else if ( mNotEqual( gTimeScale, 1.0f ) )
  462. {
  463. elapsedTime = (U32) (elapsedTime * gTimeScale);
  464. }
  465. {
  466. elapsedTime = elapsedTime;
  467. }
  468. Platform::advanceTime(elapsedTime);
  469. bool tickPass;
  470. PROFILE_START(ServerProcess);
  471. #ifdef TORQUE_OS_IOS_PROFILE
  472. iPhoneProfilerStart("SERVER_PROC");
  473. #endif
  474. #ifdef TORQUE_OS_ANDROID_PROFILE
  475. AndroidProfilerStart("SERVER_PROC");
  476. #endif
  477. tickPass = gServerProcessList.advanceTime(elapsedTime);
  478. #ifdef TORQUE_OS_IOS_PROFILE
  479. iPhoneProfilerEnd("SERVER_PROC");
  480. #endif
  481. #ifdef TORQUE_OS_ANDROID_PROFILE
  482. AndroidProfilerEnd("SERVER_PROC");
  483. #endif
  484. PROFILE_END();
  485. PROFILE_START(ServerNetProcess);
  486. // only send packets if a tick happened
  487. if(tickPass)
  488. GNet->processServer();
  489. PROFILE_END();
  490. PROFILE_START(SimAdvanceTime);
  491. #ifdef TORQUE_OS_IOS_PROFILE
  492. iPhoneProfilerStart("SIM_TIME");
  493. #endif
  494. #ifdef TORQUE_OS_ANDROID_PROFILE
  495. AndroidProfilerStart("SIM_TIME");
  496. #endif
  497. Sim::advanceTime(elapsedTime);
  498. #ifdef TORQUE_OS_IOS_PROFILE
  499. iPhoneProfilerEnd("SIM_TIME");
  500. #endif
  501. #ifdef TORQUE_OS_ANDROID_PROFILE
  502. AndroidProfilerEnd("SIM_TIME");
  503. #endif
  504. PROFILE_END();
  505. PROFILE_START(ClientProcess);
  506. #ifdef TORQUE_OS_IOS_PROFILE
  507. iPhoneProfilerStart("CLIENT_PROC");
  508. #endif
  509. #ifdef TORQUE_OS_ANDROID_PROFILE
  510. AndroidProfilerStart("CLIENT_PROC");
  511. #endif
  512. PROFILE_START(TickableAdvanceTime);
  513. Tickable::advanceTime(elapsedTime);
  514. PROFILE_END();
  515. // This is based on PW's stuff
  516. #ifndef NO_AUDIO_SUPPORT
  517. // Milliseconds between audio updates.
  518. const U32 AudioUpdatePeriod = 125;
  519. // alxUpdate is somewhat expensive and does not need to be updated constantly,
  520. // though it does need to be updated in real time
  521. static U32 lastAudioUpdate = 0;
  522. U32 realTime = Platform::getRealMilliseconds();
  523. if((realTime - lastAudioUpdate) >= AudioUpdatePeriod)
  524. {
  525. alxUpdate();
  526. lastAudioUpdate = realTime;
  527. }
  528. #endif
  529. #ifdef TORQUE_OS_IOS_PROFILE
  530. iPhoneProfilerEnd("CLIENT_PROC");
  531. #endif
  532. #ifdef TORQUE_OS_ANDROID_PROFILE
  533. AndroidProfilerEnd("CLIENT_PROC");
  534. #endif
  535. PROFILE_END();
  536. PROFILE_START(ClientNetProcess);
  537. GNet->processClient();
  538. PROFILE_END();
  539. if(Canvas && TextureManager::mDGLRender)
  540. {
  541. #ifdef TORQUE_OS_IOS_PROFILE
  542. iPhoneProfilerStart("GL_RENDER");
  543. #endif
  544. #ifdef TORQUE_OS_ANDROID_PROFILE
  545. AndroidProfilerStart("GL_RENDER");
  546. #endif
  547. bool preRenderOnly = false;
  548. if(gFrameSkip && gFrameCount % gFrameSkip)
  549. preRenderOnly = true;
  550. PROFILE_START(RenderFrame);
  551. Canvas->renderFrame(preRenderOnly);
  552. PROFILE_END();
  553. gFrameCount++;
  554. #ifdef TORQUE_OS_IOS_PROFILE
  555. iPhoneProfilerEnd("GL_RENDER");
  556. #endif
  557. #ifdef TORQUE_OS_ANDROID_PROFILE
  558. AndroidProfilerEnd("GL_RENDER");
  559. #endif
  560. }
  561. GNet->checkTimeouts();
  562. #ifdef TORQUE_ALLOW_MUSICPLAYER
  563. updateVolume();
  564. #endif
  565. PROFILE_END();
  566. }
  567. //--------------------------------------------------------------------------
  568. void DefaultGame::processInputEvent(InputEvent *event)
  569. {
  570. PROFILE_START(ProcessInputEvent);
  571. // [neo, 5/24/2007 - #2986]
  572. // Swapped around the order of call for global action map and canvas input
  573. // handling to give canvas first go as GlobalActionMap will eat any input
  574. // events meant for firstResponders only and as a "general" trap should really
  575. // should only be called if any "local" traps did not take it, e.g. left/right
  576. // in a text edit control should not be forwarded if the text edit has focus, etc.
  577. // Any new issues regarding input should most probably start looking here first!
  578. if(!(Canvas && Canvas->processInputEvent(event)))
  579. {
  580. if(!ActionMap::handleEventGlobal(event))
  581. {
  582. // Other input consumers here...
  583. ActionMap::handleEvent(event);
  584. }
  585. }
  586. PROFILE_END();
  587. }
  588. //-----------------------------------------------------------------------------
  589. void DefaultGame::processMouseMoveEvent(MouseMoveEvent * mEvent)
  590. {
  591. if (Canvas)
  592. Canvas->processMouseMoveEvent(mEvent);
  593. }
  594. //--------------------------------------------------------------------------
  595. void DefaultGame::processScreenTouchEvent(ScreenTouchEvent * mEvent)
  596. {
  597. if (Canvas)
  598. Canvas->processScreenTouchEvent(mEvent);
  599. }
  600. //--------------------------------------------------------------------------
  601. void DefaultGame::processConsoleEvent(ConsoleEvent *event)
  602. {
  603. char *argv[2];
  604. argv[0] = (char*)"eval";
  605. argv[1] = event->data;
  606. Sim::postCurrentEvent(Sim::getRootGroup(), new SimConsoleEvent(2, const_cast<const char**>(argv), false));
  607. }
  608. //--------------------------------------------------------------------------
  609. void DefaultGame::processPacketReceiveEvent(PacketReceiveEvent * prEvent)
  610. {
  611. GNet->processPacketReceiveEvent(prEvent);
  612. }