From c0f1678142aac773ca08cd7c3459ca6d68c6442f Mon Sep 17 00:00:00 2001 From: Quinn Date: Tue, 18 Feb 2025 20:03:13 +0100 Subject: [PATCH] start using gametime --- src/error.c | 1 + src/game/gametime.h | 2 +- src/main.c | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/error.c b/src/error.c index c0384c3..7fb5df5 100644 --- a/src/error.c +++ b/src/error.c @@ -10,6 +10,7 @@ #define PRINT_BUFFER_SIZE 128 // defines the buffer size for printing // writes the arguments to the specified buffer +// using a macro instead of an inline function because fmt otherwise gets horribly messed up #define write_args(buf, fmt) \ va_list args; \ va_start(args, fmt); \ diff --git a/src/game/gametime.h b/src/game/gametime.h index 647060f..f3863e5 100644 --- a/src/game/gametime.h +++ b/src/game/gametime.h @@ -25,7 +25,7 @@ static inline void gametime_update(gametime* gt) { gt->ts = ts; } -// gets how many times the +// gets how many times the game updates per second static inline float gametime_get_ups(gametime* gt) { return 1.0F / gt->deltatime; } diff --git a/src/main.c b/src/main.c index f647b11..e47a758 100644 --- a/src/main.c +++ b/src/main.c @@ -5,10 +5,13 @@ #include "error.h" #include "game/game.h" +#include "game/gametime.h" #include "window/render.h" -static gamedata gdat; // initialized in init(), reading beforehand is undefined behaviour -static renderdata rdat; // initialized in init(), reading beforehand is undefined behaviour +// initialized in init(), reading beforehand is undefined behaviour +static gametime gt; +static gamedata gdat; +static renderdata rdat; // initialize the game static void init(void) { @@ -17,6 +20,7 @@ static void init(void) { error(ERROR_SDL_INIT, "SDL could not initialize! SDL Error: %s", SDL_GetError()); // initialize other game components + gt = gametime_new(); game_init(&gdat); render_init(&rdat, &gdat); } @@ -36,6 +40,7 @@ static void update(void) { } // perform updates + gametime_update(>); game_update(&gdat); render_update(&rdat); }