3template <
typename TScheduler,
typename... Args>
6 if (this->
_schedulers.contains(std::type_index(
typeid(TScheduler))))
8 Log::Warning(fmt::format(
"Scheduler already exists: {}",
typeid(TScheduler).name()));
11 Log::Debug(fmt::format(
"Adding scheduler: {}",
typeid(TScheduler).name()));
12 std::shared_ptr<TScheduler> scheduler = std::make_shared<TScheduler>(core, std::forward<Args>(args)...);
13 this->
_schedulers[std::type_index(
typeid(TScheduler))] = scheduler;
19 auto it = this->
_schedulers.find(std::type_index(
typeid(TScheduler)));
22 throw SchedulerError(fmt::format(
"Scheduler not found: {}",
typeid(TScheduler).name()));
24 return *
static_cast<TScheduler *
>(it->second.get());
30 _dependencies[std::type_index(
typeid(TAfter))].insert(std::type_index(
typeid(TBefore)));
41 auto it =
_dependencies.find(std::type_index(
typeid(TAfter)));
44 it->second.erase(std::type_index(
typeid(TBefore)));
45 if (it->second.empty())
50 Log::Warning(fmt::format(
"Dependency not found: {} -> {}",
typeid(TBefore).name(),
typeid(TAfter).name()));
64 scheduler->RunSystems();
66 if (!scheduler->ShouldRunNextScheduler())
77 return Contains(std::type_index(
typeid(TScheduler)));
84 throw SchedulerError(fmt::format(
"Scheduler not found: {}",
id.name()));
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
std::unordered_map< std::type_index, std::unordered_set< std::type_index > > _dependencies
A map of the dependencies between schedulers. The key is the type index of a scheduler,...
Definition SchedulerContainer.hpp:140
std::list< std::shared_ptr< Scheduler::AScheduler > > _orderedSchedulers
A list of the the ordered list of schedulers.
Definition SchedulerContainer.hpp:143
void Update()
Updates the order of schedulers based on their dependencies. This function performs a topological sor...
Definition SchedulerContainer.cpp:89
void Before()
Add a dependency between two schedulers. It will set the first scheduler to be before the second one.
Definition SchedulerContainer.inl:27
void After()
Add a dependency between two schedulers. It will set the first scheduler to be after the second one.
Definition SchedulerContainer.inl:33
void RunSchedulers()
Runs all schedulers in the container. This function iterates through the ordered list of schedulers a...
Definition SchedulerContainer.inl:59
bool Contains() const
Checks if a scheduler of the specified type exists in the container.
Definition SchedulerContainer.inl:75
std::map< std::type_index, std::shared_ptr< Scheduler::AScheduler > > _schedulers
A map of the schedulers.
Definition SchedulerContainer.hpp:136
bool _dirty
A flag indicating whether the order of schedulers needs to be updated.
Definition SchedulerContainer.hpp:133
void RemoveDependencyAfter()
Remove a dependency between two schedulers. It will remove the dependency that the first scheduler is...
Definition SchedulerContainer.inl:54
TScheduler & GetScheduler()
Retrieves a scheduler of the specified type.
Definition SchedulerContainer.inl:17
void RemoveDependencyBefore()
Remove a dependency between two schedulers. It will remove the dependency that the first scheduler is...
Definition SchedulerContainer.inl:38
void AddScheduler(Core &core, Args &&...args)
Adds a scheduler to the container.
Definition SchedulerContainer.inl:4
Custom exception class for scheduler-related errors.
Definition SchedulerContainer.hpp:19
void Warning(const T &msg) noexcept
Definition Logger.hpp:49
void Debug(const T &msg) noexcept
Definition Logger.hpp:45