Engine.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "Audio.h"
  24. #include "Console.h"
  25. #include "Context.h"
  26. #include "CoreEvents.h"
  27. #include "DebugHud.h"
  28. #include "Engine.h"
  29. #include "FileSystem.h"
  30. #include "Graphics.h"
  31. #include "Input.h"
  32. #include "Log.h"
  33. #include "Navigation.h"
  34. #include "Network.h"
  35. #include "PackageFile.h"
  36. #include "PhysicsWorld.h"
  37. #include "ProcessUtils.h"
  38. #include "Profiler.h"
  39. #include "Renderer.h"
  40. #include "ResourceCache.h"
  41. #include "Scene.h"
  42. #include "SceneEvents.h"
  43. #include "Script.h"
  44. #include "ScriptAPI.h"
  45. #include "StringUtils.h"
  46. #include "UI.h"
  47. #include "WorkQueue.h"
  48. #include "XMLFile.h"
  49. #include "DebugNew.h"
  50. #if defined(_MSC_VER) && defined(_DEBUG)
  51. // From dbgint.h
  52. #define nNoMansLandSize 4
  53. typedef struct _CrtMemBlockHeader
  54. {
  55. struct _CrtMemBlockHeader* pBlockHeaderNext;
  56. struct _CrtMemBlockHeader* pBlockHeaderPrev;
  57. char* szFileName;
  58. int nLine;
  59. size_t nDataSize;
  60. int nBlockUse;
  61. long lRequest;
  62. unsigned char gap[nNoMansLandSize];
  63. } _CrtMemBlockHeader;
  64. #endif
  65. namespace Urho3D
  66. {
  67. extern const char* logLevelPrefixes[];
  68. OBJECTTYPESTATIC(Engine);
  69. Engine::Engine(Context* context) :
  70. Object(context),
  71. timeStep_(0.0f),
  72. minFps_(10),
  73. #if defined(ANDROID) || defined(IOS)
  74. maxFps_(60),
  75. maxInactiveFps_(10),
  76. pauseMinimized_(true),
  77. #else
  78. maxFps_(200),
  79. maxInactiveFps_(60),
  80. pauseMinimized_(false),
  81. #endif
  82. initialized_(false),
  83. exiting_(false),
  84. headless_(false),
  85. audioPaused_(false)
  86. {
  87. }
  88. Engine::~Engine()
  89. {
  90. // Remove subsystems that use SDL in reverse order of construction
  91. context_->RemoveSubsystem<Audio>();
  92. context_->RemoveSubsystem<UI>();
  93. context_->RemoveSubsystem<Input>();
  94. context_->RemoveSubsystem<Renderer>();
  95. context_->RemoveSubsystem<Graphics>();
  96. }
  97. bool Engine::Initialize(const VariantMap& parameters)
  98. {
  99. if (initialized_)
  100. return true;
  101. // Set headless mode
  102. headless_ = GetParameter(parameters, "Headless", false).GetBool();
  103. // Register object factories and attributes first, then subsystems
  104. RegisterObjects();
  105. RegisterSubsystems();
  106. PROFILE(InitEngine);
  107. // Start logging
  108. Log* log = GetSubsystem<Log>();
  109. if (log)
  110. {
  111. if (HasParameter(parameters, "LogLevel"))
  112. log->SetLevel(GetParameter(parameters, "LogLevel").GetInt());
  113. log->SetQuiet(GetParameter(parameters, "LogQuiet", false).GetBool());
  114. log->Open(GetParameter(parameters, "LogName", "Urho3D.log").GetString());
  115. }
  116. // Set maximally accurate low res timer
  117. GetSubsystem<Time>()->SetTimerPeriod(1);
  118. // Configure max FPS
  119. if (GetParameter(parameters, "FrameLimiter", true) == false)
  120. SetMaxFps(0);
  121. // Set amount of worker threads according to the available physical CPU cores. Using also hyperthreaded cores results in
  122. // unpredictable extra synchronization overhead. Also reserve one core for the main thread
  123. unsigned numThreads = GetParameter(parameters, "WorkerThreads", true).GetBool() ? GetNumPhysicalCPUs() - 1 : 0;
  124. if (numThreads)
  125. {
  126. GetSubsystem<WorkQueue>()->CreateThreads(numThreads);
  127. LOGINFO(ToString("Created %u worker thread%s", numThreads, numThreads > 1 ? "s" : ""));
  128. }
  129. // Add resource paths
  130. ResourceCache* cache = GetSubsystem<ResourceCache>();
  131. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  132. String exePath = fileSystem->GetProgramDir();
  133. Vector<String> resourcePaths = GetParameter(parameters, "ResourcePaths", "CoreData;Data").GetString().Split(';');
  134. Vector<String> resourcePackages = GetParameter(parameters, "ResourcePackages").GetString().Split(';');
  135. // Prefer to add the resource paths as packages if possible
  136. for (unsigned i = 0; i < resourcePaths.Size(); ++i)
  137. {
  138. bool success = false;
  139. String packageName = exePath + resourcePaths[i] + ".pak";
  140. if (fileSystem->FileExists(packageName))
  141. {
  142. SharedPtr<PackageFile> package(new PackageFile(context_));
  143. if (package->Open(packageName))
  144. {
  145. cache->AddPackageFile(package);
  146. success = true;
  147. }
  148. }
  149. if (!success && fileSystem->DirExists(exePath + resourcePaths[i]))
  150. success = cache->AddResourceDir(exePath + resourcePaths[i]);
  151. if (!success)
  152. {
  153. LOGERROR("Failed to add resource path " + resourcePaths[i]);
  154. return false;
  155. }
  156. }
  157. // Then add specified packages
  158. for (unsigned i = 0; i < resourcePackages.Size(); ++i)
  159. {
  160. bool success = false;
  161. if (fileSystem->FileExists(exePath + resourcePackages[i]))
  162. {
  163. SharedPtr<PackageFile> package(new PackageFile(context_));
  164. if (package->Open(exePath + resourcePackages[i]))
  165. {
  166. cache->AddPackageFile(package);
  167. success = true;
  168. }
  169. }
  170. if (!success)
  171. {
  172. LOGERROR("Failed to add resource package " + resourcePackages[i]);
  173. return false;
  174. }
  175. }
  176. // Initialize graphics & audio output
  177. if (!headless_)
  178. {
  179. Graphics* graphics = GetSubsystem<Graphics>();
  180. Renderer* renderer = GetSubsystem<Renderer>();
  181. if (HasParameter(parameters, "ExternalWindow"))
  182. graphics->SetExternalWindow(GetParameter(parameters, "ExternalWindow").GetPtr());
  183. graphics->SetForceSM2(GetParameter(parameters, "ForceSM2", false).GetBool());
  184. graphics->SetWindowTitle(GetParameter(parameters, "WindowTitle", "Urho3D").GetString());
  185. if (!graphics->SetMode(
  186. GetParameter(parameters, "WindowWidth", 0).GetInt(),
  187. GetParameter(parameters, "WindowHeight", 0).GetInt(),
  188. GetParameter(parameters, "FullScreen", true).GetBool(),
  189. GetParameter(parameters, "WindowResizable", false).GetBool(),
  190. GetParameter(parameters, "VSync", false).GetBool(),
  191. GetParameter(parameters, "TripleBuffer", false).GetBool(),
  192. GetParameter(parameters, "MultiSample", 1).GetInt()
  193. ))
  194. return false;
  195. if (HasParameter(parameters, "RenderPath"))
  196. renderer->SetDefaultRenderPath(cache->GetResource<XMLFile>(GetParameter(parameters, "RenderPath").GetString()));
  197. renderer->SetDrawShadows(GetParameter(parameters, "Shadows", true).GetBool());
  198. if (renderer->GetDrawShadows() && GetParameter(parameters, "LowQualityShadows", false).GetBool())
  199. renderer->SetShadowQuality(SHADOWQUALITY_LOW_16BIT);
  200. if (GetParameter(parameters, "Sound", true).GetBool())
  201. {
  202. GetSubsystem<Audio>()->SetMode(
  203. GetParameter(parameters, "SoundBuffer", 100).GetInt(),
  204. GetParameter(parameters, "SoundMixRate", 44100).GetInt(),
  205. GetParameter(parameters, "SoundStereo", true).GetBool(),
  206. GetParameter(parameters, "SoundInterpolation", true).GetBool()
  207. );
  208. }
  209. }
  210. // Init FPU state of main thread
  211. InitFPU();
  212. frameTimer_.Reset();
  213. initialized_ = true;
  214. return true;
  215. }
  216. bool Engine::InitializeScripting()
  217. {
  218. // Check if scripting already initialized
  219. if (GetSubsystem<Script>())
  220. return true;
  221. RegisterScriptLibrary(context_);
  222. context_->RegisterSubsystem(new Script(context_));
  223. {
  224. PROFILE(RegisterScriptAPI);
  225. asIScriptEngine* engine = GetSubsystem<Script>()->GetScriptEngine();
  226. RegisterMathAPI(engine);
  227. RegisterCoreAPI(engine);
  228. RegisterIOAPI(engine);
  229. RegisterResourceAPI(engine);
  230. RegisterSceneAPI(engine);
  231. RegisterGraphicsAPI(engine);
  232. RegisterInputAPI(engine);
  233. RegisterAudioAPI(engine);
  234. RegisterUIAPI(engine);
  235. RegisterNetworkAPI(engine);
  236. RegisterPhysicsAPI(engine);
  237. RegisterNavigationAPI(engine);
  238. RegisterScriptAPI(engine);
  239. RegisterEngineAPI(engine);
  240. }
  241. return true;
  242. }
  243. void Engine::RunFrame()
  244. {
  245. assert(initialized_ && !exiting_);
  246. // Note: there is a minimal performance cost to looking up subsystems (uses a hashmap); if they would be looked up several
  247. // times per frame it would be better to cache the pointers
  248. Time* time = GetSubsystem<Time>();
  249. Input* input = GetSubsystem<Input>();
  250. Audio* audio = GetSubsystem<Audio>();
  251. time->BeginFrame(timeStep_);
  252. // If pause when minimized -mode is in use, stop updates and audio as necessary
  253. if (pauseMinimized_ && input->IsMinimized())
  254. {
  255. if (audio->IsPlaying())
  256. {
  257. audio->Stop();
  258. audioPaused_ = true;
  259. }
  260. }
  261. else
  262. {
  263. // Only unpause when it was paused by the engine
  264. if (audioPaused_)
  265. {
  266. audio->Play();
  267. audioPaused_ = false;
  268. }
  269. Update();
  270. }
  271. Render();
  272. ApplyFrameLimit();
  273. time->EndFrame();
  274. }
  275. Console* Engine::CreateConsole()
  276. {
  277. if (headless_ || !initialized_)
  278. return 0;
  279. // Return existing console if possible
  280. Console* console = GetSubsystem<Console>();
  281. if (!console)
  282. {
  283. console = new Console(context_);
  284. context_->RegisterSubsystem(console);
  285. }
  286. return console;
  287. }
  288. DebugHud* Engine::CreateDebugHud()
  289. {
  290. if (headless_ || !initialized_)
  291. return 0;
  292. // Return existing debug HUD if possible
  293. DebugHud* debugHud = GetSubsystem<DebugHud>();
  294. if (!debugHud)
  295. {
  296. debugHud = new DebugHud(context_);
  297. context_->RegisterSubsystem(debugHud);
  298. }
  299. return debugHud;
  300. }
  301. void Engine::SetMinFps(int fps)
  302. {
  303. minFps_ = Max(fps, 0);
  304. }
  305. void Engine::SetMaxFps(int fps)
  306. {
  307. maxFps_ = Max(fps, 0);
  308. }
  309. void Engine::SetMaxInactiveFps(int fps)
  310. {
  311. maxInactiveFps_ = Max(fps, 0);
  312. }
  313. void Engine::SetPauseMinimized(bool enable)
  314. {
  315. pauseMinimized_ = enable;
  316. }
  317. void Engine::Exit()
  318. {
  319. Graphics* graphics = GetSubsystem<Graphics>();
  320. if (graphics)
  321. graphics->Close();
  322. exiting_ = true;
  323. }
  324. void Engine::DumpProfiler()
  325. {
  326. Profiler* profiler = GetSubsystem<Profiler>();
  327. if (profiler)
  328. LOGRAW(profiler->GetData(true, true) + "\n");
  329. }
  330. void Engine::DumpResources()
  331. {
  332. #ifdef ENABLE_LOGGING
  333. ResourceCache* cache = GetSubsystem<ResourceCache>();
  334. const HashMap<ShortStringHash, ResourceGroup>& resourceGroups = cache->GetAllResources();
  335. LOGRAW("\n");
  336. for (HashMap<ShortStringHash, ResourceGroup>::ConstIterator i = resourceGroups.Begin();
  337. i != resourceGroups.End(); ++i)
  338. {
  339. unsigned num = i->second_.resources_.Size();
  340. unsigned memoryUse = i->second_.memoryUse_;
  341. if (num)
  342. {
  343. LOGRAW("Resource type " + i->second_.resources_.Begin()->second_->GetTypeName() +
  344. ": count " + String(num) + " memory use " + String(memoryUse) + "\n");
  345. }
  346. }
  347. LOGRAW("Total memory use of all resources " + String(cache->GetTotalMemoryUse()) + "\n\n");
  348. #endif
  349. }
  350. void Engine::DumpMemory()
  351. {
  352. #ifdef ENABLE_LOGGING
  353. #if defined(_MSC_VER) && defined(_DEBUG)
  354. _CrtMemState state;
  355. _CrtMemCheckpoint(&state);
  356. _CrtMemBlockHeader* block = state.pBlockHeader;
  357. unsigned total = 0;
  358. unsigned blocks = 0;
  359. for (;;)
  360. {
  361. if (block && block->pBlockHeaderNext)
  362. block = block->pBlockHeaderNext;
  363. else
  364. break;
  365. }
  366. while (block)
  367. {
  368. if (block->nBlockUse > 0)
  369. {
  370. if (block->szFileName)
  371. LOGRAW("Block " + String((int)block->lRequest) + ": " + String(block->nDataSize) + " bytes, file " + String(block->szFileName) + " line " + String(block->nLine) + "\n");
  372. else
  373. LOGRAW("Block " + String((int)block->lRequest) + ": " + String(block->nDataSize) + " bytes\n");
  374. total += block->nDataSize;
  375. ++blocks;
  376. }
  377. block = block->pBlockHeaderPrev;
  378. }
  379. LOGRAW("Total allocated memory " + String(total) + " bytes in " + String(blocks) + " blocks\n\n");
  380. #else
  381. LOGRAW("DumpMemory() supported on MSVC debug mode only\n\n");
  382. #endif
  383. #endif
  384. }
  385. void Engine::Update()
  386. {
  387. PROFILE(Update);
  388. // Logic update event
  389. using namespace Update;
  390. VariantMap eventData;
  391. eventData[P_TIMESTEP] = timeStep_;
  392. SendEvent(E_UPDATE, eventData);
  393. // Logic post-update event
  394. SendEvent(E_POSTUPDATE, eventData);
  395. // Rendering update event
  396. SendEvent(E_RENDERUPDATE, eventData);
  397. // Post-render update event
  398. SendEvent(E_POSTRENDERUPDATE, eventData);
  399. }
  400. void Engine::Render()
  401. {
  402. PROFILE(Render);
  403. // Do not render if device lost
  404. Graphics* graphics = GetSubsystem<Graphics>();
  405. if (!graphics || !graphics->BeginFrame())
  406. return;
  407. GetSubsystem<Renderer>()->Render();
  408. GetSubsystem<UI>()->Render();
  409. graphics->EndFrame();
  410. }
  411. void Engine::ApplyFrameLimit()
  412. {
  413. if (!initialized_)
  414. return;
  415. int maxFps = maxFps_;
  416. Input* input = GetSubsystem<Input>();
  417. if (input && !input->HasFocus())
  418. maxFps = Min(maxInactiveFps_, maxFps);
  419. long long elapsed = 0;
  420. // Perform waiting loop if maximum FPS set
  421. if (maxFps)
  422. {
  423. PROFILE(ApplyFrameLimit);
  424. long long targetMax = 1000000LL / maxFps;
  425. for (;;)
  426. {
  427. elapsed = frameTimer_.GetUSec(false);
  428. if (elapsed >= targetMax)
  429. break;
  430. // Sleep if 1 ms or more off the frame limiting goal
  431. if (targetMax - elapsed >= 1000LL)
  432. {
  433. unsigned sleepTime = (unsigned)((targetMax - elapsed) / 1000LL);
  434. Time::Sleep(sleepTime);
  435. }
  436. }
  437. }
  438. elapsed = frameTimer_.GetUSec(true);
  439. // If FPS lower than minimum, clamp elapsed time
  440. if (minFps_)
  441. {
  442. long long targetMin = 1000000LL / minFps_;
  443. if (elapsed > targetMin)
  444. elapsed = targetMin;
  445. }
  446. timeStep_ = elapsed / 1000000.0f;
  447. }
  448. VariantMap Engine::ParseParameters(const Vector<String>& arguments)
  449. {
  450. VariantMap ret;
  451. for (unsigned i = 0; i < arguments.Size(); ++i)
  452. {
  453. if (arguments[i][0] == '-' && arguments[i].Length() >= 2)
  454. {
  455. String argument = arguments[i].Substring(1).ToLower();
  456. if (argument == "headless")
  457. ret["Headless"] = true;
  458. else if (argument.Substring(0, 3) == "log")
  459. {
  460. argument = argument.Substring(3);
  461. int logLevel = GetStringListIndex(argument.CString(), logLevelPrefixes, -1);
  462. if (logLevel != -1)
  463. ret["LogLevel"] = logLevel;
  464. }
  465. else if (argument == "nolimit")
  466. ret["FrameLimiter"] = false;
  467. else if (argument == "nosound")
  468. ret["Sound"] = false;
  469. else if (argument == "noip")
  470. ret["SoundInterpolation"] = false;
  471. else if (argument == "mono")
  472. ret["SoundStereo"] = false;
  473. else if (argument == "prepass")
  474. ret["RenderPath"] = "RenderPaths/Prepass.xml";
  475. else if (argument == "deferred")
  476. ret["RenderPath"] = "RenderPaths/Deferred.xml";
  477. else if (argument == "noshadows")
  478. ret["Shadows"] = false;
  479. else if (argument == "lqshadows")
  480. ret["LowQualityShadows"] = true;
  481. else if (argument == "nothreads")
  482. ret["WorkerThreads"] = false;
  483. else if (argument == "sm2")
  484. ret["ForceSM2"] = true;
  485. else
  486. {
  487. int value;
  488. if (argument.Length() > 1)
  489. value = ToInt(argument.Substring(1));
  490. switch (tolower(argument[0]))
  491. {
  492. case 'x':
  493. ret["WindowWidth"] = value;
  494. break;
  495. case 'y':
  496. ret["WindowHeight"] = value;
  497. break;
  498. case 'm':
  499. ret["MultiSample"] = value;
  500. break;
  501. case 'b':
  502. ret["SoundBuffer"] = value;
  503. break;
  504. case 'r':
  505. ret["SoundMixRate"] = value;
  506. break;
  507. case 'v':
  508. ret["VSync"] = true;
  509. break;
  510. case 't':
  511. ret["TripleBuffer"] = true;
  512. break;
  513. case 'w':
  514. ret["FullScreen"] = false;
  515. break;
  516. case 's':
  517. ret["WindowResizable"] = true;
  518. break;
  519. case 'q':
  520. ret["LogQuiet"] = true;
  521. break;
  522. }
  523. }
  524. }
  525. }
  526. return ret;
  527. }
  528. bool Engine::HasParameter(const VariantMap& parameters, const String& parameter)
  529. {
  530. ShortStringHash nameHash(parameter);
  531. return parameters.Find(nameHash) != parameters.End();
  532. }
  533. const Variant& Engine::GetParameter(const VariantMap& parameters, const String& parameter, const Variant& defaultValue)
  534. {
  535. ShortStringHash nameHash(parameter);
  536. VariantMap::ConstIterator i = parameters.Find(nameHash);
  537. return i != parameters.End() ? i->second_ : defaultValue;
  538. }
  539. void Engine::RegisterObjects()
  540. {
  541. RegisterResourceLibrary(context_);
  542. RegisterSceneLibrary(context_);
  543. RegisterNetworkLibrary(context_);
  544. RegisterGraphicsLibrary(context_);
  545. RegisterAudioLibrary(context_);
  546. RegisterUILibrary(context_);
  547. RegisterPhysicsLibrary(context_);
  548. RegisterNavigationLibrary(context_);
  549. // In debug mode, check that all factory created objects can be created without crashing
  550. #ifdef _DEBUG
  551. const HashMap<ShortStringHash, SharedPtr<ObjectFactory> >& factories = context_->GetObjectFactories();
  552. for (HashMap<ShortStringHash, SharedPtr<ObjectFactory> >::ConstIterator i = factories.Begin(); i != factories.End(); ++i)
  553. SharedPtr<Object> object = i->second_->CreateObject();
  554. #endif
  555. }
  556. void Engine::RegisterSubsystems()
  557. {
  558. // Register self as a subsystem
  559. context_->RegisterSubsystem(this);
  560. // Create and register the rest of the subsystems
  561. context_->RegisterSubsystem(new Time(context_));
  562. context_->RegisterSubsystem(new WorkQueue(context_));
  563. #ifdef ENABLE_PROFILING
  564. context_->RegisterSubsystem(new Profiler(context_));
  565. #endif
  566. context_->RegisterSubsystem(new FileSystem(context_));
  567. context_->RegisterSubsystem(new ResourceCache(context_));
  568. context_->RegisterSubsystem(new Network(context_));
  569. if (!headless_)
  570. {
  571. context_->RegisterSubsystem(new Graphics(context_));
  572. context_->RegisterSubsystem(new Renderer(context_));
  573. }
  574. context_->RegisterSubsystem(new Input(context_));
  575. context_->RegisterSubsystem(new UI(context_));
  576. context_->RegisterSubsystem(new Audio(context_));
  577. #ifdef ENABLE_LOGGING
  578. context_->RegisterSubsystem(new Log(context_));
  579. #endif
  580. }
  581. }