12#ifndef ECS__SYSTEM_MANAGER_H__
13#define ECS__SYSTEM_MANAGER_H__
70 void PreUpdate(
f32 dt_ms);
71 void Update(
f32 dt_ms);
72 void PostUpdate(
f32 dt_ms);
81 template<
class Predicate>
84 for (
ISystem* system : this->m_SystemWorkOrder)
108 template<
class T,
class... ARGS>
111 const u64 STID = T::STATIC_SYSTEM_TYPE_ID;
115 auto it = this->m_Systems.find(STID);
116 if ((this->m_Systems.find(STID) != this->m_Systems.end()) && (it->second !=
nullptr))
117 return (T*)it->second;
120 void* pSystemMem = this->m_SystemAllocator->
allocate(
sizeof(T),
alignof(T));
121 if (pSystemMem !=
nullptr)
124 ((T*)pSystemMem)->m_SystemManagerInstance =
this;
127 system =
new (pSystemMem)T(engine, std::forward<ARGS>(systemArgs)...);
128 this->m_Systems[STID] = system;
130 LOG_INFO(
"System \'{}\' ({} bytes) created.",
typeid(T).name(),
sizeof(T));
134 LOG_ERROR(
"Unable to create system \'{}\' ({} bytes).",
typeid(T).name(),
sizeof(T));
139 if (STID + 1 > this->m_SystemDependencyMatrix.size())
141 this->m_SystemDependencyMatrix.resize(STID + 1);
142 for (
size_t i = 0u; i < this->m_SystemDependencyMatrix.size(); ++i)
143 this->m_SystemDependencyMatrix[i].resize(STID + 1);
147 this->m_SystemWorkOrder.push_back(system);
171 template<
class System_,
class Dependency_>
174 const u64 TARGET_ID = target->GetStaticSystemTypeID();
175 const u64 DEPEND_ID = dependency->GetStaticSystemTypeID();
177 if (this->m_SystemDependencyMatrix[TARGET_ID][DEPEND_ID] !=
true)
179 this->m_SystemDependencyMatrix[TARGET_ID][DEPEND_ID] =
true;
180 LOG_INFO(
"added '{}' as dependency to '{}'", dependency->GetSystemTypeName(), target->GetSystemTypeName());
186 template<
class Target_,
class Dependency_,
class... Dependencies>
189 const u64 TARGET_ID = target->GetStaticSystemTypeID();
190 const u64 DEPEND_ID = dependency->GetStaticSystemTypeID();
192 if (this->m_SystemDependencyMatrix[TARGET_ID][DEPEND_ID] !=
true)
194 this->m_SystemDependencyMatrix[TARGET_ID][DEPEND_ID] =
true;
195 LOG_INFO(
"added '{}' as dependency to '{}'", dependency->GetSystemTypeName(), target->GetSystemTypeName());
198 this->AddSystemDependency(target,
FWD(dependencies)...);
212 void UpdateSystemWorkOrder();
232 auto it = this->m_Systems.find(T::STATIC_SYSTEM_TYPE_ID);
234 return it != this->m_Systems.end() ? (T*)it->second :
nullptr;
244 auto it = this->m_Systems.find(STID);
245 if (it != this->m_Systems.end())
247 if (it->second->m_Enabled ==
true)
251 it->second->m_Enabled =
true;
255 LOG_WARNING(
"Trying to enable system [{}], but system is not registered yet.", STID);
266 auto it = this->m_Systems.find(STID);
267 if (it != this->m_Systems.end())
269 if (it->second->m_Enabled ==
false)
273 it->second->m_Enabled =
false;
277 LOG_WARNING(
"Trying to disable system [{}], but system is not registered yet.", STID);
287 auto it = this->m_Systems.find(STID);
288 if (it != this->m_Systems.end())
290 it->second->m_UpdateInterval = interval_ms;
294 LOG_WARNING(
"Trying to change system's [{}] update interval, but system is not registered yet.", STID);
304 auto it = this->m_Systems.find(STID);
305 if (it != this->m_Systems.end())
309 if (oldPriority == newPriority)
312 it->second->m_Priority = newPriority;
319 LOG_WARNING(
"Trying to change system's [{}] priority, but system is not registered yet.", STID);
353 template<
class... ActiveSystems>
358 eastl::list<ISystem*> AS = { activeSystems... };
361 for (
int i = 0; i < this->m_SystemWorkOrder.size(); ++i)
363 if (this->m_SystemWorkOrder[i]->GetStaticSystemTypeID() == s->GetStaticSystemTypeID())
#define LOG_WARNING(format,...)
#define LOG_INFO(format,...)
#define LOG_ERROR(format,...)
virtual void * allocate(size_t size, u8 alignment) override
SystemDependencyMatrix m_SystemDependencyMatrix
eastl::vector< eastl::vector< bool > > SystemDependencyMatrix
T * AddSystem(ECSEngine &engine, ARGS &&... systemArgs)
void AddSystemDependency(Target_ target, Dependency_ dependency, Dependencies &&... dependencies)
SystemAllocator * m_SystemAllocator
SystemManager(const SystemManager &)=delete
eastl::unordered_map< u64, ISystem * > SystemRegistry
void ForEachSystem(Predicate &&pred)
void AddSystemDependency(System_ target, Dependency_ dependency)
eastl::vector< ISystem * > SystemWorkOrder
SystemManager & operator=(SystemManager &)=delete
SystemWorkStateMask GenerateActiveSystemWorkState(ActiveSystems &&... activeSystems)
SystemWorkOrder m_SystemWorkOrder
void SetSystemUpdateInterval(f32 interval_ms)
void SetSystemPriority(SystemPriority newPriority)
eastl::vector< bool > SystemWorkStateMask