basic-game-framework/src/engine.cc

53 lines
984 B
C++

#include "engine.hpp"
#include "corelib/assets.h"
#include "corelib/render.h"
#include "SDL2/SDL_image.h"
int engine_start() {
init_context();
return 0;
}
int engine_shutdown() {
clean_assets();
close_context();
exit(0);
}
void handle_events() {
while(SDL_PollEvent(&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();
}
engine_shutdown();
return 0;
}
int main(int argc, char* argv[]) {
engine_start();
engine_run();
engine_shutdown();
}