You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
784 B
C
38 lines
784 B
C
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
#ifndef _TIMER_H
|
|
#define _TIMER_H
|
|
/* This file defines a simple timer struct, and methods to initialize it,
|
|
and keep track of time elapsed.
|
|
It was copied from https://github.com/raysan5/raylib/wiki/Frequently-Asked-Questions#how-do-i-make-a-timer */
|
|
|
|
typedef struct Timer {
|
|
double start_time; // Start time (seconds)
|
|
double lifetime; // Lifetime (seconds)
|
|
} Timer;
|
|
|
|
Timer timer_init(double lifetime_secs)
|
|
{
|
|
Timer timer;
|
|
timer.start_time = GetTime();
|
|
timer.lifetime = lifetime_secs;
|
|
|
|
return timer;
|
|
}
|
|
|
|
bool timer_done(Timer timer)
|
|
{
|
|
return GetTime() - timer.start_time >= timer.lifetime;
|
|
}
|
|
|
|
double timer_get_elapsed(Timer timer)
|
|
{
|
|
return GetTime() - timer.start_time;
|
|
}
|
|
|
|
#endif
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|