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

sdl_runtime_compiler git · main

SDL3 game for running and compiling code at runtime

sdl3 c++ compiler dlopen cmake · first commit 2026-04-19 · last commit 2026-07-03 (3 months ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-runtime-compiler

C++ 72.3% C 26.2%
git clone https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler/archive/sdl_runtime_compiler.tar.gz
src/core/main.cpp 1.4 KB · 63 lines raw
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>

#include "utils/config.hpp"
#include "utils/globals.hpp"
#include "core/game.hpp"
#include "entities/world.hpp"
#include "entities/player.hpp"
#include "utils/frame_profiler.hpp"


int main()
{
    FRAME_SORT_PEAK;

    if (!SDL_Init(SDL_INIT_VIDEO)) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init failed: %s", SDL_GetError());
        return 1;
    }

    Nimbin::Game game;
    if (!game.init()) {
        SDL_Quit();
        return 1;
    }

    // Without this clamp an OS pause ruins the next physics substep
    // AND poisons profiler readings.
    constexpr Uint64 MAX_DT_NS = 100'000'000ull;   // 100 ms

    bool   running = true;
    Uint64 past    = SDL_GetTicksNS();

    while (running) {
        FRAME_BEGIN();

        { FP_ZONE("main.events");
            SDL_Event event;
            while (SDL_PollEvent(&event)) {
                if (event.type == SDL_EVENT_QUIT)
                     running = false;
                else game.handle_Event(event);
            }
        }

        Uint64 now   = SDL_GetTicksNS();
        Uint64 dt_ns = now - past;
               past  = now;

        if (dt_ns > MAX_DT_NS) dt_ns = MAX_DT_NS;

        { FP_ZONE("main.update");
            game.update(static_cast<double>(dt_ns)); }
        { FP_ZONE("main.render");
            game.render(); }

        FRAME_END();
    }

    game.shutdown();
    SDL_Quit();
    return 0;
}