implement new code, and remove deprecated old code. Overal optimisation.

this code is currently broken, but this'll be fixed in a subsequent
commit
This commit is contained in:
2025-06-25 15:51:27 +02:00
parent a202442853
commit 937ecedfe3
12 changed files with 252 additions and 550 deletions

View File

@@ -1,62 +1,23 @@
#include <SDL.h>
#include <SDL_error.h>
#include <SDL_events.h>
#include <SDL_ttf.h>
#include <stdlib.h>
#include "error.h"
#include "game/game.h"
#include "game/paths.h"
#include "io/render.h"
#include "io/window.h"
// initialized in init(), reading beforehand is undefined behaviour
static gamedata gdat;
static renderdata rdat;
// initialize the game
static void init(void) {
// initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) fatal(ERROR_SDL_INIT, "SDL could not initialize! SDL Error: %s", SDL_GetError());
if (TTF_Init() != 0) fatal(ERROR_SDL_FONT_INIT, "the TTF module of SDL could not initialize! TTF Error: %s", TTF_GetError());
// initialize other game components
paths_init();
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:
gdat.run = false;
break;
}
}
}
// perform updates
game_update(&gdat);
render_update(&rdat);
static void stop(void) {
debug("stopping...", );
window_close();
SDL_Quit();
}
// entry-point of the application
int main(int argc, char** argv) {
(void)argc, (void)argv;
// register stop as exit function
atexit(stop);
init();
debug("successfully initialized!", );
window_open(game_init());
while (gdat.run == true)
update();
debug("done! starting to free resources...", );
game_free(&gdat);
render_free(&rdat);
paths_free();
SDL_Quit();
return 0;
}