Using stopwatch for precise timing and delta time measurements.
Using stopwatch for precise timing and delta time measurements.A stopwatch tracks both total elapsed time and delta time (time since last measurement). This is essential for frame-independent game logic, animation, and performance profiling.
It is a plain console program with its own loop rather than an App (bj_run_app) program: there is no window or event handling to drive, so the bj_sleep_ms() that paces this loop is exactly what such a program should use.
int main(
int argc,
char* argv[]) {
(void)argc; (void)argv;
return 1;
}
double elapsed = 0.0;
while (elapsed < 3.0) {
bj_trace(
"Elapsed: %.3lf s | Delay: %.3lf s", elapsed, delay);
}
return 0;
}
#define bj_trace(...)
Log a message using the BJ_LOG_TRACE level.
bj_bool bj_begin(int systems, struct bj_error **error)
Initialises the system.
void bj_end(void)
De-initialises the system.
double bj_step_stopwatch(struct bj_stopwatch *stopwatch)
Record a step and return the seconds since the previous step.
void bj_sleep_ms(int milliseconds)
Suspend the current thread for at least the given number of milliseconds.
double bj_stopwatch_total(const struct bj_stopwatch *stopwatch)
Return the seconds elapsed since the stopwatch was last reset.
Structure representing a simple stopwatch.
Logging utility functions.
Portable main() replacement with platform-aware entry shim.
Header file for system interactions.
Header file for time manipulation utilities.