Nimbin[12]?SDL & Graphics / sdl3_3d_oop_basic_game / src/core/main.cpp

sdl3_3d_oop_basic_game git · main

SDL3 3D OOP basic game (entities, systems, CMake)

sdl3 3d c++ game cmake · first commit 2026-04-19 · last commit 2026-04-19 (7 months ago) · synced 1 hour ago · upstream: git.ide3.de/chfis005/sdl3_3d_oop_basic_game

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.gz
src/core/main.cpp 1.4 KB · 71 lines 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();
}