Banjo API 0.0.1
C99 game development API
|
Data Structures | |
struct | bj_stopwatch |
Typedefs | |
typedef struct bj_stopwatch | bj_stopwatch |
Functions | |
uint64_t | bj_get_time (void) |
void | bj_sleep (int milliseconds) |
double | bj_run_time (void) |
uint64_t | bj_time_counter (void) |
uint64_t | bj_time_frequency (void) |
void | bj_reset_stopwatch (bj_stopwatch *p_stopwatch) |
void | bj_step_stopwatch (bj_stopwatch *p_stopwatch) |
double | bj_stopwatch_elapsed (const bj_stopwatch *p_stopwatch) |
double | bj_stopwatch_delay (const bj_stopwatch *p_stopwatch) |
double | bj_step_delay_stopwatch (bj_stopwatch *p_stopwatch) |
High-level and low-level time management utilities, including thread sleeping, time counters, and a simple stopwatch abstraction.
struct bj_stopwatch |
Structure representing a simple stopwatch.
A stopwatch records the time it was last reset and the time of the last step. It computes elapsed time since reset, and delay since the last step. A zero-initialized stopwatch is valid and will auto-reset on first use.
Data Fields | ||
---|---|---|
uint64_t | last_tick | Time of last step/checkpoint. |
uint64_t | start_counter | Time when stopwatch was last reset. |
typedef struct bj_stopwatch bj_stopwatch |
Structure representing a simple stopwatch.
A stopwatch records the time it was last reset and the time of the last step. It computes elapsed time since reset, and delay since the last step. A zero-initialized stopwatch is valid and will auto-reset on first use.
uint64_t bj_get_time | ( | void | ) |
Get the current system time in seconds since the Unix epoch.
The returned value is the number of whole seconds elapsed since 1970-01-01 00:00:00 UTC (Unix epoch). This is the standard "wall-clock" system time.
void bj_reset_stopwatch | ( | bj_stopwatch * | p_stopwatch | ) |
Resets the stopwatch to the current time.
Records the current time as both the reset point and last step. Clears any prior timing information.
p_stopwatch | Pointer to the stopwatch. |
double bj_run_time | ( | void | ) |
Gets the current time in seconds since Banjo initialization.
This function returns the time in seconds since bj_initialize was called. It is suitable for general-purpose timing, but not for high-resolution use.
void bj_sleep | ( | int | milliseconds | ) |
Suspends the current thread for a specified duration.
This function puts the current thread to sleep for at least the specified number of milliseconds. The actual sleep duration may be longer depending on the system.
milliseconds | Number of milliseconds to sleep. |
double bj_step_delay_stopwatch | ( | bj_stopwatch * | p_stopwatch | ) |
Steps the stopwatch and returns the delay since the previous step.
Equivalent to calling bj_stopwatch_delay followed by bj_step_stopwatch, but more efficient and concise.
p_stopwatch | Pointer to the stopwatch. |
void bj_step_stopwatch | ( | bj_stopwatch * | p_stopwatch | ) |
Records a step/checkpoint in time.
Updates the internal step timestamp. This does not affect the reset time, but is used to measure time deltas via bj_stopwatch_delay or bj_step_delay_stopwatch.
p_stopwatch | Pointer to the stopwatch. |
double bj_stopwatch_delay | ( | const bj_stopwatch * | p_stopwatch | ) |
Returns the time in seconds since the last step.
If the stopwatch has never been used, it will be reset automatically on first use. This function does not modify the stopwatch state.
p_stopwatch | Pointer to the stopwatch. |
double bj_stopwatch_elapsed | ( | const bj_stopwatch * | p_stopwatch | ) |
Returns the elapsed time in seconds since the stopwatch was reset.
If the stopwatch has never been explicitly reset, it will be reset automatically on first use.
p_stopwatch | Pointer to the stopwatch. |
uint64_t bj_time_counter | ( | void | ) |
Returns the current high-resolution time counter.
This value is in platform-dependent ticks and is suitable for precise timing and performance measurements. To convert ticks to seconds, divide by the result of bj_time_frequency.
uint64_t bj_time_frequency | ( | void | ) |
Returns the frequency of the high-resolution counter.
This is the number of ticks per second returned by bj_time_counter. Use this to convert tick counts to seconds.