Split timer into header and implementation file

master
Aadhavan Srinivasan 10 months ago
parent 352d3f26f1
commit 1423cc19a0

@ -3,33 +3,26 @@ 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.
#include <stdbool.h>
/* This file defines a simple timer Types, and declares functions to initialize it,
and keep track of time elapsed. The actual definition of the Timer struct is in timer.c
It was copied from https://github.com/raysan5/raylib/wiki/Frequently-Asked-Questions#how-do-i-make-a-timer */
typedef struct Timer {
typedef struct Timer_s {
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;
}
/* Starts a timer for given number of seconds */
Timer timer_init(double lifetime_secs);
bool timer_done(Timer timer)
{
return GetTime() - timer.start_time >= timer.lifetime;
}
/* Returns true when timer finishes, false if not */
bool timer_done(Timer timer);
double timer_get_elapsed(Timer timer)
{
return GetTime() - timer.start_time;
}
/* Returns amount of time elapsed since start of timer */
double timer_get_elapsed(Timer timer);
#endif
#ifdef __cplusplus

@ -0,0 +1,19 @@
#include <stdbool.h>
#include "includes/timer.h"
#include "includes/raygui/raygui.h"
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;
}
Loading…
Cancel
Save