galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
SystemManager.cpp
Go to the documentation of this file.
1
7
8#include <nlohmann/json.hpp>
9
10#include "SystemManager.hpp"
11
12namespace galaxy
13{
15 : m_suspended {false}
16 {
17 }
18
20 {
21 this->m_systems = std::move(sm.m_systems);
22 this->m_suspended = sm.m_suspended;
23 }
24
26 {
27 if (this != &sm)
28 {
29 this->m_systems = std::move(sm.m_systems);
30 this->m_suspended = sm.m_suspended;
31 }
32
33 return *this;
34 }
35
37 {
38 }
39
40 void SystemManager::add_system(const std::string& system)
41 {
42 auto& sf = entt::locator<SystemFactory>::value();
43 sf.create_system(system, m_systems);
44 }
45
47 {
48 if (!m_suspended)
49 {
50 for (auto&& system : m_systems)
51 {
52 system->update(em, scene);
53 }
54 }
55 }
56
57 void SystemManager::suspend() noexcept
58 {
59 m_suspended = true;
60 }
61
62 void SystemManager::resume() noexcept
63 {
64 m_suspended = false;
65 }
66
68 {
69 m_systems.clear();
70 }
71
73 {
74 return m_systems;
75 }
76
77 bool SystemManager::is_suspended() const noexcept
78 {
79 return m_suspended;
80 }
81
82 nlohmann::json SystemManager::serialize()
83 {
84 nlohmann::json json = "{}"_json;
85
86 json["systems"] = nlohmann::json::object();
87 json["systems"]["list"] = nlohmann::json::object();
88
89 for (auto i = 0; i < m_systems.size(); i++)
90 {
91 json["systems"]["list"][std::to_string(i)] = m_systems[i]->id();
92 }
93
94 json["systems"]["suspended"] = m_suspended;
95
96 return json;
97 }
98
99 void SystemManager::deserialize(const nlohmann::json& json)
100 {
101 const auto& systems = json.at("systems");
102
103 m_systems.reserve(systems.size());
104 for (const auto& [index, name] : systems.items())
105 {
106 add_system(name.get<std::string>());
107 }
108
109 m_suspended = json.at("suspended");
110 }
111} // namespace galaxy
Class for making creating and managing entities easier.
Represents a scene in a game.
Definition Scene.hpp:28
void deserialize(const nlohmann::json &json) override
Deserializes from object.
void add_system(const std::string &system)
Add a system to operate on entities in this scene.
~SystemManager() noexcept
Destructor.
void clear()
Remove all systems.
nlohmann::json serialize() override
Serializes object.
bool m_suspended
Are systems allowed to run.
SystemManager & operator=(SystemManager &&) noexcept
Move assignment operator.
void resume() noexcept
Resume all systems.
SystemManager() noexcept
Constructor.
bool is_suspended() const noexcept
Check if systems are suspended.
void suspend() noexcept
Suspend all running systems.
void update(EntityManager &em, Scene *scene)
Process all systems.
SystemStack & stack() noexcept
Get list of systems.
SystemStack m_systems
List of systems to process.
Tag.cpp galaxy.
Definition Tag.cpp:13
std::vector< std::shared_ptr< System > > SystemStack
System stack typedef.