get rid of set_gamestatus as it's usecase is no longer relevant

This commit is contained in:
2025-03-22 12:21:34 +01:00
parent aeaba3262f
commit 7e5236db7c
5 changed files with 7 additions and 18 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -6,12 +6,12 @@
#include <stdint.h>
#include <stdlib.h>
#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) {

View File

@@ -1,6 +1,7 @@
#pragma once
#include <math.h>
#include <stdbool.h>
#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

View File

@@ -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...");