R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
SystemScheduler.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** rtype
4** File description:
5** SystemScheduler - Advanced system execution control
6*/
7
8#pragma once
9
10#include <functional>
11#include <string>
12#include <unordered_map>
13#include <unordered_set>
14#include <vector>
15
16#include "ECSWorld.hpp"
17
18namespace ecs::wrapper {
19
28 public:
33 struct SystemInfo {
34 std::string name;
36 std::vector<std::string> runBefore;
37 std::vector<std::string> runAfter;
38 bool enabled;
39 };
40
41 private:
43 std::unordered_map<std::string, SystemInfo> _systemInfos;
44 std::vector<std::string> _executionOrder;
46
48 void topologicalSort();
49
50 public:
56 explicit SystemScheduler(ECSWorld *world);
57
65 SystemScheduler &registerSystem(const std::string &name, int priority = 0);
66
74 SystemScheduler &runBefore(const std::string &systemName, const std::string &afterSystemName);
75
83 SystemScheduler &runAfter(const std::string &systemName, const std::string &beforeSystemName);
84
90 void enable(const std::string &name);
91
97 void disable(const std::string &name);
98
105 bool isEnabled(const std::string &name) const;
106
112 void update(float deltaTime);
113
119 const std::vector<std::string> &getExecutionOrder() const;
120
124 void printExecutionOrder() const;
125 };
126
127} // namespace ecs::wrapper
High-level ECS manager providing clean server-side API.
Definition ECSWorld.hpp:122
Advanced scheduler for controlling system execution order and dependencies.
const std::vector< std::string > & getExecutionOrder() const
Get the computed execution order.
void disable(const std::string &name)
Disable a system.
bool isEnabled(const std::string &name) const
Check if a system is enabled.
void printExecutionOrder() const
Print the execution order for debugging.
SystemScheduler & registerSystem(const std::string &name, int priority=0)
Register a system with the scheduler.
std::unordered_map< std::string, SystemInfo > _systemInfos
SystemScheduler & runBefore(const std::string &systemName, const std::string &afterSystemName)
Specify that a system must run before another.
std::vector< std::string > _executionOrder
SystemScheduler & runAfter(const std::string &systemName, const std::string &beforeSystemName)
Specify that a system must run after another.
void update(float deltaTime)
Update all enabled systems in the scheduled order.
void enable(const std::string &name)
Enable a system.
Information about a scheduled system.
std::vector< std::string > runBefore
Systems that must run after this one.
std::vector< std::string > runAfter
Systems that must run before this one.
int priority
Higher priority systems run first.