// // Copyright (c) 2008-2013 the Urho3D project. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // #include "Precompiled.h" #include "Audio.h" #include "Console.h" #include "Context.h" #include "CoreEvents.h" #include "DebugHud.h" #include "Engine.h" #include "FileSystem.h" #include "Graphics.h" #include "Input.h" #include "InputEvents.h" #include "Log.h" #include "Navigation.h" #include "Network.h" #include "PackageFile.h" #include "PhysicsWorld.h" #include "ProcessUtils.h" #include "Profiler.h" #include "Renderer.h" #include "ResourceCache.h" #include "Scene.h" #include "SceneEvents.h" #include "StringUtils.h" #include "UI.h" #include "WorkQueue.h" #include "XMLFile.h" #include "DebugNew.h" #if defined(_MSC_VER) && defined(_DEBUG) // From dbgint.h #define nNoMansLandSize 4 typedef struct _CrtMemBlockHeader { struct _CrtMemBlockHeader* pBlockHeaderNext; struct _CrtMemBlockHeader* pBlockHeaderPrev; char* szFileName; int nLine; size_t nDataSize; int nBlockUse; long lRequest; unsigned char gap[nNoMansLandSize]; } _CrtMemBlockHeader; #endif #ifdef ANDROID extern "C" { void Android_JNI_FinishActivity(); } #endif namespace Urho3D { extern const char* logLevelPrefixes[]; Engine::Engine(Context* context) : Object(context), timeStep_(0.0f), timeStepSmoothing_(2), minFps_(10), #if defined(ANDROID) || defined(IOS) || defined(RASPI) maxFps_(60), maxInactiveFps_(10), pauseMinimized_(true), #else maxFps_(200), maxInactiveFps_(60), pauseMinimized_(false), #endif autoExit_(true), initialized_(false), #ifdef ANDROID exitRequested_(false), #endif exiting_(false), headless_(false), audioPaused_(false) { // Register self as a subsystem context_->RegisterSubsystem(this); // Create subsystems which do not depend on engine initialization or startup parameters context_->RegisterSubsystem(new Time(context_)); context_->RegisterSubsystem(new WorkQueue(context_)); #ifdef ENABLE_PROFILING context_->RegisterSubsystem(new Profiler(context_)); #endif context_->RegisterSubsystem(new FileSystem(context_)); #ifdef ENABLE_LOGGING context_->RegisterSubsystem(new Log(context_)); #endif context_->RegisterSubsystem(new ResourceCache(context_)); context_->RegisterSubsystem(new Network(context_)); context_->RegisterSubsystem(new Input(context_)); context_->RegisterSubsystem(new Audio(context_)); context_->RegisterSubsystem(new UI(context_)); // Register object factories for libraries which are not automatically registered along with subsystem creation RegisterSceneLibrary(context_); RegisterPhysicsLibrary(context_); RegisterNavigationLibrary(context_); SubscribeToEvent(E_EXITREQUESTED, HANDLER(Engine, HandleExitRequested)); } Engine::~Engine() { } bool Engine::Initialize(const VariantMap& parameters) { if (initialized_) return true; PROFILE(InitEngine); // Set headless mode headless_ = GetParameter(parameters, "Headless", false).GetBool(); // Register the rest of the subsystems if (!headless_) { context_->RegisterSubsystem(new Graphics(context_)); context_->RegisterSubsystem(new Renderer(context_)); } else { // Register graphics library objects explicitly in headless mode to allow them to work without using actual GPU resources RegisterGraphicsLibrary(context_); } // In debug mode, check now that all factory created objects can be created without crashing #ifdef _DEBUG const HashMap >& factories = context_->GetObjectFactories(); for (HashMap >::ConstIterator i = factories.Begin(); i != factories.End(); ++i) SharedPtr object = i->second_->CreateObject(); #endif // Start logging Log* log = GetSubsystem(); if (log) { if (HasParameter(parameters, "LogLevel")) log->SetLevel(GetParameter(parameters, "LogLevel").GetInt()); log->SetQuiet(GetParameter(parameters, "LogQuiet", false).GetBool()); log->Open(GetParameter(parameters, "LogName", "Urho3D.log").GetString()); } // Set maximally accurate low res timer GetSubsystem