Banjo API 0.0.1
Multi-purpose C99 API
Loading...
Searching...
No Matches
stopwatch.c

Code example demonstrating the use of bj_stopwatch for 3 seconds.

Code example demonstrating the use of bj_stopwatch for 3 seconds.

#define BJ_AUTOMAIN_CALLBACKS
#include <banjo/log.h>
#include <banjo/main.h>
#include <banjo/system.h>
#include <banjo/time.h>
static bj_stopwatch p_stopwatch = {0};
int bj_app_begin(void** user_data, int argc, char* argv[]) {
(void)user_data; (void)argc; (void)argv;
bj_error* p_error = 0;
if (!bj_begin(&p_error)) {
bj_err("Error 0x%08X: %s", p_error->code, p_error->message);
return bj_callback_exit_error;
}
return bj_callback_continue;
}
int bj_app_iterate(void* user_data) {
(void)user_data;
bj_stopwatch_step(&p_stopwatch);
double elapsed = bj_stopwatch_elapsed(&p_stopwatch);
double delay = bj_stopwatch_delay(&p_stopwatch);
bj_trace("Elapsed: %.3lf s | Delay: %.3lf s", elapsed, delay);
bj_sleep(300);
return elapsed >= 3.0 ? bj_callback_exit_success : bj_callback_continue;
}
int bj_app_end(void* user_data, int status) {
(void)user_data;
bj_end(0);
return status;
}
uint32_t code
Error code.
Definition error.h:132
char message[BJ_ERROR_MESSAGE_MAX_LEN+1]
Optional error description.
Definition error.h:133
Error structure.
Definition error.h:131
#define bj_trace(...)
Log a message using the BJ_LOG_TRACE level.
Definition log.h:75
#define bj_err(...)
Log a message using the BJ_LOG_ERROR level.
Definition log.h:131
void bj_end(bj_error **p_error)
De-initializes the system.
bj_bool bj_begin(bj_error **p_error)
Initializes the system.
double bj_stopwatch_delay(const bj_stopwatch *p_stopwatch)
Returns the time in seconds since the last step.
void bj_sleep(int milliseconds)
Suspends the current thread for a specified duration.
void bj_stopwatch_step(bj_stopwatch *p_stopwatch)
Records a step/checkpoint in time.
double bj_stopwatch_elapsed(const bj_stopwatch *p_stopwatch)
Returns the elapsed time in seconds since the stopwatch was reset.
Structure representing a simple stopwatch.
Definition time.h:83
Logging utility functions.
Header file for system interactions.
Header file for time manipulation utilities.