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
getDeltaTimefor consistent movement, regardless of framerate. - Time scaling: Global control over game speed via
setTimeScale. - Pause system: Built-in
setPausedfunctionality useful for pause screens. - Timers: Functions like
hasTimestampPassedandgetSecondsSinceto 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
Section titled “getApplicationInitTime”getApplicationInitTime :: proc () -> i64Returns time when the application was initialized in UNIX nanoseconds.
getApplicationTime
Section titled “getApplicationTime”getApplicationTime :: proc () -> f64Returns the total real-world seconds elapsed since the application initialized. This time is unaffected by game pauses or time scaling.
getAverageFrameTime
Section titled “getAverageFrameTime”getAverageFrameTime :: proc () -> f32Returns average frame time (delta time) in seconds over last 60 frames.
getDeltaTime
Section titled “getDeltaTime”getDeltaTime :: proc () -> f32Returns the scaled time since the last frame in seconds.
Returns 0.0 if the game is paused.
getFps
Section titled “getFps”getFps :: proc () -> intReturns estimated frames per seconds the application is running at. Calculated using the average frame time over last 60 frames.
getGameTime
Section titled “getGameTime”getGameTime :: proc () -> f64Returns total accumulated game time in seconds. This value stops increasing when paused.
getSecondsSince
Section titled “getSecondsSince”getSecondsSince :: proc (timestamp: f64) -> f32Calculates 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
Section titled “getTicks”getTicks :: proc () -> u64Returns the total number of frames (ticks) processed since app start.
getTimeScale
Section titled “getTimeScale”getTimeScale :: proc () -> f32Returns the current time scale multiplier.
getUnscaledDeltaTime
Section titled “getUnscaledDeltaTime”getUnscaledDeltaTime :: proc () -> f32Returns the actual time since the last frame in seconds. Unaffected by pause or time scaling.
hasTimestampPassed
Section titled “hasTimestampPassed”hasTimestampPassed :: proc (targetTimestamp: f64) -> boolChecks 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
Section titled “isPaused”isPaused :: proc () -> boolReturns true, if game is paused.
setPaused
Section titled “setPaused”setPaused :: proc (paused: bool)Setter for pausing the game (equivalent to setTimeScale(0.0)).
Stops getDeltaTime, but not getUnscaledDeltaTime.
setTimeScale
Section titled “setTimeScale”setTimeScale :: proc (scale: f32)Sets the speed multiplier of game time.
(default: 1.0).