rename error_hangling to error. Also add the needed SDL code in main.c

This commit is contained in:
2025-02-13 15:40:39 +01:00
parent 8b5c4429c8
commit 197156067d
5 changed files with 28 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
#include "error_handling.h"
#include "error.h"
#include <stdarg.h>
#include <stdint.h>

View File

@@ -1,6 +1,6 @@
#include "game.h"
#include "../error_handling.h"
#include "../error.h"
void game_init(game_data* dat) {
(void)dat;

View File

@@ -1,23 +1,47 @@
#include <SDL.h>
#include <SDL_error.h>
#include <SDL_events.h>
#include <stdint.h>
#include <stdlib.h>
#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;

View File

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