#define SDL_MAIN_USE_CALLBACKS 1 #include #include #include "utils/config.hpp" #include "utils/math.hpp" #include "core/game.hpp" #include "entities/world.hpp" #include "entities/player.hpp" static const struct { const char *key; const char *value; } extended_metadata[] = { { SDL_PROP_APP_METADATA_CREATOR_STRING, "Nimbin" }, { SDL_PROP_APP_METADATA_COPYRIGHT_STRING, "Placed in the public domain" }, { SDL_PROP_APP_METADATA_TYPE_STRING, "game" } }; static Game game; SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) { (void)argc; (void) argv; if (!game.init()) { return SDL_APP_FAILURE; } *appstate = &game; return SDL_APP_CONTINUE; } SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) { Game* game_ = static_cast(appstate); if (event->type == SDL_EVENT_QUIT) return SDL_APP_SUCCESS; game_->handleEvent(*event); return SDL_APP_CONTINUE; } SDL_AppResult SDL_AppIterate(void* appstate) { Game* game_ = static_cast(appstate); static Uint64 past = SDL_GetTicksNS(); Uint64 now = SDL_GetTicksNS(); Uint64 dt_ns = now - past; past = now; game_->update(static_cast(dt_ns)); game_->render(); return SDL_APP_CONTINUE; } void SDL_AppQuit(void* appstate, SDL_AppResult result) { (void)result; Game* game_ = static_cast(appstate); game_->shutdown(); }