Nimbin[12]?SDL & Graphics / sdl_runtime_compiler / src/entities/world.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/entities/world.cpp 1.5 KB · 76 lines raw
#include "entities/world.hpp"
#include "utils/frame_profiler.hpp"

namespace
Nimbin
{

World::World()
{
    _wall_surfaces.generate(get_BoxScale());

    _floor_surface = cpputils::make_unique<Floor::Mandelbrot>();
    _floor_surface->generate(World::get_BoxScale(), World::get_FloorY());
}


static double
sweepAxis(double end, double min, double max, bool& hit)
{
    hit = false;

    if (end < min) {
        hit = true;
        return min;
    }

    if (end > max) {
        hit = true;
        return max;
    }

    return end;
}


PlayerCollision
World::resolve_Player(const Player& player) const
{
    PlayerCollision out;
    out.vel = player.vel;

    const double min = -get_BoxScale() + player.radius;
    const double max =  get_BoxScale() - player.radius;

    const double minY = player.height - get_BoxScale();
    const double maxY = get_BoxScale();

    out.pos.x = sweepAxis(player.pos.x, min,  max,  out.hit_x);
    out.pos.y = sweepAxis(player.pos.y, minY, maxY, out.hit_y);
    out.pos.z = sweepAxis(player.pos.z, min,  max,  out.hit_z);

    if (out.hit_x) out.vel.x = 0;
    if (out.hit_y) out.vel.y = 0;
    if (out.hit_z) out.vel.z = 0;

    return out;
}


void
World::draw(GlRenderer& gl, const Camera& camera, const Light& light) const
{
    { FP_ZONE("world.draw.wall");
        _wall_surfaces.draw(gl, camera, light); }
    { FP_ZONE("world.draw.floor");
        _floor_surface->draw(gl, camera, light);
    }

}


Vec3
World::get_SpawnPoint() const
{ return {0.0, 2.0, 0.0}; }

} // namespace Nimbin