From 7e5236db7c65eb13761fd97c97dbd7934990b5da Mon Sep 17 00:00:00 2001 From: Quinn Date: Sat, 22 Mar 2025 12:21:34 +0100 Subject: [PATCH] get rid of set_gamestatus as it's usecase is no longer relevant --- src/error.c | 13 +------------ src/error.h | 2 -- src/game/game.c | 4 ++-- src/game/game.h | 2 ++ src/main.c | 4 ++-- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/error.c b/src/error.c index 1939e29..11b2176 100644 --- a/src/error.c +++ b/src/error.c @@ -16,16 +16,6 @@ (void)vsnprintf(buf, PRINT_BUFFER_SIZE, fmt, args); \ va_end(args); -static gamestatus status = STATUS_RUNNING; - -void set_gamestatus(gamestatus nstatus) { - status = nstatus; -} - -gamestatus get_gamestatus(void) { - return status; -} - void debug(char const* fmt, ...) { char const* env = getenv("DEBUG"); if (env == NULL || *env != '1') @@ -66,6 +56,5 @@ noreturn void fatal(gamestatus error_code, char const* fname, uint32_t ln, char SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "something went wrong! :O", buf2, NULL); // set status, but exit immediately, as code is not allowed to execute beyond this point - set_gamestatus(error_code); - exit(status); + exit(error_code); } diff --git a/src/error.h b/src/error.h index ef7fd55..b1bedf4 100644 --- a/src/error.h +++ b/src/error.h @@ -28,8 +28,6 @@ enum { }; typedef int8_t gamestatus; -void set_gamestatus(gamestatus); // sets the current status of the game -gamestatus get_gamestatus(void); // gets the current status of the game void debug(char const*, ...); // prints a debug message to stdout if the DEBUG environment variable is set, otherwise the call is ignored. void info(char const*, ...); // prints an info message to stdout void warn(char const*, ...); // prints a warning message to stderr diff --git a/src/game/game.c b/src/game/game.c index ce27302..ebd89b3 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -6,12 +6,12 @@ #include #include -#include "../error.h" #include "gametime.h" void game_init(gamedata* dat) { *dat = (gamedata){ gametime_new(), + true, }; } @@ -20,7 +20,7 @@ void game_update(gamedata* dat) { uint8_t const* keys = SDL_GetKeyboardState(NULL); if (keys[SDL_SCANCODE_ESCAPE]) - set_gamestatus(STATUS_SUCCESS); + dat->run = false; } void game_free(gamedata* dat) { diff --git a/src/game/game.h b/src/game/game.h index 1867985..5de0717 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "gametime.h" @@ -12,6 +13,7 @@ typedef struct { gametime time; + bool run; } gamedata; void game_init(gamedata*); // initializes everything needed to start the game; outputs to game_data diff --git a/src/main.c b/src/main.c index 3693751..91b1386 100644 --- a/src/main.c +++ b/src/main.c @@ -33,7 +33,7 @@ static void update(void) { while (SDL_PollEvent(&e)) { switch (e.type) { case SDL_QUIT: - set_gamestatus(STATUS_SUCCESS); + gdat->run = false; break; } } @@ -52,7 +52,7 @@ int32_t main(int32_t argc, char** argv) { init(); debug("successfully initialized!"); - while (get_gamestatus() == STATUS_RUNNING) + while (gdat->run == true) update(); debug("done! starting to free resources...");