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

FixedTimeUpdate is a scheduler that runs systems at a fixed rate It is made to only be run a certain amount of times per second, skipping updates when the framerate is high and running multiple updates when the framerate is low. The time that passes is accumulated if the time between updates is greater than the tick rate or if there is a remainder from the last update(s). More...

#include <FixedTimeUpdate.hpp>

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

Public Member Functions

 FixedTimeUpdate (Core &core, float tickRate=DEFAULT_TICK_RATE)
 Constructor of the FixedTimeUpdate scheduler. It takes a reference to the core and an optional tick rate. If the tick rate is not provided, it will be set to the default tick rate (DEFAULT_TICK_RATE).
void RunSystems () override
 Interface for the schedulers. A scheduler is responsible for running systems according to a specific policy. Schedulers also manage how logic (system) should be handled.
float GetTickRate () const
 Get the fixed tick rate.
void SetTickRate (float tickRate)
 Set the fixed tick rate.
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 tick rate correspond to the number of update the scheduler should do in a second.
float _bufferedTime = 0.0f
 Buffered time since the last update, this allow to not lose time.

Static Private Attributes

static constexpr float DEFAULT_TICK_RATE = 1.0f / 50.0f
 The default tick rate for the FixedTimeUpdate scheduler. It is set to 1/50 seconds, which means that the scheduler will run at 50 updates per second by default.

Additional Inherited Members

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

Detailed Description

FixedTimeUpdate is a scheduler that runs systems at a fixed rate It is made to only be run a certain amount of times per second, skipping updates when the framerate is high and running multiple updates when the framerate is low. The time that passes is accumulated if the time between updates is greater than the tick rate or if there is a remainder from the last update(s).

See also
Engine::Scheduler::AScheduler

Constructor & Destructor Documentation

◆ FixedTimeUpdate()

Engine::Scheduler::FixedTimeUpdate::FixedTimeUpdate ( Core & core,
float tickRate = DEFAULT_TICK_RATE )
inline

Constructor of the FixedTimeUpdate scheduler. It takes a reference to the core and an optional tick rate. If the tick rate is not provided, it will be set to the default tick rate (DEFAULT_TICK_RATE).

Parameters
coreReference to the core.
tickRateThe tick rate for the scheduler. It is the time in seconds between each update. It is recommended to set this value to a value that is a divisor of the frame time to avoid issues with the accumulation of time. For example, if the frame time is 16ms (60 FPS), it is recommended to set the tick rate to 1/60 seconds or 1/120 seconds.
See also
Engine::Core
Engine::Scheduler::FixedTimeUpdate::DEFAULT_TICK_RATE
Todo
Put the implementation inside cpp file

Member Function Documentation

◆ GetTickRate()

float Engine::Scheduler::FixedTimeUpdate::GetTickRate ( ) const
inline

Get the fixed tick rate.

Returns
The tick rate in seconds
Todo
Put the implementation inside a cpp file (remove inline)
See also
Engine::Scheduler::FixedTimeUpdate::_tickRate

◆ RunSystems()

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

Interface for the schedulers. A scheduler is responsible for running systems according to a specific policy. Schedulers also manage how logic (system) should be handled.

Todo
Remove this interface and merge it with the AScheduler class.

Implements Engine::Scheduler::IScheduler.

◆ SetTickRate()

void Engine::Scheduler::FixedTimeUpdate::SetTickRate ( float tickRate)
inline

Set the fixed tick rate.

Parameters
tickRateThe fixed tick rate
Note
This can cause issues if the value is changed during an update. It is recommended to change this value before the update loop starts.
See also
Engine::Scheduler::FixedTimeUpdate::_tickRate
Todo
Put the implementation inside a cpp file (remove inline)

Member Data Documentation

◆ _bufferedTime

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

Buffered time since the last update, this allow to not lose time.

◆ _tickRate

float Engine::Scheduler::FixedTimeUpdate::_tickRate
private

The tick rate correspond to the number of update the scheduler should do in a second.

◆ DEFAULT_TICK_RATE

float Engine::Scheduler::FixedTimeUpdate::DEFAULT_TICK_RATE = 1.0f / 50.0f
inlinestaticconstexprprivate

The default tick rate for the FixedTimeUpdate scheduler. It is set to 1/50 seconds, which means that the scheduler will run at 50 updates per second by default.


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