Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Engine::Scheduler::RelativeTimeUpdate Class Reference

RelativeTimeUpdate is a scheduler that runs systems at a defined rate. The tick rate is the maximum time we want between each system run. If the time between each system run is more than the target tick rate, we will run the systems multiple times with a delta time equal to the tick rate. Else, we will just run the systems once with the delta time we have (remaining). More...

#include <RelativeTimeUpdate.hpp>

Inheritance diagram for Engine::Scheduler::RelativeTimeUpdate:
Engine::Scheduler::AScheduler Engine::Scheduler::IScheduler

Public Member Functions

 RelativeTimeUpdate (Core &core, float tickRate=DEFAULT_TARGET_TICK_RATE)
 Constructor of the RelativeTimeUpdate scheduler. It takes a reference to the core and an optional tick rate.
void RunSystems () override
 Run the systems according to the scheduler policy.
float GetTargetTickRate () const
 Get the target tick rate.
void SetTargetTickRate (float tickRate)
 Set the target tick rate.
float GetCurrentDeltaTime () const
 Get the current delta time.
Public Member Functions inherited from Engine::Scheduler::AScheduler
 AScheduler (Core &core)
 Constructor of the AScheduler class.
decltype(auto) GetSystems ()
 Get systems inside the scheduler.
template<typename... TSystems>
decltype(auto) AddSystems (TSystems... systems)
 Add systems to the scheduler.
void Disable (FunctionUtils::FunctionID id)
 Disable a system.
void Enable (FunctionUtils::FunctionID id)
 Enable a system.
void RunSystem (const SystemBase *system, Core &core)
 Execute a system.
bool ShouldRunNextScheduler () const
 Get whether the next scheduler should run or not. This is mainly set by the error policy of the scheduler.
SchedulerErrorPolicy GetErrorPolicy () const override
 Get the error policy of the scheduler.
void SetErrorPolicy (SchedulerErrorPolicy errorPolicy) override
 Set the error policy of the scheduler.
void Remove (FunctionUtils::FunctionID id)
 Remove a system from the scheduler.
Public Member Functions inherited from Engine::Scheduler::IScheduler
virtual ~IScheduler ()=default
 Virtual destructor for IScheduler.

Private Attributes

float _tickRate
 The target tick rate for the scheduler. It is the maximum time we want between each system run. If the time between each system run is more than the target tick rate, we will run the systems multiple times with a delta time equal to the tick rate. After tick rate time has passed, if there is a remainder time that is greater than the remainder threshold, he will run the systems one more time with the remainder time as delta time. Else, he will just add the remainder time to the buffered time for the next tick. This is to avoid running the systems with a very small delta time.
float _deltaTime = 0.0f
 The current delta time. It is the time between the last system run and the current system run. This value may be modified by the scheduler to run the systems multiple times if the time between each system run is more than the target tick rate.
float _bufferedTime = 0.0f
 Time accumulated from the previous ticks that is less than the threshold. This time will be added to the delta time of the next tick. This is to avoid running the systems with a very small delta time.

Static Private Attributes

static constexpr float DEFAULT_TARGET_TICK_RATE = 1.0f / 50.0f
 The default target tick rate for the RelativeTimeUpdate scheduler. It is set to 1/50 seconds, which means that the scheduler will try to run the systems at a maximum rate of 50 times per second.
static constexpr float REMAINDER_THRESHOLD = 0.0001f
 The threshold for the remainder time. If the remainder time is less than this threshold, we will not run the systems with the remainder time as delta time, and we will just add the remainder time to the buffered time for the next tick. This is to avoid running the systems with a very small delta time, which can cause issues.

Additional Inherited Members

Protected Attributes inherited from Engine::Scheduler::AScheduler
Core_core
 Reference to the core.

Detailed Description

RelativeTimeUpdate is a scheduler that runs systems at a defined rate. The tick rate is the maximum time we want between each system run. If the time between each system run is more than the target tick rate, we will run the systems multiple times with a delta time equal to the tick rate. Else, we will just run the systems once with the delta time we have (remaining).

Constructor & Destructor Documentation

◆ RelativeTimeUpdate()

Engine::Scheduler::RelativeTimeUpdate::RelativeTimeUpdate ( Core & core,
float tickRate = DEFAULT_TARGET_TICK_RATE )
inline

Constructor of the RelativeTimeUpdate scheduler. It takes a reference to the core and an optional tick rate.

Parameters
coreReference to the core.
tickRateThe target tick rate for the scheduler. If no tick rate is provided, the default target tick rate will be used (DEFAULT_TARGET_TICK_RATE).
See also
Engine::Core
Engine::Scheduler::RelativeTimeUpdate::DEFAULT_TARGET_TICK_RATE
Engine::Scheduler::RelativeTimeUpdate::_tickRate
Engine::Scheduler::RelativeTimeUpdate::AScheduler
Todo
put the implementation in the cpp file

Member Function Documentation

◆ GetCurrentDeltaTime()

float Engine::Scheduler::RelativeTimeUpdate::GetCurrentDeltaTime ( ) const
inline

Get the current delta time.

Returns
The current delta time
See also
Engine::Scheduler::RelativeTimeUpdate::_deltaTime
Todo
put the implementation in the cpp file, (remove inline)

◆ GetTargetTickRate()

float Engine::Scheduler::RelativeTimeUpdate::GetTargetTickRate ( ) const
inline

Get the target tick rate.

Returns
The target tick rate
See also
Engine::Scheduler::RelativeTimeUpdate::DEFAULT_TARGET_TICK_RATE
Engine::Scheduler::RelativeTimeUpdate::_tickRate
Todo
put the implementation in the cpp file, (remove inline)

◆ RunSystems()

void Engine::Scheduler::RelativeTimeUpdate::RunSystems ( void )
overridevirtual

Run the systems according to the scheduler policy.

Implements Engine::Scheduler::IScheduler.

◆ SetTargetTickRate()

void Engine::Scheduler::RelativeTimeUpdate::SetTargetTickRate ( float tickRate)
inline

Set the target tick rate.

Parameters
tickRateThe target tick rate
See also
Engine::Scheduler::RelativeTimeUpdate::DEFAULT_TARGET_TICK_RATE
Engine::Scheduler::RelativeTimeUpdate::_tickRate
Todo
put the implementation in the cpp file, (remove inline)

Member Data Documentation

◆ _bufferedTime

float Engine::Scheduler::RelativeTimeUpdate::_bufferedTime = 0.0f
private

Time accumulated from the previous ticks that is less than the threshold. This time will be added to the delta time of the next tick. This is to avoid running the systems with a very small delta time.

See also
Engine::Scheduler::RelativeTimeUpdate::REMAINDER_THRESHOLD

◆ _deltaTime

float Engine::Scheduler::RelativeTimeUpdate::_deltaTime = 0.0f
private

The current delta time. It is the time between the last system run and the current system run. This value may be modified by the scheduler to run the systems multiple times if the time between each system run is more than the target tick rate.

See also
Engine::Scheduler::RelativeTimeUpdate::GetCurrentDeltaTime

◆ _tickRate

float Engine::Scheduler::RelativeTimeUpdate::_tickRate
private

The target tick rate for the scheduler. It is the maximum time we want between each system run. If the time between each system run is more than the target tick rate, we will run the systems multiple times with a delta time equal to the tick rate. After tick rate time has passed, if there is a remainder time that is greater than the remainder threshold, he will run the systems one more time with the remainder time as delta time. Else, he will just add the remainder time to the buffered time for the next tick. This is to avoid running the systems with a very small delta time.

See also
Engine::Scheduler::RelativeTimeUpdate::DEFAULT_TARGET_TICK_RATE
Engine::Scheduler::RelativeTimeUpdate::GetTargetTickRate
Engine::Scheduler::RelativeTimeUpdate::SetTargetTickRate

◆ DEFAULT_TARGET_TICK_RATE

float Engine::Scheduler::RelativeTimeUpdate::DEFAULT_TARGET_TICK_RATE = 1.0f / 50.0f
inlinestaticconstexprprivate

The default target tick rate for the RelativeTimeUpdate scheduler. It is set to 1/50 seconds, which means that the scheduler will try to run the systems at a maximum rate of 50 times per second.

◆ REMAINDER_THRESHOLD

float Engine::Scheduler::RelativeTimeUpdate::REMAINDER_THRESHOLD = 0.0001f
inlinestaticconstexprprivate

The threshold for the remainder time. If the remainder time is less than this threshold, we will not run the systems with the remainder time as delta time, and we will just add the remainder time to the buffered time for the next tick. This is to avoid running the systems with a very small delta time, which can cause issues.


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