8#include "core/engine_config.h"
10namespace Vkm::Engine {
23 Clock(
const Clock& other) =
default;
24 Clock& operator=(
const Clock& other) =
default;
26 Clock(Clock && other) =
default;
27 Clock& operator=(Clock && other) =
default;
77 void setTimeScale(
float scale) { m_timeScale = scale < 0.0f ? 0.0f : scale; }
89 void setPacing(
float scale) { m_pacing = scale < 0.0f ? 0.0f : scale; }
99 void requestStep(
int steps = 1) {
if (steps > 0) m_pendingSteps += steps; }
101 float getDeltaTime()
const {
return m_deltaTime; }
102 float getSimDelta()
const {
return m_simDelta; }
103 float getFixedStep()
const {
return m_fixedStep; }
111 return m_fixedStep > 0.0f ? glm::clamp(m_accumulator / m_fixedStep, 0.0f, 1.0f) : 0.0f;
121 float getFrameRate()
const {
return m_smoothedDelta > 0.0f ? 1.0f / m_smoothedDelta : 0.0f; }
130 bool isPaused()
const {
return m_paused; }
140 float getTimeScale()
const {
return m_timeScale; }
141 float getPacing()
const {
return m_pacing; }
153 std::chrono::steady_clock::time_point m_last{};
154 bool m_started =
false;
156 float m_fixedStep = 1.0f /
static_cast<float>(Config::DEFAULT_TICK_RATE);
158 float m_deltaTime = 0.0f;
159 float m_simDelta = 0.0f;
160 float m_accumulator = 0.0f;
161 float m_smoothedDelta = 0.0f;
163 bool m_paused =
false;
164 int m_pendingSteps = 0;
165 float m_timeScale = 1.0f;
166 float m_pacing = 1.0f;
bool isSimulationStill() const
Whether the world stands still this frame.
Definition clock.h:138
float getFixedAlpha() const
How far into the next fixed step this frame falls, 0..1.
Definition clock.h:110
float getFrameTime() const
The smoothed frame as a duration rather than a rate.
Definition clock.h:128
void setPacing(float scale)
Set how many fixed steps a second of wall time buys, as a multiple.
Definition clock.h:89
bool consumeFixedStep()
Take one fixed step if one is owed; the main-loop fixedUpdate condition.
void setTimeScale(float scale)
Set the slow-motion / fast-forward multiplier applied while running.
Definition clock.h:77
float getFrameRate() const
Frames per second, smoothed over roughly the last half second.
Definition clock.h:121
uint32_t getTick() const
Which fixed step is running, counting from one.
Definition clock.h:150
void requestStep(int steps=1)
Queue fixed-step advances, whatever the play state.
Definition clock.h:99
void setPaused(bool paused)
Pause or resume simulation time.
Definition clock.h:67
void setTickRate(uint32_t ticksPerSecond)
Set the simulation cadence, in ticks per second.
Definition clock.h:56
void beginFrame()
Open a new frame: measure the real delta, derive the sim delta, fill the accumulator.
constexpr uint32_t clampTickRate(uint32_t ticksPerSecond)
What a project's requested tick rate is honoured as.
Definition engine_config.h:59