From ad22993557296b02bc0c947cb3bb6247fac8f47f Mon Sep 17 00:00:00 2001 From: banana Date: Fri, 22 Mar 2024 13:46:36 -0700 Subject: Initial commit --- game_time.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 game_time.c (limited to 'game_time.c') diff --git a/game_time.c b/game_time.c new file mode 100644 index 0000000..af116b6 --- /dev/null +++ b/game_time.c @@ -0,0 +1,21 @@ +#include +#include "./constants.h" + +int last_frame_time = 0; + +void delay(void) { + // logic to keep a fixed timestep + int time_to_wait = FRAME_TARGET_TIME - (SDL_GetTicks() - last_frame_time); + + if(time_to_wait > 0 && time_to_wait <= FRAME_TARGET_TIME) { + SDL_Delay(time_to_wait); + } +} + +float get_delta_time() { + // get a delta time factor converted to seconds + float delta_time = (SDL_GetTicks() - last_frame_time) / 1000.0f; + + last_frame_time = SDL_GetTicks(); + return delta_time; +} -- cgit v1.2.3