Operation Null Mind 0.4.1
A 2D roguelike top down shooter game made with SDL2
 
Loading...
Searching...
No Matches
time_system.c File Reference

Game timing and frame rate management. More...

#include <time_system.h>
#include <app.h>

Functions

void Time_PreUpdate ()
 [PreUpdate] Updates the time system values
 
void Time_UpdateFPS ()
 [Utility] Updates the FPS counter
 
void Time_SetTimeScale (float scale)
 [Utility] Sets the time scale.
 
void Time_ResetTotalTime ()
 [Utility] Resets the total time elapsed in the program.
 

Variables

TimeSystem time
 [Data] The initialization of the time system
 
const TimeSystem *const Time = &time
 Global read-only time system pointer for other modules.
 

Detailed Description

Game timing and frame rate management.

Handles game timing, delta time calculation, and frame rate tracking to ensure consistent gameplay across different hardware.

Author
Mango
Date
2025-03-01

Function Documentation

◆ Time_PreUpdate()

void Time_PreUpdate ( )

[PreUpdate] Updates the time system values

Called at the beginning of each frame to calculate delta time and other time-related metrics. Caps deltaTime to prevent spiral of death if the game freezes temporarily.

◆ Time_ResetTotalTime()

void Time_ResetTotalTime ( )

[Utility] Resets the total time elapsed in the program.

Zeroes out the accumulated program time, useful for timing specific operations or resetting game timers.

◆ Time_SetTimeScale()

void Time_SetTimeScale ( float  scale)

[Utility] Sets the time scale.

Adjusts the game's time scale, which can speed up or slow down the entire game. A value of 1.0 is normal speed, while 2.0 would be double speed and 0.5 would be half speed.

Parameters
scaleThe scale to set the time to.

◆ Time_UpdateFPS()

void Time_UpdateFPS ( )

[Utility] Updates the FPS counter

Calculates average FPS over different time scales to monitor performance metrics for the game.

Variable Documentation

◆ time

TimeSystem time
Initial value:
= {
.deltaTimeSeconds = 0,
.timeScale = 1,
.scaledDeltaTimeSeconds = 0,
.programElapsedTimeSeconds = 0,
.previousTick = 0
}

[Data] The initialization of the time system

◆ Time

const TimeSystem* const Time = &time

Global read-only time system pointer for other modules.