defaultGame.cc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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) || defined(TORQUE_OS_EMSCRIPTEN)
  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. #ifdef TORQUE_OS_EMSCRIPTEN
  273. // temp hack
  274. argc = 0;
  275. #endif
  276. // Set up the command line args for the console scripts...
  277. Con::setIntVariable("$GameProject::argc", argc);
  278. U32 i;
  279. for (i = 0; i < (U32)argc; i++)
  280. Con::setVariable(avar("$GameProject::argv%d", i), argv[i]);
  281. if (initializeGame(argc, argv) == false)
  282. {
  283. //Using printf cos Con:: is not around here.
  284. printf("\nApplication failed to start! Make sure your resources are in the correct place.");
  285. shutdownGame();
  286. shutdownLibraries();
  287. return false;
  288. }
  289. // Start processing ticks.
  290. setProcessTicks( true );
  291. #ifdef TORQUE_OS_IOS
  292. // Torque 2D does not have true, GameKit networking support.
  293. // The old socket network code is untested, undocumented and likely broken.
  294. // This will eventually be replaced with GameKit.
  295. // For now, it is confusing to even have a checkbox in the editor that no one uses or understands.
  296. // If you are one of the few that uses this, just replace the false; with the commented line. -MP 1.5
  297. //-Mat this is a bit of a hack, but if we don't want the network, we shut it off now.
  298. // We can't do it until we've run the entry script, otherwise the script variable will not have ben loaded
  299. bool usesNet = false; //dAtob( Con::getVariable( "$pref::iOS::UseNetwork" ) );
  300. if( !usesNet ) {
  301. Net::shutdown();
  302. }
  303. #ifdef TORQUE_OS_IOS_PROFILE
  304. iPhoneProfilerProfilerInit();
  305. #endif
  306. #endif
  307. #ifdef TORQUE_OS_ANDROID
  308. //-Mat this is a bit of a hack, but if we don't want the network, we shut it off now.
  309. // We can't do it until we've run the entry script, otherwise the script variable will not have ben loaded
  310. bool usesNet = false; //dAtob( Con::getVariable( "$pref::iOS::UseNetwork" ) );
  311. if( !usesNet ) {
  312. Net::shutdown();
  313. }
  314. #ifdef TORQUE_OS_ANDROID_PROFILE
  315. AndroidProfilerProfilerInit();
  316. #endif
  317. #endif
  318. return true;
  319. }
  320. //--------------------------------------------------------------------------
  321. void DefaultGame::processTick( void )
  322. {
  323. Con::setVariable( "Sim::Time", avar("%4.1f", (F32)Platform::getVirtualMilliseconds() / 1000.0f ) );
  324. // Update the frame variables periodically.
  325. static F32 lastFrameUpdate = frameTotalTime;
  326. if ( (frameTotalTime - lastFrameUpdate) > 0.25f )
  327. {
  328. Con::setVariable( "fps::framePeriod", avar("%4.1f", 1.0f / framePeriod) );
  329. Con::setVariable( "fps::frameCount", avar("%u", frameTotalCount) );
  330. lastFrameUpdate = frameTotalTime;
  331. }
  332. }
  333. //--------------------------------------------------------------------------
  334. void DefaultGame::advanceTime( F32 timeDelta )
  335. {
  336. // Update total frame time.
  337. frameTotalTime += timeDelta;
  338. // Update frame total count.
  339. frameTotalCount++;
  340. // Have we already processed a single frame?
  341. if ( frameTotalCount > 1 )
  342. {
  343. // Yes, so set the time-bias to use.
  344. const F32 timeBias = 0.01f;
  345. // Calculate the current frame period.
  346. framePeriod = framePeriod * ( 1.0f - timeBias ) + ( frameTotalTime - frameTotalLastTime ) * timeBias;
  347. }
  348. // Update last total frame time.
  349. frameTotalLastTime = frameTotalTime;
  350. }
  351. //--------------------------------------------------------------------------
  352. void DefaultGame::mainLoop( void )
  353. {
  354. #ifdef TORQUE_OS_IOS_PROFILE
  355. iPhoneProfilerStart("MAIN_LOOP");
  356. #endif
  357. #ifdef TORQUE_OS_ANDROID_PROFILE
  358. AndroidProfilerStart("MAIN_LOOP");
  359. #endif
  360. PROFILE_START(MainLoop);
  361. #ifdef TORQUE_ALLOW_JOURNALING
  362. PROFILE_START(JournalMain);
  363. Game->journalProcess();
  364. PROFILE_END();
  365. #endif // TORQUE_ALLOW_JOURNALING
  366. PROFILE_START(NetProcessMain);
  367. Net::process(); // read in all events
  368. PROFILE_END();
  369. PROFILE_START(PlatformProcessMain);
  370. Platform::process(); // keys, etc.
  371. PROFILE_END();
  372. PROFILE_START(TelconsoleProcessMain);
  373. TelConsole->process();
  374. PROFILE_END();
  375. PROFILE_START(TelDebuggerProcessMain);
  376. TelDebugger->process();
  377. PROFILE_END();
  378. PROFILE_START(TimeManagerProcessMain);
  379. TimeManager::process(); // guaranteed to produce an event
  380. PROFILE_END();
  381. PROFILE_START(GameProcessEvents);
  382. Game->processEvents(); // process all non-sim posted events.
  383. PROFILE_END();
  384. PROFILE_END();
  385. #ifdef TORQUE_OS_IOS_PROFILE
  386. iPhoneProfilerEnd("MAIN_LOOP");
  387. if(iPhoneProfilerGetCount() >= 60){
  388. iPhoneProfilerPrintAllResults();
  389. iPhoneProfilerProfilerInit();
  390. }
  391. #endif
  392. #ifdef TORQUE_OS_ANDROID_PROFILE
  393. AndroidProfilerEnd("MAIN_LOOP");
  394. if(AndroidProfilerGetCount() >= 60){
  395. AndroidProfilerPrintAllResults();
  396. AndroidProfilerProfilerInit();
  397. }
  398. #endif
  399. }
  400. //-----------------------------------------------------------------------------
  401. void DefaultGame::mainShutdown( void )
  402. {
  403. // Stop processing ticks.
  404. setProcessTicks( false );
  405. shutdownGame();
  406. shutdownLibraries();
  407. if( Game->requiresRestart() )
  408. Platform::restartInstance();
  409. }
  410. //--------------------------------------------------------------------------
  411. void DefaultGame::gameReactivate( void )
  412. {
  413. if ( !Input::isEnabled() )
  414. Input::enable();
  415. if ( !Input::isActive() )
  416. Input::reactivate();
  417. TextureManager::mDGLRender = true;
  418. if ( Canvas )
  419. Canvas->resetUpdateRegions();
  420. }
  421. //--------------------------------------------------------------------------
  422. void DefaultGame::gameDeactivate( const bool noRender )
  423. {
  424. if ( Input::isActive() )
  425. Input::deactivate();
  426. if ( Input::isEnabled() )
  427. Input::disable();
  428. if ( noRender )
  429. TextureManager::mDGLRender = false;
  430. }
  431. //--------------------------------------------------------------------------
  432. void DefaultGame::textureKill()
  433. {
  434. TextureManager::killManager();
  435. }
  436. //--------------------------------------------------------------------------
  437. void DefaultGame::textureResurrect()
  438. {
  439. TextureManager::resurrectManager();
  440. }
  441. //--------------------------------------------------------------------------
  442. void DefaultGame::refreshWindow()
  443. {
  444. if(Canvas)
  445. Canvas->resetUpdateRegions();
  446. }
  447. //--------------------------------------------------------------------------
  448. void DefaultGame::processQuitEvent()
  449. {
  450. setRunning(false);
  451. }
  452. //--------------------------------------------------------------------------
  453. void DefaultGame::processTimeEvent(TimeEvent *event)
  454. {
  455. PROFILE_START(ProcessTimeEvent);
  456. U32 elapsedTime = event->elapsedTime;
  457. if(elapsedTime > 1024)
  458. {
  459. elapsedTime = 0;
  460. }
  461. if(gTimeAdvance)
  462. {
  463. elapsedTime = gTimeAdvance;
  464. }
  465. else if ( mNotEqual( gTimeScale, 1.0f ) )
  466. {
  467. elapsedTime = (U32) (elapsedTime * gTimeScale);
  468. }
  469. {
  470. elapsedTime = elapsedTime;
  471. }
  472. Platform::advanceTime(elapsedTime);
  473. bool tickPass;
  474. PROFILE_START(ServerProcess);
  475. #ifdef TORQUE_OS_IOS_PROFILE
  476. iPhoneProfilerStart("SERVER_PROC");
  477. #endif
  478. #ifdef TORQUE_OS_ANDROID_PROFILE
  479. AndroidProfilerStart("SERVER_PROC");
  480. #endif
  481. tickPass = gServerProcessList.advanceTime(elapsedTime);
  482. #ifdef TORQUE_OS_IOS_PROFILE
  483. iPhoneProfilerEnd("SERVER_PROC");
  484. #endif
  485. #ifdef TORQUE_OS_ANDROID_PROFILE
  486. AndroidProfilerEnd("SERVER_PROC");
  487. #endif
  488. PROFILE_END();
  489. PROFILE_START(ServerNetProcess);
  490. // only send packets if a tick happened
  491. if(tickPass)
  492. GNet->processServer();
  493. PROFILE_END();
  494. PROFILE_START(SimAdvanceTime);
  495. #ifdef TORQUE_OS_IOS_PROFILE
  496. iPhoneProfilerStart("SIM_TIME");
  497. #endif
  498. #ifdef TORQUE_OS_ANDROID_PROFILE
  499. AndroidProfilerStart("SIM_TIME");
  500. #endif
  501. Sim::advanceTime(elapsedTime);
  502. #ifdef TORQUE_OS_IOS_PROFILE
  503. iPhoneProfilerEnd("SIM_TIME");
  504. #endif
  505. #ifdef TORQUE_OS_ANDROID_PROFILE
  506. AndroidProfilerEnd("SIM_TIME");
  507. #endif
  508. PROFILE_END();
  509. PROFILE_START(ClientProcess);
  510. #ifdef TORQUE_OS_IOS_PROFILE
  511. iPhoneProfilerStart("CLIENT_PROC");
  512. #endif
  513. #ifdef TORQUE_OS_ANDROID_PROFILE
  514. AndroidProfilerStart("CLIENT_PROC");
  515. #endif
  516. PROFILE_START(TickableAdvanceTime);
  517. Tickable::advanceTime(elapsedTime);
  518. PROFILE_END();
  519. // Milliseconds between audio updates.
  520. const U32 AudioUpdatePeriod = 125;
  521. // alxUpdate is somewhat expensive and does not need to be updated constantly,
  522. // though it does need to be updated in real time
  523. static U32 lastAudioUpdate = 0;
  524. U32 realTime = Platform::getRealMilliseconds();
  525. if((realTime - lastAudioUpdate) >= AudioUpdatePeriod)
  526. {
  527. alxUpdate();
  528. lastAudioUpdate = realTime;
  529. }
  530. #ifdef TORQUE_OS_IOS_PROFILE
  531. iPhoneProfilerEnd("CLIENT_PROC");
  532. #endif
  533. #ifdef TORQUE_OS_ANDROID_PROFILE
  534. AndroidProfilerEnd("CLIENT_PROC");
  535. #endif
  536. PROFILE_END();
  537. PROFILE_START(ClientNetProcess);
  538. GNet->processClient();
  539. PROFILE_END();
  540. if(Canvas && TextureManager::mDGLRender)
  541. {
  542. #ifdef TORQUE_OS_IOS_PROFILE
  543. iPhoneProfilerStart("GL_RENDER");
  544. #endif
  545. #ifdef TORQUE_OS_ANDROID_PROFILE
  546. AndroidProfilerStart("GL_RENDER");
  547. #endif
  548. bool preRenderOnly = false;
  549. if(gFrameSkip && gFrameCount % gFrameSkip)
  550. preRenderOnly = true;
  551. PROFILE_START(RenderFrame);
  552. Canvas->renderFrame(preRenderOnly);
  553. PROFILE_END();
  554. gFrameCount++;
  555. #ifdef TORQUE_OS_IOS_PROFILE
  556. iPhoneProfilerEnd("GL_RENDER");
  557. #endif
  558. #ifdef TORQUE_OS_ANDROID_PROFILE
  559. AndroidProfilerEnd("GL_RENDER");
  560. #endif
  561. }
  562. GNet->checkTimeouts();
  563. #ifdef TORQUE_ALLOW_MUSICPLAYER
  564. updateVolume();
  565. #endif
  566. PROFILE_END();
  567. }
  568. //--------------------------------------------------------------------------
  569. void DefaultGame::processInputEvent(InputEvent *event)
  570. {
  571. PROFILE_START(ProcessInputEvent);
  572. // [neo, 5/24/2007 - #2986]
  573. // Swapped around the order of call for global action map and canvas input
  574. // handling to give canvas first go as GlobalActionMap will eat any input
  575. // events meant for firstResponders only and as a "general" trap should really
  576. // should only be called if any "local" traps did not take it, e.g. left/right
  577. // in a text edit control should not be forwarded if the text edit has focus, etc.
  578. // Any new issues regarding input should most probably start looking here first!
  579. if(!(Canvas && Canvas->processInputEvent(event)))
  580. {
  581. if(!ActionMap::handleEventGlobal(event))
  582. {
  583. // Other input consumers here...
  584. ActionMap::handleEvent(event);
  585. }
  586. }
  587. PROFILE_END();
  588. }
  589. //-----------------------------------------------------------------------------
  590. void DefaultGame::processMouseMoveEvent(MouseMoveEvent * mEvent)
  591. {
  592. if (Canvas)
  593. Canvas->processMouseMoveEvent(mEvent);
  594. }
  595. //--------------------------------------------------------------------------
  596. void DefaultGame::processScreenTouchEvent(ScreenTouchEvent * mEvent)
  597. {
  598. if (Canvas)
  599. Canvas->processScreenTouchEvent(mEvent);
  600. }
  601. //--------------------------------------------------------------------------
  602. void DefaultGame::processConsoleEvent(ConsoleEvent *event)
  603. {
  604. char *argv[2];
  605. argv[0] = (char*)"eval";
  606. argv[1] = event->data;
  607. Sim::postCurrentEvent(Sim::getRootGroup(), new SimConsoleEvent(2, const_cast<const char**>(argv), false));
  608. }
  609. //--------------------------------------------------------------------------
  610. void DefaultGame::processPacketReceiveEvent(PacketReceiveEvent * prEvent)
  611. {
  612. GNet->processPacketReceiveEvent(prEvent);
  613. }