Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
main_thread.cpp
Go to the documentation of this file.
1#include <pch.hpp>
2
4
5#include <helios/assert.hpp>
6#include <helios/ecs/details/profile.hpp>
9
10#include <cstddef>
11
12namespace helios::ecs {
13
15 HELIOS_ECS_PROFILE_SCOPE_N("helios::ecs::MainThreadExecutor::Execute");
16 HELIOS_ASSERT(schedule.plan_.has_value(),
17 "MainThreadExecutor: schedule has no compiled plan!");
18
19 const auto& plan = *schedule.plan_;
20 const auto& execution_order = plan.execution_order;
21 for (size_t exec_idx = 0; exec_idx < execution_order.size(); ++exec_idx) {
22 const SystemId id = execution_order[exec_idx];
23
24 const auto it = plan.system_id_to_entry_idx.find(id.id);
25 if (it == plan.system_id_to_entry_idx.end()) {
26 continue;
27 }
28
29 auto& entries = schedule.system_entries_;
30 const size_t entry_idx = it->second;
31 HELIOS_ASSERT(entry_idx < entries.size(),
32 "System index out of bounds in MainThreadExecutor!");
33
34 auto& entry = entries[entry_idx];
35 auto& storage = entry.storage;
36
37 auto& conditions = schedule.conditions_cache_;
38 if (exec_idx < conditions.size()) {
39 bool should_run = true;
40 for (RunConditionStorage* cond_storage : conditions[exec_idx]) {
41 HELIOS_ECS_PROFILE_SCOPE();
42 HELIOS_ECS_PROFILE_ZONE_NAME(cond_storage->name);
43 if (!cond_storage->run_condition(world, cond_storage->local_data)) {
44 should_run = false;
45 break;
46 }
47 }
48 if (!should_run) {
49 continue;
50 }
51 }
52
53 HELIOS_ECS_PROFILE_ZONE_NAME(storage.name);
54 storage.system(world, storage.local_data);
55 }
56}
57
58} // namespace helios::ecs
#define HELIOS_ASSERT(condition,...)
Assertion macro that aborts execution in debug builds.
Definition assert.hpp:259
void Execute(Schedule &schedule, World &world) override
Submits all systems in the schedule for execution.
A collection of systems, sets, and run conditions with ordering constraints.
Definition schedule.hpp:182
The World class manages entities with their components and systems.
Definition world.hpp:39
Storage for a run condition — predicate + access policy + local data.
Id for systems.
Definition system.hpp:146