Manages time-related functionality for frame rate independence and timing. More...
#include <SDL.h>Go to the source code of this file.
Classes | |
| struct | TimeSystem |
| Structure to handle time-related functionality. More... | |
Typedefs | |
| typedef struct TimeSystem | TimeSystem |
| Structure to handle time-related functionality. | |
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 | |
| const TimeSystem *const | Time |
| Global read-only time system pointer for other modules. | |
Manages time-related functionality for frame rate independence and timing.
The time system struct is used to keep track of the program's time, delta time, and time scale. Time delta is the time between the current frame and the previous frame. It's super useful for making sure that the game runs at the same speed on different fps.
Usage in updating the position of an object that's moving up with the speed of 5 units per second.
It is quite tempting to move an object something like this:
Since this is called every frame, the speed will be 5 units/frame. Which causes the speed to be dependent on the frame rate.
To make the speed independent of the frame rate, we can use the delta time like this:
This way, the object will move up 5 units per second regardless of the frame rate.
| typedef struct TimeSystem TimeSystem |
Structure to handle time-related functionality.
| 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.
| 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.
| 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.
| scale | The scale to set the time to. |
| void Time_UpdateFPS | ( | ) |
[Utility] Updates the FPS counter
Calculates average FPS over different time scales to monitor performance metrics for the game.
|
extern |
Global read-only time system pointer for other modules.