Sound Bakery  v0.1.0
Open-source audio middleware for games
Loading...
Searching...
No Matches
App.h
1#pragma once
2
3#include "Managers/AppManager.h"
4#include "Managers/ProjectManager.h"
5#include "Subsystems/Subsystem.h"
6#include "Widgets/Widget.h"
7#include "pch.h"
8
9class App final
10{
11public:
12 int Run(int argc, char** argv);
13 void RequestExit();
14
15public:
16 template <class T>
17 T* AddSubsystemClass();
18
19 template <class T>
20 T* GetSubsystemByClass();
21
22 AppManager* GetAppManager() const { return m_appManager.get(); }
23 ProjectManager* GetProjectManager() const { return m_projectManager.get(); }
24
25 void OpenProject(const std::filesystem::path& projectFile);
26
27private:
28 std::vector<std::unique_ptr<Subsystem>> m_subsystems;
29 std::chrono::high_resolution_clock::time_point m_previousTime;
30 std::string m_executableLocation;
31 bool m_hasInit = false;
32 bool m_isRequestingExit = false;
33
34 std::unique_ptr<AppManager> m_appManager;
35 std::unique_ptr<ProjectManager> m_projectManager;
36};
37
38template <class T>
39T* App::AddSubsystemClass()
40{
41 m_subsystems.push_back(std::make_unique<T>(this));
42 T* subsystem = dynamic_cast<T*>(m_subsystems.back().get());
43 assert(subsystem);
44
45 if (m_hasInit)
46 {
47 subsystem->PreInit(0, NULL);
48 subsystem->Init();
49 }
50
51 return subsystem;
52}
53
54template <class T>
55T* App::GetSubsystemByClass()
56{
57 for (std::unique_ptr<Subsystem>& subsystem : m_subsystems)
58 {
59 if (T* castedSubsystem = dynamic_cast<T*>(subsystem.get()))
60 {
61 return castedSubsystem;
62 }
63 }
64 assert(false);
65 return nullptr;
66}
Definition AppManager.h:8
Definition App.h:10
Definition ProjectManager.h:36