54 _main_thread_systems.emplace_back(into_system_interface(std::forward<
decltype(args)>(args)...));
63 _systems.emplace_back(into_system_interface(std::forward<
decltype(args)>(args)...));
75 std::vector<vector_of_executors_t> executors{};
77 while (!_systems.empty()) {
81 for (
size_t i = 0; i < _systems.size();) {
82 auto executor = _systems[i]->create_executor(
registry, user_context);
83 auto system_access_pattern = executor->access_pattern();
85 if (!access_pattern.
allows(system_access_pattern)) {
90 access_pattern &= system_access_pattern;
91 executor_set.emplace_back(std::move(executor));
92 _systems.erase(_systems.begin() + i);
98 for (
auto& system : _main_thread_systems) {
99 main_thread_executors.emplace_back(system->create_executor(
registry, user_context));
102 return std::make_unique<stage_executor>(_name, std::move(executors), std::move(main_thread_executors));
112 static auto into_system_interface(F&& func) -> std::unique_ptr<system_interface> {
113 return std::make_unique<system<F>>(std::forward<F>(func));
122 static auto into_system_interface(std::unique_ptr<S> system) -> std::unique_ptr<system_interface> {
128 std::string_view _name;
129 std::vector<std::unique_ptr<system_interface>> _systems{};
130 std::vector<std::unique_ptr<system_interface>> _main_thread_systems{};
146 std::vector<vector_of_executors_t> executor_set,
148 _executor_set(
std::move(executor_set)), _main_thread_executors(
std::move(main_thread_executors)), _name(name) {
153 for (
auto& executors : _executor_set) {
154 execute_batch(executors);
163 template<
typename WorkBatch>
164 void execute_batch(WorkBatch&& work_batch) {
168 for (
auto& work_item : work_batch) {
169 auto task = _thread_pool.submit([&work_item]() { work_item->run(); }, parent);
176 for (
auto& executor : _main_thread_executors) {
181 _thread_pool.wait(parent);
186 std::vector<vector_of_executors_t> _executor_set;
188 std::string_view _name;
Class representing an access pattern for components.
Definition access.hpp:19
auto allows(const access_pattern_t &other) const noexcept -> bool
Checks if this access pattern allows another access pattern.
Definition access.hpp:44
Registry is a container for all our entities and components. Components are stored in continuously in...
Definition registry.hpp:13
Manages the execution of systems in different stages.
Definition schedule.hpp:15
Class representing a stage executor.
Definition stage.hpp:136
void run()
Runs all systems in the stage.
Definition stage.hpp:152
stage_executor(std::string_view name, std::vector< vector_of_executors_t > executor_set, vector_of_executors_t main_thread_executors)
Constructs a new stage executor.
Definition stage.hpp:145
Class representing a stage in the schedule.
Definition stage.hpp:29
auto create_executor(registry ®istry, void *user_context=nullptr) -> std::unique_ptr< stage_executor >
Creates an executor for the stage.
Definition stage.hpp:74
auto end_stage() noexcept -> schedule &
Ends the current stage and returns the schedule.
Definition stage.hpp:44
stage(schedule &schedule, std::string_view name={})
Constructs a new stage object.
Definition stage.hpp:38
auto add_system(auto &&... args) -> self_type &
Adds a system to the stage.
Definition stage.hpp:62
auto add_system(main_thread_execution_policty_t policy, auto &&... args) -> self_type &
Adds a system to the main thread execution list.
Definition stage.hpp:53
Represents a task that can be executed, monitored for completion, and linked to a parent task.
Definition task.hpp:10
static thread_pool & get()
Get thread pool instance.
Definition thread_pool.hpp:264
Definition archetype.hpp:11
constexpr main_thread_execution_policty_t main_thread_execution_policy
Constant instance of the main thread execution policy.
Definition stage.hpp:24
std::vector< std::unique_ptr< system_executor_interface > > vector_of_executors_t
Vector of systems.
Definition stage.hpp:10
Structure representing the main thread execution policy.
Definition stage.hpp:18
main_thread_execution_policty_t()=default
Default constructor.