Skip to content

clock

This package manages the application’s timing. It provides all essential utilities for frame-rate independent movement, time manipulation and global pause states.

Features:

  • Frame independence: Access to getDeltaTime for consistent movement, regardless of framerate.
  • Time scaling: Global control over game speed via setTimeScale.
  • Pause system: Built-in setPaused functionality useful for pause screens.
  • Timers: Functions like hasTimestampPassed and getSecondsSince to easily handle cooldowns, delays and timers without ugly timer variables.

Usage:

update :: proc() {
// Standard movement, stops when paused
pot.position += velocity * clock.getDeltaTime()
// Continues when paused
ui.rotation += speed * clock.getUnscaledDeltaTime()
// Simple cooldown check
if clock.hasTimestampPassed(nextAttackTime) {
potAttack()
nextAttackTime = clock.getGameTime() + 0.5
}
}

getApplicationInitTime :: proc () -> i64

Returns time when the application was initialized in UNIX nanoseconds.


getApplicationTime :: proc () -> f64

Returns the total real-world seconds elapsed since the application initialized. This time is unaffected by game pauses or time scaling.


getAverageFrameTime :: proc () -> f32

Returns average frame time (delta time) in seconds over last 60 frames.


getDeltaTime :: proc () -> f32

Returns the scaled time since the last frame in seconds. Returns 0.0 if the game is paused.


getFps :: proc () -> int

Returns estimated frames per seconds the application is running at. Calculated using the average frame time over last 60 frames.


getGameTime :: proc () -> f64

Returns total accumulated game time in seconds. This value stops increasing when paused.


getSecondsSince :: proc (timestamp: f64) -> f32

Calculates the duration in seconds that has passed since a specific timestamp.

Returns a large safe value if the input time is invalid (0 or negative) to prevent logic errors.


getTicks :: proc () -> u64

Returns the total number of frames (ticks) processed since app start.


getTimeScale :: proc () -> f32

Returns the current time scale multiplier.


getUnscaledDeltaTime :: proc () -> f32

Returns the actual time since the last frame in seconds. Unaffected by pause or time scaling.


hasTimestampPassed :: proc (targetTimestamp: f64) -> bool

Checks if the current game time has passed a specific target timestamp (in seconds).

Useful for cooldowns or timers. Returns false if the target timestamp is -1 (unset).


isPaused :: proc () -> bool

Returns true, if game is paused.


setPaused :: proc (paused: bool)

Setter for pausing the game (equivalent to setTimeScale(0.0)). Stops getDeltaTime, but not getUnscaledDeltaTime.


setTimeScale :: proc (scale: f32)

Sets the speed multiplier of game time. (default: 1.0).