R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ecs::wrapper::SystemScheduler Class Reference

Advanced scheduler for controlling system execution order and dependencies. More...

#include <SystemScheduler.hpp>

Collaboration diagram for ecs::wrapper::SystemScheduler:
Collaboration graph

Classes

struct  SystemInfo
 Information about a scheduled system. More...
 

Public Member Functions

 SystemScheduler (ECSWorld *world)
 Construct a SystemScheduler.
 
SystemSchedulerregisterSystem (const std::string &name, int priority=0)
 Register a system with the scheduler.
 
SystemSchedulerrunBefore (const std::string &systemName, const std::string &afterSystemName)
 Specify that a system must run before another.
 
SystemSchedulerrunAfter (const std::string &systemName, const std::string &beforeSystemName)
 Specify that a system must run after another.
 
void enable (const std::string &name)
 Enable a system.
 
void disable (const std::string &name)
 Disable a system.
 
bool isEnabled (const std::string &name) const
 Check if a system is enabled.
 
void update (float deltaTime)
 Update all enabled systems in the scheduled order.
 
const std::vector< std::string > & getExecutionOrder () const
 Get the computed execution order.
 
void printExecutionOrder () const
 Print the execution order for debugging.
 

Private Member Functions

void computeExecutionOrder ()
 
void topologicalSort ()
 

Private Attributes

ECSWorld_world
 
std::unordered_map< std::string, SystemInfo_systemInfos
 
std::vector< std::string > _executionOrder
 
bool _needsReorder
 

Detailed Description

Advanced scheduler for controlling system execution order and dependencies.

Allows defining execution stages, priorities, and dependencies between systems. Useful for complex server-side game logic with specific ordering requirements.

Definition at line 27 of file SystemScheduler.hpp.

Constructor & Destructor Documentation

◆ SystemScheduler()

ecs::wrapper::SystemScheduler::SystemScheduler ( ECSWorld world)
explicit

Construct a SystemScheduler.

Parameters
worldPointer to the ECS world

Definition at line 14 of file SystemScheduler.cpp.

Member Function Documentation

◆ computeExecutionOrder()

void ecs::wrapper::SystemScheduler::computeExecutionOrder ( )
private

Definition at line 76 of file SystemScheduler.cpp.

References _executionOrder, _needsReorder, _systemInfos, and topologicalSort().

Referenced by update().

Here is the call graph for this function:

◆ disable()

void ecs::wrapper::SystemScheduler::disable ( const std::string &  name)

Disable a system.

Parameters
nameSystem name

Definition at line 61 of file SystemScheduler.cpp.

References _systemInfos.

◆ enable()

void ecs::wrapper::SystemScheduler::enable ( const std::string &  name)

Enable a system.

Parameters
nameSystem name

Definition at line 54 of file SystemScheduler.cpp.

References _systemInfos.

◆ getExecutionOrder()

const std::vector< std::string > & ecs::wrapper::SystemScheduler::getExecutionOrder ( ) const

Get the computed execution order.

Returns
const std::vector<std::string>& Vector of system names in execution order

Definition at line 186 of file SystemScheduler.cpp.

References _executionOrder.

◆ isEnabled()

bool ecs::wrapper::SystemScheduler::isEnabled ( const std::string &  name) const

Check if a system is enabled.

Parameters
nameSystem name
Returns
bool true if enabled, false otherwise

Definition at line 68 of file SystemScheduler.cpp.

References _systemInfos.

◆ printExecutionOrder()

void ecs::wrapper::SystemScheduler::printExecutionOrder ( ) const

Print the execution order for debugging.

Definition at line 190 of file SystemScheduler.cpp.

References _executionOrder, and _systemInfos.

◆ registerSystem()

SystemScheduler & ecs::wrapper::SystemScheduler::registerSystem ( const std::string &  name,
int  priority = 0 
)

Register a system with the scheduler.

Parameters
nameSystem name
priorityExecution priority (higher = earlier)
Returns
SystemScheduler& Reference for chaining

Definition at line 16 of file SystemScheduler.cpp.

References _needsReorder, _systemInfos, ecs::wrapper::SystemScheduler::SystemInfo::enabled, ecs::wrapper::SystemScheduler::SystemInfo::name, and ecs::wrapper::SystemScheduler::SystemInfo::priority.

◆ runAfter()

SystemScheduler & ecs::wrapper::SystemScheduler::runAfter ( const std::string &  systemName,
const std::string &  beforeSystemName 
)

Specify that a system must run after another.

Parameters
systemNameThe system that runs second
beforeSystemNameThe system that runs before
Returns
SystemScheduler& Reference for chaining

Definition at line 41 of file SystemScheduler.cpp.

References _needsReorder, _systemInfos, and LOG_ERROR.

◆ runBefore()

SystemScheduler & ecs::wrapper::SystemScheduler::runBefore ( const std::string &  systemName,
const std::string &  afterSystemName 
)

Specify that a system must run before another.

Parameters
systemNameThe system that runs first
afterSystemNameThe system that runs after
Returns
SystemScheduler& Reference for chaining

Definition at line 28 of file SystemScheduler.cpp.

References _needsReorder, _systemInfos, and LOG_ERROR.

◆ topologicalSort()

void ecs::wrapper::SystemScheduler::topologicalSort ( )
private

Definition at line 100 of file SystemScheduler.cpp.

References _executionOrder, _systemInfos, and LOG_WARNING.

Referenced by computeExecutionOrder().

◆ update()

void ecs::wrapper::SystemScheduler::update ( float  deltaTime)

Update all enabled systems in the scheduled order.

Parameters
deltaTimeTime elapsed since last update

Definition at line 173 of file SystemScheduler.cpp.

References _executionOrder, _needsReorder, _systemInfos, _world, computeExecutionOrder(), and ecs::wrapper::ECSWorld::updateSystem().

Here is the call graph for this function:

Member Data Documentation

◆ _executionOrder

std::vector<std::string> ecs::wrapper::SystemScheduler::_executionOrder
private

◆ _needsReorder

bool ecs::wrapper::SystemScheduler::_needsReorder
private

◆ _systemInfos

std::unordered_map<std::string, SystemInfo> ecs::wrapper::SystemScheduler::_systemInfos
private

◆ _world

ECSWorld* ecs::wrapper::SystemScheduler::_world
private

Definition at line 42 of file SystemScheduler.hpp.

Referenced by update().


The documentation for this class was generated from the following files: