Nimbin[12]?SDL & Graphics / sdl_runtime_compiler / src/systems/projectile_system.hpp

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/systems/projectile_system.hpp 1.7 KB · 95 lines raw
#pragma once

#include "systems/aim.hpp"
#include "text/token.hpp"
#include "utils/globals.hpp"
#include "wall/wall.hpp"

namespace
Nimbin
{

static constexpr uint8_t BOUNCED_X = 1 << 0;
static constexpr uint8_t BOUNCED_Z = 1 << 1;


enum class ProjectileLanding : uint8_t
{
    None,
    Floor,
    ProgramInput,
    Wall,
    WallText,
};


struct Projectile
{
    DynArray<Text::TokenPtr> words;

    Vec3 vel{};
    Vec3 dir{};
    Vec3 prev_centroid{};
    Vec3 launch_origin{};
    Vec3 aim_point    {};

    Vec3 track_local  {};
    Vec3 track_last   {};

    double yaw;
    double stick_t = 0.0;
    double step_dt = 0.0;

    Text::Token::Data* track_obj = nullptr;

    bool sticking      = false;
    bool collided      = false;
    bool program_stick = false;
    uint8_t bounce_state = 0;

    Wall::Position
         stick_wall    { Wall::Position::PosX };
};


struct WallTextHitTest
{
    Vec3 aabb_Min;
    Vec3 aabb_Max;

    size_t index;

    Wall::Position
           wall_position;
};


struct ProjectileResult
{
    DynArray<Text::TokenPtr> words;
    ProjectileLanding   landing = ProjectileLanding::None;

    Vec3   aim_point       {};
    Vec3   vel             {};
    size_t wall_text_index = 0;
    bool   use_aim         = false;

    Wall::Position
           wall_pos        = Wall::Position::NegZ;
};


struct ProjectileSystem
{
    void launch(DynArray<Projectile>& out,
                DynArray<Text::TokenPtr> words,
                const Vec3& fwd,
                const Aim::Result& aim);

    void update(DynArray<Projectile>&        projectiles,
                DynArray<ProjectileResult>&  results,
                const DynArray<WallTextHitTest>& wall_text_hits,
                double dt, bool program_running);
};

} // namespace Nimbin