From 197156067d7b8393a782372151b67f4e1b1a0192 Mon Sep 17 00:00:00 2001 From: Quinn Date: Thu, 13 Feb 2025 15:40:39 +0100 Subject: [PATCH] rename `error_hangling` to `error`. Also add the needed SDL code in `main.c` --- src/{error_handling.c => error.c} | 2 +- src/{error_handling.h => error.h} | 0 src/game/game.c | 2 +- src/main.c | 26 +++++++++++++++++++++++++- src/window/render.c | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) rename src/{error_handling.c => error.c} (98%) rename src/{error_handling.h => error.h} (100%) diff --git a/src/error_handling.c b/src/error.c similarity index 98% rename from src/error_handling.c rename to src/error.c index aee0e2c..ea9495a 100644 --- a/src/error_handling.c +++ b/src/error.c @@ -1,4 +1,4 @@ -#include "error_handling.h" +#include "error.h" #include #include diff --git a/src/error_handling.h b/src/error.h similarity index 100% rename from src/error_handling.h rename to src/error.h diff --git a/src/game/game.c b/src/game/game.c index 8725fce..a138369 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -1,6 +1,6 @@ #include "game.h" -#include "../error_handling.h" +#include "../error.h" void game_init(game_data* dat) { (void)dat; diff --git a/src/main.c b/src/main.c index 66d8471..c043e2a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,23 +1,47 @@ +#include +#include +#include #include +#include -#include "error_handling.h" +#include "error.h" #include "game/game.h" #include "window/render.h" static game_data gdat; // initialized in init(), reading beforehand is undefined behaviour static render_data rdat; // initialized in init(), reading beforehand is undefined behaviour +// initialize the game static void init(void) { + // initialize SDL + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) + error(ERROR_SDL_INIT, "SDL could not initialize! SDL Error: %s", SDL_GetError()); + + // initialize other game components game_init(&gdat); render_init(&rdat, &gdat); } +// perform the updates to the game static void update(void) { + // update the input + { + SDL_Event e; + while (SDL_PollEvent(&e)) { + switch (e.type) { + case SDL_QUIT: + exit(STATUS_SUCCESS); + break; + } + } + } + // perform updates game_update(&gdat); render_update(&rdat); } +// entry-point of the application int32_t main(int32_t argc, char** argv) { (void)argc, (void)argv; diff --git a/src/window/render.c b/src/window/render.c index cbb3425..65a488e 100644 --- a/src/window/render.c +++ b/src/window/render.c @@ -1,6 +1,6 @@ #include "render.h" -#include "../error_handling.h" +#include "../error.h" #include "../game/game.h" void render_init(render_data* const rdat, game_data const* const gdat) {