basic-game-framework/src/engine.c

57 lines
1007 B
C
Raw Normal View History

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