basic-game-framework/src/engine.c

57 lines
1007 B
C

#include "engine.h"
#include "corelib/assets.h"
#include "corelib/render.h"
#include "corelib/input.h"
int engine_start() {
init_context();
return 0;
}
int engine_shutdown() {
game_exit();
clean_assets();
close_context();
exit(0);
}
void handle_events() {
while(SDL_PollEvent(&g_context.event)) {
input_event(g_context.event);
switch(g_context.event.type) {
case SDL_QUIT:
g_context.running = 0;
break;
}
}
}
int engine_run() {
SDL_Window* window = SDL_CreateWindow("Tabletop", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 420, SDL_WINDOW_FULLSCREEN_DESKTOP);
g_context = (context_t){
.window = window,
.renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED),
.running = 1,
};
load_game();
start_game();
while(g_context.running) {
handle_events();
_render_mode = 1;
update_ui();
_render_mode = 0;
update_game();
swap_buffer();
}
return 0;
}
int main(int argc, char* argv[]) {
engine_start();
engine_run();
engine_shutdown();
}