sdl3_3d_oop_basic_game git · main
SDL3 3D OOP basic game (entities, systems, CMake)
C++ 99%git clone https://git.christianimmanuel.de/sdl-graphics/sdl3_3d_oop_basic_game.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl3_3d_oop_basic_game/archive/sdl3_3d_oop_basic_game.tar.gzsrc/core/main.cpp raw
#define SDL_MAIN_USE_CALLBACKS 1
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#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<Game*>(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<Game*>(appstate);
static Uint64 past = SDL_GetTicksNS();
Uint64 now = SDL_GetTicksNS();
Uint64 dt_ns = now - past;
past = now;
game_->update(static_cast<double>(dt_ns));
game_->render();
return SDL_APP_CONTINUE;
}
void SDL_AppQuit(void* appstate, SDL_AppResult result)
{
(void)result;
Game* game_ = static_cast<Game*>(appstate);
game_->shutdown();
}