21 LOG_INFO(
"Initialize SystemManager!",
"");
29 for (SystemWorkOrder::reverse_iterator it = this->
m_SystemWorkOrder.rbegin(); it != this->m_SystemWorkOrder.rend(); ++it)
43 LOG_INFO(
"Release SystemManager!",
"");
53 system->m_TimeSinceLastUpdate += dt_ms;
56 system->m_NeedsUpdate = (system->m_UpdateInterval < 0.0f) || ((system->m_UpdateInterval > 0.0f) && (system->m_TimeSinceLastUpdate > system->m_UpdateInterval));
58 if (system->m_Enabled ==
true && system->m_NeedsUpdate ==
true)
60 system->PreUpdate(dt_ms);
71 if (system->m_Enabled ==
true && system->m_NeedsUpdate ==
true)
73 system->Update(dt_ms);
76 system->m_TimeSinceLastUpdate = 0.0f;
87 if (system->m_Enabled ==
true && system->m_NeedsUpdate ==
true)
89 system->PostUpdate(dt_ms);
98 if (system->m_Enabled ==
true) {
99 system->OnFrameStart();
109 if (system->m_Enabled ==
true) {
110 system->OnFrameEnd();
118 static const std::function<void(
SystemTypeId, eastl::vector<int>&,
const eastl::vector<eastl::vector<bool>>&, eastl::vector<SystemTypeId>&)> DFS = [&](
SystemTypeId vertex, eastl::vector<int>& VERTEX_STATE,
const eastl::vector<eastl::vector<bool>>& EDGES, eastl::vector<SystemTypeId>& output)
120 VERTEX_STATE[vertex] = 1;
122 for (
size_t i = 0; i < VERTEX_STATE.size(); ++i)
124 if (EDGES[i][vertex] ==
true && VERTEX_STATE[i] == 0)
125 DFS(i, VERTEX_STATE, EDGES, output);
128 VERTEX_STATE[vertex] = 2;
129 output.push_back(vertex);
136 eastl::vector<int> INDICES(NUM_SYSTEMS);
137 for (
int i = 0; i < NUM_SYSTEMS; ++i)
141 eastl::vector<eastl::vector<SystemTypeId>> VERTEX_GROUPS;
142 eastl::vector<SystemPriority> GROUP_PRIORITY;
144 while (INDICES.empty() ==
false)
146 int idx = INDICES.back();
154 eastl::vector<SystemTypeId> group;
155 eastl::vector<SystemTypeId> member;
158 member.push_back(index);
160 while (member.empty() ==
false)
162 index = member.back();
165 for (
size_t i = 0; i < INDICES.size(); ++i)
174 group.push_back(index);
181 VERTEX_GROUPS.push_back(group);
182 GROUP_PRIORITY.push_back(groupPriority);
185 const size_t NUM_VERTEX_GROUPS = VERTEX_GROUPS.size();
188 eastl::vector<int> vertex_states(NUM_SYSTEMS, 0);
190 eastl::multimap<SystemPriority, eastl::vector<SystemTypeId>> VERTEX_GROUPS_SORTED;
193 for (
size_t i = 0; i < NUM_VERTEX_GROUPS; ++i)
195 auto g = VERTEX_GROUPS[i];
197 eastl::vector<SystemTypeId> order;
199 for (
size_t j = 0; j < g.size(); ++j)
201 if (vertex_states[g[j]] == 0)
205 eastl::reverse(order.begin(), order.end());
208 VERTEX_GROUPS_SORTED.insert(eastl::pair<
SystemPriority, eastl::vector<SystemTypeId>>(
static_cast<SystemPriority>(std::numeric_limits<SystemPriority>::max() - GROUP_PRIORITY[i]), order));
213 LOG_INFO(
"Update system work order:",
"");
217 for (
auto group : VERTEX_GROUPS_SORTED)
219 for (
auto m : group.second)
245 assert(mask.size() == this->m_SystemWorkOrder.size() &&
"Provided mask does not match size of current system array.");
#define ECS_SYSTEM_MEMORY_BUFFER_SIZE
#define DEFINE_LOGGER(name)
#define LOG_INFO(format,...)
#define PROFILE_SCOPE_AUTO(CATEGORY)
SystemPriority m_Priority
virtual const char * GetSystemTypeName() const =0
const void * GetMemoryAddress0() const
const void * Allocate(size_t memSize, const char *user=nullptr)
SystemDependencyMatrix m_SystemDependencyMatrix
SystemAllocator * m_SystemAllocator
SystemWorkStateMask GetSystemWorkState() const
Memory::Allocator::LinearAllocator SystemAllocator
void UpdateSystemWorkOrder()
void SetSystemWorkState(SystemWorkStateMask mask)
~SystemManager() override
void PostUpdate(f32 dt_ms)
SystemWorkOrder m_SystemWorkOrder
void PreUpdate(f32 dt_ms)
constexpr Optick::Category::Type GameLogic
static const SystemPriority LOWEST_SYSTEM_PRIORITY
eastl::vector< bool > SystemWorkStateMask
static const SystemPriority NORMAL_SYSTEM_PRIORITY