|
@@ -115,26 +115,26 @@ Engine::Engine(Context* context) :
|
|
|
context_->RegisterSubsystem(this);
|
|
context_->RegisterSubsystem(this);
|
|
|
|
|
|
|
|
// Create subsystems which do not depend on engine initialization or startup parameters
|
|
// Create subsystems which do not depend on engine initialization or startup parameters
|
|
|
- context_->RegisterSubsystem(new Time(context_));
|
|
|
|
|
- context_->RegisterSubsystem(new WorkQueue(context_));
|
|
|
|
|
|
|
+ context_->RegisterSubsystemStatic<Time>();
|
|
|
|
|
+ context_->RegisterSubsystemStatic<WorkQueue>();
|
|
|
#ifdef URHO3D_PROFILING
|
|
#ifdef URHO3D_PROFILING
|
|
|
- context_->RegisterSubsystem(new Profiler(context_));
|
|
|
|
|
|
|
+ context_->RegisterSubsystemStatic<Profiler>();
|
|
|
#endif
|
|
#endif
|
|
|
- context_->RegisterSubsystem(new FileSystem(context_));
|
|
|
|
|
|
|
+ context_->RegisterSubsystemStatic<FileSystem>();
|
|
|
#ifdef URHO3D_LOGGING
|
|
#ifdef URHO3D_LOGGING
|
|
|
- context_->RegisterSubsystem(new Log(context_));
|
|
|
|
|
|
|
+ context_->RegisterSubsystemStatic<Log>();
|
|
|
#endif
|
|
#endif
|
|
|
- context_->RegisterSubsystem(new ResourceCache(context_));
|
|
|
|
|
- context_->RegisterSubsystem(new Localization(context_));
|
|
|
|
|
|
|
+ context_->RegisterSubsystemStatic<ResourceCache>();
|
|
|
|
|
+ context_->RegisterSubsystemStatic<Localization>();
|
|
|
#ifdef URHO3D_NETWORK
|
|
#ifdef URHO3D_NETWORK
|
|
|
- context_->RegisterSubsystem(new Network(context_));
|
|
|
|
|
|
|
+ context_->RegisterSubsystemStatic<Network>();
|
|
|
#endif
|
|
#endif
|
|
|
#ifdef URHO3D_DATABASE
|
|
#ifdef URHO3D_DATABASE
|
|
|
- context_->RegisterSubsystem(new Database(context_));
|
|
|
|
|
|
|
+ context_->RegisterSubsystemStatic<Database>();
|
|
|
#endif
|
|
#endif
|
|
|
- context_->RegisterSubsystem(new Input(context_));
|
|
|
|
|
- context_->RegisterSubsystem(new Audio(context_));
|
|
|
|
|
- context_->RegisterSubsystem(new UI(context_));
|
|
|
|
|
|
|
+ context_->RegisterSubsystemStatic<Input>();
|
|
|
|
|
+ context_->RegisterSubsystemStatic<Audio>();
|
|
|
|
|
+ context_->RegisterSubsystemStatic<UI>();
|
|
|
|
|
|
|
|
// Register object factories for libraries which are not automatically registered along with subsystem creation
|
|
// Register object factories for libraries which are not automatically registered along with subsystem creation
|
|
|
RegisterSceneLibrary(context_);
|
|
RegisterSceneLibrary(context_);
|
|
@@ -167,8 +167,8 @@ bool Engine::Initialize(const VariantMap& parameters)
|
|
|
// Register the rest of the subsystems
|
|
// Register the rest of the subsystems
|
|
|
if (!headless_)
|
|
if (!headless_)
|
|
|
{
|
|
{
|
|
|
- context_->RegisterSubsystem(new Graphics(context_));
|
|
|
|
|
- context_->RegisterSubsystem(new Renderer(context_));
|
|
|
|
|
|
|
+ context_->RegisterSubsystemStatic<Graphics>();
|
|
|
|
|
+ context_->RegisterSubsystemStatic<Renderer>();
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -426,11 +426,7 @@ bool Engine::Initialize(const VariantMap& parameters)
|
|
|
#endif
|
|
#endif
|
|
|
#ifdef URHO3D_PROFILING
|
|
#ifdef URHO3D_PROFILING
|
|
|
if (GetParameter(parameters, "EventProfiler", true).GetBool())
|
|
if (GetParameter(parameters, "EventProfiler", true).GetBool())
|
|
|
- {
|
|
|
|
|
- EventProfiler* evpr = new EventProfiler(context_);
|
|
|
|
|
- context_->RegisterSubsystem(evpr);
|
|
|
|
|
- evpr->SetActive(true);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ context_->RegisterSubsystemStatic<EventProfiler>();
|
|
|
#endif
|
|
#endif
|
|
|
frameTimer_.Reset();
|
|
frameTimer_.Reset();
|
|
|
|
|
|
|
@@ -452,13 +448,13 @@ void Engine::RunFrame()
|
|
|
|
|
|
|
|
// Note: there is a minimal performance cost to looking up subsystems (uses a hashmap); if they would be looked up several
|
|
// Note: there is a minimal performance cost to looking up subsystems (uses a hashmap); if they would be looked up several
|
|
|
// times per frame it would be better to cache the pointers
|
|
// times per frame it would be better to cache the pointers
|
|
|
- Time* time = GetSubsystem<Time>();
|
|
|
|
|
- Input* input = GetSubsystem<Input>();
|
|
|
|
|
- Audio* audio = GetSubsystem<Audio>();
|
|
|
|
|
|
|
+ Time* time = context_->GetSubsystemStatic<Time>();
|
|
|
|
|
+ Input* input = context_->GetSubsystemStatic<Input>();
|
|
|
|
|
+ Audio* audio = context_->GetSubsystemStatic<Audio>();
|
|
|
#ifdef URHO3D_PROFILING
|
|
#ifdef URHO3D_PROFILING
|
|
|
- EventProfiler* eventProfiler = GetSubsystem<EventProfiler>();
|
|
|
|
|
- if (eventProfiler)
|
|
|
|
|
- eventProfiler->BeginFrame();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (context_->GetSubsystemStatic<EventProfiler>())
|
|
|
|
|
+ context_->GetSubsystemStatic<EventProfiler>()->BeginFrame();
|
|
|
#endif
|
|
#endif
|
|
|
time->BeginFrame(timeStep_);
|
|
time->BeginFrame(timeStep_);
|
|
|
|
|
|
|
@@ -488,8 +484,8 @@ void Engine::RunFrame()
|
|
|
|
|
|
|
|
time->EndFrame();
|
|
time->EndFrame();
|
|
|
#ifdef URHO3D_PROFILING
|
|
#ifdef URHO3D_PROFILING
|
|
|
- if (eventProfiler)
|
|
|
|
|
- eventProfiler->EndFrame();
|
|
|
|
|
|
|
+ if (context_->GetSubsystemStatic<EventProfiler>())
|
|
|
|
|
+ context_->GetSubsystemStatic<EventProfiler>()->EndFrame();
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -499,14 +495,10 @@ Console* Engine::CreateConsole()
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
// Return existing console if possible
|
|
// Return existing console if possible
|
|
|
- Console* console = GetSubsystem<Console>();
|
|
|
|
|
- if (!console)
|
|
|
|
|
- {
|
|
|
|
|
- console = new Console(context_);
|
|
|
|
|
- context_->RegisterSubsystem(console);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return console;
|
|
|
|
|
|
|
+ if (!context_->GetSubsystemStatic<Console>())
|
|
|
|
|
+ context_->RegisterSubsystemStatic<Console>();
|
|
|
|
|
+
|
|
|
|
|
+ return context_->GetSubsystemStatic<Console>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
DebugHud* Engine::CreateDebugHud()
|
|
DebugHud* Engine::CreateDebugHud()
|
|
@@ -515,14 +507,10 @@ DebugHud* Engine::CreateDebugHud()
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
// Return existing debug HUD if possible
|
|
// Return existing debug HUD if possible
|
|
|
- DebugHud* debugHud = GetSubsystem<DebugHud>();
|
|
|
|
|
- if (!debugHud)
|
|
|
|
|
- {
|
|
|
|
|
- debugHud = new DebugHud(context_);
|
|
|
|
|
- context_->RegisterSubsystem(debugHud);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!context_->GetSubsystemStatic<DebugHud>())
|
|
|
|
|
+ context_->RegisterSubsystemStatic<DebugHud>();
|
|
|
|
|
|
|
|
- return debugHud;
|
|
|
|
|
|
|
+ return context_->GetSubsystemStatic<DebugHud>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Engine::SetTimeStepSmoothing(int frames)
|
|
void Engine::SetTimeStepSmoothing(int frames)
|
|
@@ -575,15 +563,14 @@ void Engine::Exit()
|
|
|
|
|
|
|
|
void Engine::DumpProfiler()
|
|
void Engine::DumpProfiler()
|
|
|
{
|
|
{
|
|
|
- Profiler* profiler = GetSubsystem<Profiler>();
|
|
|
|
|
- if (profiler)
|
|
|
|
|
- URHO3D_LOGRAW(profiler->PrintData(true, true) + "\n");
|
|
|
|
|
|
|
+ if (context_->GetSubsystemStatic<Profiler>())
|
|
|
|
|
+ URHO3D_LOGRAW(context_->GetSubsystemStatic<Profiler>()->PrintData(true, true) + "\n");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Engine::DumpResources(bool dumpFileName)
|
|
void Engine::DumpResources(bool dumpFileName)
|
|
|
{
|
|
{
|
|
|
#ifdef URHO3D_LOGGING
|
|
#ifdef URHO3D_LOGGING
|
|
|
- ResourceCache* cache = GetSubsystem<ResourceCache>();
|
|
|
|
|
|
|
+ ResourceCache* cache = context_->GetSubsystemStatic<ResourceCache>();
|
|
|
const HashMap<StringHash, ResourceGroup>& resourceGroups = cache->GetAllResources();
|
|
const HashMap<StringHash, ResourceGroup>& resourceGroups = cache->GetAllResources();
|
|
|
URHO3D_LOGRAW("\n");
|
|
URHO3D_LOGRAW("\n");
|
|
|
|
|
|
|
@@ -676,12 +663,12 @@ void Engine::Render()
|
|
|
URHO3D_PROFILE(Render);
|
|
URHO3D_PROFILE(Render);
|
|
|
|
|
|
|
|
// If device is lost, BeginFrame will fail and we skip rendering
|
|
// If device is lost, BeginFrame will fail and we skip rendering
|
|
|
- Graphics* graphics = GetSubsystem<Graphics>();
|
|
|
|
|
|
|
+ Graphics* graphics = context_->GetSubsystemStatic<Graphics>();
|
|
|
if (!graphics->BeginFrame())
|
|
if (!graphics->BeginFrame())
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
- GetSubsystem<Renderer>()->Render();
|
|
|
|
|
- GetSubsystem<UI>()->Render();
|
|
|
|
|
|
|
+ context_->GetSubsystemStatic<Renderer>()->Render();
|
|
|
|
|
+ context_->GetSubsystemStatic<UI>()->Render();
|
|
|
graphics->EndFrame();
|
|
graphics->EndFrame();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -691,7 +678,7 @@ void Engine::ApplyFrameLimit()
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
unsigned maxFps = maxFps_;
|
|
unsigned maxFps = maxFps_;
|
|
|
- Input* input = GetSubsystem<Input>();
|
|
|
|
|
|
|
+ Input* input = context_->GetSubsystemStatic<Input>();
|
|
|
if (input && !input->HasFocus())
|
|
if (input && !input->HasFocus())
|
|
|
maxFps = Min(maxInactiveFps_, maxFps);
|
|
maxFps = Min(maxInactiveFps_, maxFps);
|
|
|
|
|
|
|
@@ -936,7 +923,7 @@ void Engine::HandleExitRequested(StringHash eventType, VariantMap& eventData)
|
|
|
|
|
|
|
|
void Engine::DoExit()
|
|
void Engine::DoExit()
|
|
|
{
|
|
{
|
|
|
- Graphics* graphics = GetSubsystem<Graphics>();
|
|
|
|
|
|
|
+ Graphics* graphics = context_->GetSubsystemStatic<Graphics>();
|
|
|
if (graphics)
|
|
if (graphics)
|
|
|
graphics->Close();
|
|
graphics->Close();
|
|
|
|
|
|