From 68c61a04be191eae4c3c3ffb467d7a4833cd3557 Mon Sep 17 00:00:00 2001 From: Quinn Date: Sat, 22 Mar 2025 12:57:12 +0100 Subject: [PATCH] fix: two gametimes were present --- src/game/game.c | 7 ++++--- src/game/game.h | 4 ++-- src/game/gametime.h | 5 +++++ src/main.c | 11 ++++------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/game/game.c b/src/game/game.c index ebd89b3..8e5b181 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -8,15 +8,15 @@ #include "gametime.h" -void game_init(gamedata* dat) { +void game_init(gamedata* dat, gametime* gt) { *dat = (gamedata){ - gametime_new(), + gt, true, }; } void game_update(gamedata* dat) { - gametime_update(&dat->time); + gametime_update(dat->time); uint8_t const* keys = SDL_GetKeyboardState(NULL); if (keys[SDL_SCANCODE_ESCAPE]) @@ -24,5 +24,6 @@ void game_update(gamedata* dat) { } void game_free(gamedata* dat) { + gametime_free(dat->time); *dat = (gamedata){0}; } diff --git a/src/game/game.h b/src/game/game.h index 5de0717..1a73cf2 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -12,10 +12,10 @@ #define TAUf (M_PIf * 2.0F) // τ constant as a 32-bit floating point typedef struct { - gametime time; + gametime* time; bool run; } gamedata; -void game_init(gamedata*); // initializes everything needed to start the game; outputs to game_data +void game_init(gamedata*, gametime*); // initializes everything needed to start the game; outputs to game_data void game_update(gamedata*); // causes an update to occur within the game void game_free(gamedata*); // frees the resources associated with the game diff --git a/src/game/gametime.h b/src/game/gametime.h index fef3eab..b8c8118 100644 --- a/src/game/gametime.h +++ b/src/game/gametime.h @@ -1,5 +1,6 @@ #pragma once +#include #include typedef struct { @@ -22,6 +23,10 @@ static inline gametime gametime_new(void) { }; } +static inline void gametime_free(gametime* gt) { + free(gt); +} + // updates the internal variables static inline void gametime_update(gametime* gt) { struct timespec ts; diff --git a/src/main.c b/src/main.c index 91b1386..27d8b79 100644 --- a/src/main.c +++ b/src/main.c @@ -21,7 +21,7 @@ static void init(void) { // initialize other game components gt = gametime_new(); - game_init(&gdat); + game_init(&gdat, >); render_init(&rdat, &gdat); } @@ -33,7 +33,7 @@ static void update(void) { while (SDL_PollEvent(&e)) { switch (e.type) { case SDL_QUIT: - gdat->run = false; + gdat.run = false; break; } } @@ -52,15 +52,12 @@ int32_t main(int32_t argc, char** argv) { init(); debug("successfully initialized!"); - while (gdat->run == true) + while (gdat.run == true) update(); debug("done! starting to free resources..."); game_free(&gdat); render_free(&rdat); SDL_Quit(); - - gamestatus exit_code = get_gamestatus(); - debug("quitting with an exit code of %u", exit_code); - return exit_code; + return 0; }