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

Implementation of the timer utility. More...

#include <timer.h>
#include <time_system.h>
#include <stdlib.h>

Functions

Timer * Timer_Create (float duration)
 [Start/Utility] Creates a timer with the specified duration
 
void Timer_Start (Timer *timer)
 [Utility] Starts or restarts a timer
 
bool Timer_IsFinished (Timer *timer)
 [Utility] Determines whether a timer is finished
 
float Timer_GetTimeLeft (Timer *timer)
 [Utility] Gets the remaining time before a timer finishes
 
bool Timer_IsInProgress (Timer *timer)
 [Utility] Determines whether a timer is currently running
 
void Timer_Destroy (Timer *timer)
 [Utility] Destroys a timer and frees its memory
 

Detailed Description

Implementation of the timer utility.

Provides functionality for creating, starting, checking, and destroying timers. Timers are used for cooldowns, fire rates, animations, and other time-based features.

Author
Mango
Date
2025-03-02

Function Documentation

◆ Timer_Create()

Timer * Timer_Create ( float  duration)

[Start/Utility] Creates a timer with the specified duration

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().

Parameters
durationThe duration of the timer in seconds
Returns
Timer* Pointer to the newly created timer

◆ Timer_Destroy()

void Timer_Destroy ( Timer *  timer)

[Utility] Destroys a timer and frees its memory

Destroys the timer and frees its memory.

Parameters
timerPointer to the timer to destroy

◆ Timer_GetTimeLeft()

float Timer_GetTimeLeft ( Timer *  timer)

[Utility] Gets the remaining time before a timer finishes

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.

Parameters
timerPointer to the timer to check
Returns
float Time left in seconds, or 0 if the timer is not running

◆ Timer_IsFinished()

bool Timer_IsFinished ( Timer *  timer)

[Utility] Determines whether a timer is finished

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.

Parameters
timerPointer to the timer to check
Returns
bool True if the timer has finished, false otherwise

◆ Timer_IsInProgress()

bool Timer_IsInProgress ( Timer *  timer)

[Utility] Determines whether a timer is currently running

Checks if the timer is in progress.

Checks if the timer is in the "in progress" state.

Parameters
timerPointer to the timer to check
Returns
bool True if the timer is in progress, false otherwise

◆ Timer_Start()

void Timer_Start ( Timer *  timer)

[Utility] Starts or restarts a timer

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.

Parameters
timerPointer to the timer to start