mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-17 05:55:47 +01:00
rename error_hangling to error. Also add the needed SDL code in main.c
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "error_handling.h"
|
||||
#include "error.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "game.h"
|
||||
|
||||
#include "../error_handling.h"
|
||||
#include "../error.h"
|
||||
|
||||
void game_init(game_data* dat) {
|
||||
(void)dat;
|
||||
|
||||
26
src/main.c
26
src/main.c
@@ -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;
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user