Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
RelativeTimeUpdate.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <entt/entt.hpp>
4
5#include <chrono>
6
8
9namespace Engine::Scheduler {
16 private:
19 inline static constexpr float DEFAULT_TARGET_TICK_RATE = 1.0f / 50.0f;
24 inline static constexpr float REMAINDER_THRESHOLD = 0.0001f;
25
26 public:
37 RelativeTimeUpdate(Core &core, float tickRate = DEFAULT_TARGET_TICK_RATE) : AScheduler(core), _tickRate(tickRate) {}
38
40 void RunSystems() override;
41
47 inline float GetTargetTickRate() const { return _tickRate; }
48
54 inline void SetTargetTickRate(float tickRate) { _tickRate = tickRate; }
55
60 inline float GetCurrentDeltaTime() const { return _deltaTime; }
61
62 private:
72 float _tickRate;
73
78 float _deltaTime = 0.0f;
79
83 float _bufferedTime = 0.0f;
84};
85} // namespace Engine::Scheduler
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
AScheduler(Core &core)
Constructor of the AScheduler class.
Definition AScheduler.hpp:20
static constexpr float DEFAULT_TARGET_TICK_RATE
The default target tick rate for the RelativeTimeUpdate scheduler. It is set to 1/50 seconds,...
Definition RelativeTimeUpdate.hpp:19
float _bufferedTime
Time accumulated from the previous ticks that is less than the threshold. This time will be added to ...
Definition RelativeTimeUpdate.hpp:83
float _tickRate
The target tick rate for the scheduler. It is the maximum time we want between each system run....
Definition RelativeTimeUpdate.hpp:72
float GetTargetTickRate() const
Get the target tick rate.
Definition RelativeTimeUpdate.hpp:47
float GetCurrentDeltaTime() const
Get the current delta time.
Definition RelativeTimeUpdate.hpp:60
float _deltaTime
The current delta time. It is the time between the last system run and the current system run....
Definition RelativeTimeUpdate.hpp:78
static constexpr float REMAINDER_THRESHOLD
The threshold for the remainder time. If the remainder time is less than this threshold,...
Definition RelativeTimeUpdate.hpp:24
void RunSystems() override
Run the systems according to the scheduler policy.
Definition RelativeTimeUpdate.cpp:6
RelativeTimeUpdate(Core &core, float tickRate=DEFAULT_TARGET_TICK_RATE)
Constructor of the RelativeTimeUpdate scheduler. It takes a reference to the core and an optional tic...
Definition RelativeTimeUpdate.hpp:37
void SetTargetTickRate(float tickRate)
Set the target tick rate.
Definition RelativeTimeUpdate.hpp:54
Definition AScheduler.cpp:7