vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::Clock Class Reference

The engine's frame clock: real + simulation time and the fixed-step accumulator. More...

#include <clock.h>

Public Member Functions

void beginFrame ()
 Open a new frame: measure the real delta, derive the sim delta, fill the accumulator.
bool consumeFixedStep ()
 Take one fixed step if one is owed; the main-loop fixedUpdate condition.
void setTickRate (uint32_t ticksPerSecond)
 Set the simulation cadence, in ticks per second.
void setPaused (bool paused)
 Pause or resume simulation time.
void setTimeScale (float scale)
 Set the slow-motion / fast-forward multiplier applied while running.
void setPacing (float scale)
 Set how many fixed steps a second of wall time buys, as a multiple.
void requestStep (int steps=1)
 Queue fixed-step advances, whatever the play state.
float getFixedAlpha () const
 How far into the next fixed step this frame falls, 0..1.
float getFrameRate () const
 Frames per second, smoothed over roughly the last half second.
float getFrameTime () const
 The smoothed frame as a duration rather than a rate.
bool isSimulationStill () const
 Whether the world stands still this frame.
uint32_t getTick () const
 Which fixed step is running, counting from one.

Detailed Description

The engine's frame clock: real + simulation time and the fixed-step accumulator.

Systems read getDeltaTime() for real-time work (input, camera, UI), getSimDelta() for simulation update() and getFixedStep() in fixedUpdate().

Member Function Documentation

◆ beginFrame()

void Vkm::Engine::Clock::beginFrame ( )

Open a new frame: measure the real delta, derive the sim delta, fill the accumulator.

The first call reports zero, so a slow startup gives no giant step. A frame longer than Config::MAX_FRAME_ACCUMULATOR is capped, so a hitch discards wall time.

◆ consumeFixedStep()

bool Vkm::Engine::Clock::consumeFixedStep ( )

Take one fixed step if one is owed; the main-loop fixedUpdate condition.

Requested steps are taken first, then measured time.

Returns
True having taken a step, false once none is owed.

◆ setTickRate()

void Vkm::Engine::Clock::setTickRate ( uint32_t ticksPerSecond)
inline

Set the simulation cadence, in ticks per second.

Set when a project is read, never per frame: fixedUpdate assumes a fixed step.

Parameters
ticksPerSecondClamped to [Config::MIN_TICK_RATE, Config::MAX_TICK_RATE].

◆ setPaused()

void Vkm::Engine::Clock::setPaused ( bool paused)
inline

Pause or resume simulation time.

Queued steps survive it.

Parameters
pausedTrue freezes simulation time (sim delta 0).

◆ setTimeScale()

void Vkm::Engine::Clock::setTimeScale ( float scale)
inline

Set the slow-motion / fast-forward multiplier applied while running.

In the editor a scale lasts one play session; see SceneIOController::endPlaySession.

Parameters
scaleNegative is clamped to 0.

◆ setPacing()

void Vkm::Engine::Clock::setPacing ( float scale)
inline

Set how many fixed steps a second of wall time buys, as a multiple.

A networked client runs slightly fast or slow so the server's command queue neither runs dry nor backs up (NetPacing); the step never changes. Multiplied with the time scale; Engine::run sets it each frame from NetSession::pacing().

Parameters
scaleNegative is clamped to 0.

◆ requestStep()

void Vkm::Engine::Clock::requestStep ( int steps = 1)
inline

Queue fixed-step advances, whatever the play state.

A count, not seconds: a step is rarely a binary fraction, so n * step converted back would lose ticks.

Parameters
stepsFixed steps to enqueue; non-positive is ignored.

◆ getFixedAlpha()

float Vkm::Engine::Clock::getFixedAlpha ( ) const
inline

How far into the next fixed step this frame falls, 0..1.

The accumulator's leftover, as a fraction of a step past the last tick.

◆ getFrameRate()

float Vkm::Engine::Clock::getFrameRate ( ) const
inline

Frames per second, smoothed over roughly the last half second.

For this frame alone, use getDeltaTime().

Returns
Zero before the first frame.

◆ getFrameTime()

float Vkm::Engine::Clock::getFrameTime ( ) const
inline

The smoothed frame as a duration rather than a rate.

Returns
Milliseconds per frame; zero before the first frame.

◆ isSimulationStill()

bool Vkm::Engine::Clock::isSimulationStill ( ) const
inline

Whether the world stands still this frame.

True when no simulation time passes and no step is asked for, so no tick can follow; Engine::run drops input latched on such a frame.

◆ getTick()

uint32_t Vkm::Engine::Clock::getTick ( ) const
inline

Which fixed step is running, counting from one.

Advances only when consumeFixedStep() hands one out.

Returns
The tick number; zero before the first.

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