From 6f483cb0f57985c2011698e31a1073ef312b1405 Mon Sep 17 00:00:00 2001 From: Quinn Date: Thu, 13 Feb 2025 15:31:10 +0100 Subject: [PATCH] make basic header files. --- src/error_handling.c | 12 ++++++------ src/error_handling.h | 1 + src/game/game.c | 18 ++++++++++++++++++ src/game/game.h | 11 +++++++++++ src/main.c | 27 ++++++++++++++++++++------- src/main.h | 5 ----- src/window/render.c | 19 +++++++++++++++++++ src/window/render.h | 17 +++++++++++++++++ src/window/renderer.c | 0 src/window/renderer.h | 0 10 files changed, 92 insertions(+), 18 deletions(-) delete mode 100644 src/main.h create mode 100644 src/window/render.c create mode 100644 src/window/render.h delete mode 100644 src/window/renderer.c delete mode 100644 src/window/renderer.h diff --git a/src/error_handling.c b/src/error_handling.c index b4015fd..92c0659 100644 --- a/src/error_handling.c +++ b/src/error_handling.c @@ -6,7 +6,6 @@ #include #include "SDL_messagebox.h" -#include "main.h" #define PRINT_BUFFER_SIZE 128 // defines the buffer size for printing @@ -17,9 +16,10 @@ (void)vsnprintf(buf, PRINT_BUFFER_SIZE, fmt, args); \ va_end(args); -// sets the game status (in turn exiting (if not set to STATUS_RUNNING)) -static void stop(gamestatus status) { - set_gamestatus(status); +static gamestatus status = STATUS_RUNNING; + +gamestatus get_gamestatus(void) { + return status; } void debug(char const* fmt, ...) { @@ -45,10 +45,10 @@ void warn(char const* fmt, ...) { (void)fprintf(stderr, "\033[93mW: %s\033[0m\n", buf); } -void error(gamestatus status, char const* fmt, ...) { +void error(gamestatus error_code, char const* fmt, ...) { char buf[PRINT_BUFFER_SIZE] = {0}; write_args(buf, fmt); (void)fprintf(stderr, "\033[91mE: %s\033[0m\n", buf); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "something went wrong! :O", buf, NULL); - stop(status); + status = error_code; } diff --git a/src/error_handling.h b/src/error_handling.h index 725d441..5e47d13 100644 --- a/src/error_handling.h +++ b/src/error_handling.h @@ -27,6 +27,7 @@ enum { }; typedef int8_t gamestatus; +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 e69de29..8725fce 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -0,0 +1,18 @@ +#include "game.h" + +#include "../error_handling.h" + +void game_init(game_data* dat) { + (void)dat; + error(STATUS_ERROR, "function not defined"); +} + +void game_update(game_data* dat) { + (void)dat; + error(STATUS_ERROR, "function not defined"); +} + +void game_free(game_data* dat) { + (void)dat; + error(STATUS_ERROR, "function not defined"); +} diff --git a/src/game/game.h b/src/game/game.h index e69de29..6d4a4f6 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +typedef struct { + uint8_t tmp; +} game_data; + +void game_init(game_data*); // initializes everything needed to start the game; outputs to game_data +void game_update(game_data*); // causes an update to occur within the game +void game_free(game_data*); // frees the resources associated with the game diff --git a/src/main.c b/src/main.c index 94e72b7..66d8471 100644 --- a/src/main.c +++ b/src/main.c @@ -1,17 +1,30 @@ -#include "main.h" - #include #include "error_handling.h" +#include "game/game.h" +#include "window/render.h" -static gamestatus status = STATUS_RUNNING; +static game_data gdat; // initialized in init(), reading beforehand is undefined behaviour +static render_data rdat; // initialized in init(), reading beforehand is undefined behaviour -void set_gamestatus(gamestatus new_status) { - status = new_status; +static void init(void) { + game_init(&gdat); + render_init(&rdat, &gdat); +} + +static void update(void) { + // perform updates + game_update(&gdat); + render_update(&rdat); } int32_t main(int32_t argc, char** argv) { (void)argc, (void)argv; - debug("%s", "Hello, World!"); - return status; + + init(); + + while (get_gamestatus() == STATUS_RUNNING) + update(); + + return get_gamestatus(); } diff --git a/src/main.h b/src/main.h deleted file mode 100644 index 12338fb..0000000 --- a/src/main.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "error_handling.h" - -void set_gamestatus(gamestatus); // sets the status of the game (allows for quitting the game) diff --git a/src/window/render.c b/src/window/render.c new file mode 100644 index 0000000..cbb3425 --- /dev/null +++ b/src/window/render.c @@ -0,0 +1,19 @@ +#include "render.h" + +#include "../error_handling.h" +#include "../game/game.h" + +void render_init(render_data* const rdat, game_data const* const gdat) { + (void)rdat, (void)gdat; + error(STATUS_ERROR, "function not implemented"); +} + +void render_update(render_data const* const rdat) { + (void)rdat; + error(STATUS_ERROR, "function not implemented"); +} + +void render_free(render_data* const rdat) { + (void)rdat; + error(STATUS_ERROR, "function not implemented"); +} diff --git a/src/window/render.h b/src/window/render.h new file mode 100644 index 0000000..fb995c1 --- /dev/null +++ b/src/window/render.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +#include "../game/game.h" + +// contains the data necessary for rendering +typedef struct { + SDL_Window* window; + SDL_Renderer* renderer; + game_data const* gdat; +} render_data; + +void render_init(render_data*, game_data const*); // initializes the renderer, outputs to render_data +void render_update(render_data const*); // causes a draw to occur, will also determine update rate +void render_free(render_data*); // frees the memory allocated to the renderer in render_data diff --git a/src/window/renderer.c b/src/window/renderer.c deleted file mode 100644 index e69de29..0000000 diff --git a/src/window/renderer.h b/src/window/renderer.h deleted file mode 100644 index e69de29..0000000