Provides timing functionality for cooldowns, fire rates, animations, and other time-based features. More...
#include <SDL.h>#include <stdbool.h>Go to the source code of this file.
Classes | |
| struct | Timer |
| The Timer struct used to keep track of time. More... | |
Typedefs | |
| typedef struct Timer | Timer |
| The Timer struct used to keep track of time. | |
Functions | |
| Timer * | Timer_Create (float duration) |
| Creates a new timer with the specified duration. | |
| void | Timer_Start (Timer *timer) |
| Starts the timer. | |
| bool | Timer_IsFinished (Timer *timer) |
| Checks if the timer is finished. | |
| float | Timer_GetTimeLeft (Timer *timer) |
| Gets the time left on the timer. | |
| bool | Timer_IsInProgress (Timer *timer) |
| Checks if the timer is in progress. | |
| void | Timer_Destroy (Timer *timer) |
| Destroys the timer and frees its memory. | |
Provides timing functionality for cooldowns, fire rates, animations, and other time-based features.
Timer has many different uses - for cooldowns, fire rates, animations, etc. Right now, it's just a simple timer that can only be started, but not paused or stopped.
The way you use the timer is by creating a Timer object, setting its duration, and starting it. You can check if the timer is finished or in progress by using Timer_IsFinished() and Timer_IsInProgress().
The Timer struct used to keep track of time.
Used for cooldowns, delays, etc. It has a start time, an elapsed time, a duration, and flags to check if the timer is in progress or finished.
| Timer * Timer_Create | ( | float | duration | ) |
Creates a new timer with the specified duration.
| duration | The duration of the timer in seconds. |
Creates a new timer with the specified duration.
Allocates and initializes a new timer with the given duration. The timer starts in a stopped state and must be started with Timer_Start().
| duration | The duration of the timer in seconds |
| void Timer_Destroy | ( | Timer * | timer | ) |
Destroys the timer and frees its memory.
| timer | The timer to destroy. |
Destroys the timer and frees its memory.
| timer | Pointer to the timer to destroy |
| float Timer_GetTimeLeft | ( | Timer * | timer | ) |
Gets the time left on the timer.
| timer | The timer to check. |
Gets the time left on the timer.
Returns how many seconds are left before the timer completes. Returns 0 if the timer is not running or has already finished.
| timer | Pointer to the timer to check |
| bool Timer_IsFinished | ( | Timer * | timer | ) |
Checks if the timer is finished.
| timer | The timer to check. |
Checks if the timer is finished.
A timer is finished when Current Time - Timer start time > Timer duration. If the timer is not running, returns the cached finished state.
| timer | Pointer to the timer to check |
| bool Timer_IsInProgress | ( | Timer * | timer | ) |
Checks if the timer is in progress.
| timer | The timer to check. |
Checks if the timer is in progress.
Checks if the timer is in the "in progress" state.
| timer | Pointer to the timer to check |
| void Timer_Start | ( | Timer * | timer | ) |
Starts the timer.
| timer | The timer to start. |
Starts the timer.
Sets the start time to the current time and marks the timer as in progress. If the timer was already running, this will restart it.
| timer | Pointer to the timer to start |