// // Urho3D Engine // Copyright (c) 2008-2011 Lasse Öörni // // 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 "Log.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 "Script.h" #include "ScriptAPI.h" #include "StringUtils.h" #include "UI.h" #include "WorkQueue.h" #include "DebugNew.h" OBJECTTYPESTATIC(Engine); Engine::Engine(Context* context) : Object(context), minFps_(10), maxFps_(200), maxInactiveFps_(50), timeStep_(0), initialized_(false), exiting_(false), headless_(false) { } Engine::~Engine() { } bool Engine::Initialize(const String& windowTitle, const String& logName, const Vector& arguments) { if (initialized_) return true; int width = 0; int height = 0; int multiSample = 1; int buffer = 100; int mixRate = 44100; bool fullscreen = true; bool vsync = false; bool tripleBuffer = false; bool forceSM2 = false; bool forceFallback = false; bool shadows = true; bool lqShadows = false; bool sound = true; bool stereo = true; bool interpolate = true; bool flush = true; for (unsigned i = 0; i < arguments.Size(); ++i) { if (arguments[i][0] == '-' && arguments[i].Length() >= 2) { String argument = arguments[i].Substring(1).ToLower(); if (argument == "headless") headless_ = true; else if (argument == "nolimit") SetMaxFps(0); else if (argument == "nosound") sound = false; else if (argument == "noip") interpolate = false; else if (argument == "mono") stereo = false; else if (argument == "noshadows") shadows = false; else if (argument == "lqshadows") lqShadows = true; else if (argument == "noflush") flush = false; else if (argument == "sm2") forceSM2 = true; else if (argument == "fallback") forceFallback = true; else { switch (tolower(argument[0])) { case 'x': if (arguments[i].Length() > 1) width = ToInt(argument.Substring(1)); break; case 'y': if (arguments[i].Length() > 1) height = ToInt(argument.Substring(1)); break; case 'm': if (arguments[i].Length() > 1) multiSample = ToInt(argument.Substring(1)); break; case 'b': if (arguments[i].Length() > 1) buffer = ToInt(argument.Substring(1)); break; case 'r': if (arguments[i].Length() > 1) mixRate = ToInt(argument.Substring(1)); break; case 'v': vsync = true; break; case 't': tripleBuffer = true; break; case 'f': fullscreen = true; break; case 'w': fullscreen = false; break; } } } } // Register object factories and attributes first, then subsystems RegisterObjects(); RegisterSubsystems(); // Start logging Log* log = GetSubsystem(); log->Open(logName); // Add default resource paths: CoreData package or directory, Data package or directory ResourceCache* cache = GetSubsystem(); FileSystem* fileSystem = GetSubsystem(); String exePath = fileSystem->GetProgramDir(); if (fileSystem->FileExists(exePath + "CoreData.pak")) { SharedPtr package(new PackageFile(context_)); package->Open(exePath + "CoreData.pak"); cache->AddPackageFile(package); } else if (fileSystem->DirExists(exePath + "CoreData")) cache->AddResourceDir(exePath + "CoreData"); if (fileSystem->FileExists(exePath + "Data.pak")) { SharedPtr package(new PackageFile(context_)); package->Open(exePath + "Data.pak"); cache->AddPackageFile(package); } else if (fileSystem->DirExists(exePath + "Data")) cache->AddResourceDir(exePath + "Data"); // Initialize graphics & audio output if (!headless_) { Graphics* graphics = GetSubsystem(); Renderer* renderer = GetSubsystem(); graphics->SetFlushGPU(flush); graphics->SetForceSM2(forceSM2); graphics->SetForceFallback(forceFallback); graphics->SetWindowTitle(windowTitle); if (!graphics->SetMode(width, height, fullscreen, vsync, tripleBuffer, multiSample)) return false; if (!shadows) renderer->SetDrawShadows(false); else if (lqShadows) renderer->SetShadowQuality(SHADOWQUALITY_LOW_16BIT); if (sound) GetSubsystem