Nimbin[12]?SDL & Graphics / sdl_runtime_compiler / commits / aa50be1

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

Cleanup

Christian Immanuel · 2026-06-12 12:00 · aa50be11597065c35eba21d82784cf54d9485b3a

 src/states/game_state.cpp | 224 +++++++++++++++++++++++-----------------------
 src/text/handler.cpp      |   4 +-
 src/text/handler.hpp      |   2 +-
 3 files changed, 115 insertions(+), 115 deletions(-)

diff --git a/src/states/game_state.cpp b/src/states/game_state.cpp
index 7e104ff..3e7ee84 100644
--- a/src/states/game_state.cpp
+++ b/src/states/game_state.cpp
@@ -195,16 +195,16 @@ void
 GameState::on_Click()
 {
     if (_editor.edit_Active()) {
-        const Wall::Transform tf =
-            Wall::get_Transform(Wall::Role::Editor, World::get_BoxScale());
-        const double wx = tf.position.x;
-        const Vec3&  o  = _ctx.camera->pos;
-        const Vec3&  d  = _ctx.camera->fwd;
-
-        if (SDL_fabs(d.x) > 1e-6) {
-            const double t = (wx - o.x) / d.x;
+        const Wall::Transform wall_transform =
+                    Wall::get_Transform(Wall::Role::Editor, World::get_BoxScale());
+        const double wall_tans_x = wall_transform.position.x;
+        const Vec3&  cam_pos     = _ctx.camera->pos;
+        const Vec3&  cam_fwd     = _ctx.camera->fwd;
+
+        if (SDL_fabs(cam_fwd.x) > 1e-6) {
+            const double t = (wall_tans_x - cam_pos.x) / cam_fwd.x;
             if (t > 0.0) {
-                Vec3 impact { wx, o.y + d.y * t, o.z + d.z * t };
+                Vec3 impact { wall_tans_x, cam_pos.y + cam_fwd.y * t, cam_pos.z + cam_fwd.z * t };
                 if (_editor.cursor_AtImpact(impact)) return;
             }
         }
@@ -213,12 +213,12 @@ GameState::on_Click()
         return;
     }
 
-    PickResult r = PickSystem::pick(*_ctx.camera, _ctx.words, _ctx.scenery, _text_walls);
-    if (!r.hit()) return;
+    PickResult result = PickSystem::pick(*_ctx.camera, _ctx.words, _ctx.scenery, _text_walls);
+    if (!result.hit()) return;
 
-    if (r.kind == PickKind::Scenery && r.scenery_obj) {
+    if (result.kind == PickKind::Scenery && result.scenery_obj) {
         if (std::optional<PultAction> act =
-                _pult_sys->try_Activate(r.scenery_obj, _ctx.buttons); act)
+                _pult_sys->try_Activate(result.scenery_obj, _ctx.buttons); act)
             pult_DispatchAction(*act);
     }
 }
@@ -227,11 +227,11 @@ GameState::on_Click()
 bool
 GameState::on_Pick()
 {
-    PickResult r = PickSystem::pick(*_ctx.camera, _ctx.words, _ctx.scenery, _text_walls);
-    if (!r.hit()) return false;
+    PickResult result = PickSystem::pick(*_ctx.camera, _ctx.words, _ctx.scenery, _text_walls);
+    if (!result.hit()) return false;
 
-    if (r.kind == PickKind::WallWord && r.wall_handler && r.wall_token) {
-        Text::TokenPtr base = r.wall_handler->detach(r.wall_token);
+    if (result.kind == PickKind::WallWord && result.wall_handler && result.wall_token) {
+        Text::TokenPtr base = result.wall_handler->detach(result.wall_token);
         if (!base) return false;
 
         _level_director-> record_PickedUp(base->text);
@@ -241,9 +241,9 @@ GameState::on_Pick()
         return true;
     }
 
-    if (r.kind == PickKind::Word) {
-        Text::TokenPtr word = std::move(_ctx.words[r.word_index]);
-        _ctx.words.erase(_ctx.words.begin() + static_cast<std::ptrdiff_t>(r.word_index));
+    if (result.kind == PickKind::Word) {
+        Text::TokenPtr word = std::move(_ctx.words[result.word_index]);
+        _ctx.words.erase(_ctx.words.begin() + static_cast<std::ptrdiff_t>(result.word_index));
         if (!word) return false;
 
         _level_director->record_PickedUp(word->text);
@@ -422,21 +422,21 @@ void
 GameState::on_NumberAdjust(int delta)
 {
     if (_carried.empty() || !_carried.last || !_carried.last->word) return;
-    Text::Token::Data* w = _carried.last->word.get();
+    Text::Token::Data* word = _carried.last->word.get();
 
-    const std::string& s = w->text;
-    if (s.empty()) return;
+    const std::string& text = word->text;
+    if (text.empty()) return;
 
-    size_t start = (s[0] == '-') ? 1 : 0;
-    if (start == s.size()) return;
-    for (size_t i = start; i < s.size(); ++i)
-        if (!std::isdigit(static_cast<unsigned char>(s[i]))) return;
+    size_t start = (text[0] == '-') ? 1 : 0;
+    if (start == text.size()) return;
+    for (size_t i = start; i < text.size(); ++i)
+        if (!std::isdigit(static_cast<unsigned char>(text[i]))) return;
 
-    long val = std::strtol(s.c_str(), nullptr, 10);
+    long val = std::strtol(text.c_str(), nullptr, 10);
     val += delta;
 
-    w->text = std::to_string(val);
-    w->rebuild_Mesh();
+    word->text = std::to_string(val);
+    word->rebuild_Mesh();
 }
 
 
@@ -470,10 +470,10 @@ void
 GameState::projectile_FeedProgramInput(ProjectileResult& result)
 {
     std::string line;
-    for (const Text::TokenPtr& w : result.words) {
-        if (!w || w->type != ObjectType::Text) continue;
+    for (const Text::TokenPtr& word : result.words) {
+        if (!word || word->type != ObjectType::Text) continue;
         if (!line.empty()) line += ' ';
-        line += w->text;
+        line += word->text;
     }
     if (!line.empty())
         _program_sys->feed_Input(line);
@@ -485,12 +485,12 @@ GameState::projectile_FeedProgramInput(ProjectileResult& result)
 void
 GameState::projectile_LandOnFloor(ProjectileResult& result)
 {
-    for (Text::TokenPtr& w : result.words) {
-        if (!w || w->type != ObjectType::Text) continue;
-        w->set_Look(ConfigColor::keep, Text::Token::depth_floor);
-        w->body.mode = PhysicsMode::Dynamic;
-        w->body.vel  = result.vel;
-        _ctx.words.push_back(std::move(w));
+    for (Text::TokenPtr& word : result.words) {
+        if (!word || word->type != ObjectType::Text) continue;
+        word->set_Look(ConfigColor::keep, Text::Token::depth_floor);
+        word->body.mode = PhysicsMode::Dynamic;
+        word->body.vel  = result.vel;
+        _ctx.words.push_back(std::move(word));
     }
 }
 
@@ -500,19 +500,19 @@ GameState::projectile_LandOnWall(ProjectileResult& result)
 {
     DynArray<Text::TokenPtr> edit_block, prog_block, comp_block, info_block;
 
-    for (Text::TokenPtr& w : result.words) {
-        if (!w) continue;
-        w->body.mode = PhysicsMode::Static;
-        w->body.vel  = Vec3{0, 0, 0};
+    for (Text::TokenPtr& word : result.words) {
+        if (!word) continue;
+        word->body.mode = PhysicsMode::Static;
+        word->body.vel  = Vec3{0, 0, 0};
 
-        Wall::Drop d = Wall::attach_ToNearestWall(std::move(w));
-        if (!d.token) continue;
+        Wall::Drop drop = Wall::attach_ToNearestWall(std::move(word));
+        if (!drop.token) continue;
 
-        switch (d.role) {
-            case Wall::Role::Editor:   edit_block.push_back(std::move(d.token)); break;
-            case Wall::Role::Program:  prog_block.push_back(std::move(d.token)); break;
-            case Wall::Role::Compiler: comp_block.push_back(std::move(d.token)); break;
-            case Wall::Role::Info:     info_block.push_back(std::move(d.token)); break;
+        switch (drop.role) {
+            case Wall::Role::Editor:   edit_block.push_back(std::move(drop.token)); break;
+            case Wall::Role::Program:  prog_block.push_back(std::move(drop.token)); break;
+            case Wall::Role::Compiler: comp_block.push_back(std::move(drop.token)); break;
+            case Wall::Role::Info:     info_block.push_back(std::move(drop.token)); break;
         }
     }
 
@@ -539,57 +539,57 @@ GameState::projectile_LandOnWallText(ProjectileResult& result)
     const size_t idx = result.wall_text_index;
 
     if (idx >= LABEL_HIT_BASE) {
-        for (Text::TokenPtr& w : result.words)
-            if (w) _ctx.drop_WordToFloor(std::move(w), result.vel);
+        for (Text::TokenPtr& word : result.words)
+            if (word) _ctx.drop_WordToFloor(std::move(word), result.vel);
         return;
     }
 
     if (idx >= WALL_TOK_BASE) {
         const size_t rel = idx - WALL_TOK_BASE;
-        const size_t h   =  rel >> 28;
-        const size_t li  = (rel >> 14) & 0x3FFF;
-        const size_t ti  =  rel        & 0x3FFF;
-        Text::Handler* hw = (h < _text_walls.size()) ? _text_walls[h] : nullptr;
+        const size_t handler_id   =  rel >> 28;
+        const size_t line_id  = (rel >> 14) & 0x3FFF;
+        const size_t token_id  =  rel        & 0x3FFF;
+        Text::Handler* handler = (handler_id < _text_walls.size()) ? _text_walls[handler_id] : nullptr;
 
-                if (hw) {
-            const auto& lines = hw->get_Lines();
-            if (li < lines.size() && ti < lines[li].tokens.size() && lines[li].tokens[ti]) {
+        if (handler) {
+            const auto& lines = handler->get_Lines();
+            if (line_id < lines.size() && token_id < lines[line_id].tokens.size() && lines[line_id].tokens[token_id]) {
 
-                if (hw->is_Mono()) {
-                    Vec3 impact = lines[li].tokens[ti]->pos;
+                if (handler->is_Mono()) {
+                    Vec3 impact = lines[line_id].tokens[token_id]->pos;
                     for (const Text::TokenPtr& w : result.words)
                         if (w) { impact = w->pos; break; }
 
-                    const Text::Handler::EditorHit hit = hw->classify_Impact(impact);
+                    const Text::Handler::EditorHit hit = handler->classify_Impact(impact);
 
                     if (hit.kind == Text::Handler::HitKind::DropToken) {
-                        const auto& ls = hw->get_Lines();
-                        if (hit.li < ls.size() && hit.ti < ls[hit.li].tokens.size() && ls[hit.li].tokens[hit.ti]) {
-                            if (Text::TokenPtr orphan = hw->detach(ls[hit.li].tokens[hit.ti].get())) {
+                        const auto& ls = handler->get_Lines();
+                        if (hit.line_id < ls.size() && hit.token_id < ls[hit.line_id].tokens.size() && ls[hit.line_id].tokens[hit.token_id]) {
+                            if (Text::TokenPtr orphan = handler->detach(ls[hit.line_id].tokens[hit.token_id].get())) {
                                 orphan->body.hover_height = World::get_FloorY<double>() + 1.5;
                                 orphan->yaw               = 0.0f;
                                 _ctx.drop_WordToFloor(std::move(orphan), Vec3{0.0, 1.5, 0.0});
                             }
                         }
-                        for (Text::TokenPtr& w : result.words)
-                            if (w) _ctx.drop_WordToFloor(std::move(w), result.vel);
+                        for (Text::TokenPtr& word : result.words)
+                            if (word) _ctx.drop_WordToFloor(std::move(word), result.vel);
                     } else {
                         DynArray<Text::TokenPtr> block;
-                        for (Text::TokenPtr& w : result.words) if (w) block.push_back(std::move(w));
-                        hw->attach(std::move(block), impact);
+                        for (Text::TokenPtr& word : result.words) if (word) block.push_back(std::move(word));
+                        handler->attach(std::move(block), impact);
                     }
                     return;
                 }
 
-                if (Text::TokenPtr orphan = hw->detach(lines[li].tokens[ti].get())) {
+                if (Text::TokenPtr orphan = handler->detach(lines[line_id].tokens[token_id].get())) {
                     orphan->body.hover_height = World::get_FloorY<double>() + 1.5;
                     orphan->yaw               = 0.0f;
                     _ctx.drop_WordToFloor(std::move(orphan), Vec3{0.0, 1.5, 0.0});
                 }
             }
         }
-        for (Text::TokenPtr& w : result.words)
-            if (w) _ctx.drop_WordToFloor(std::move(w), result.vel);
+        for (Text::TokenPtr& word : result.words)
+            if (word) _ctx.drop_WordToFloor(std::move(word), result.vel);
         return;
     }
 
@@ -628,8 +628,8 @@ GameState::update(double dt, const GlRenderer* gl)
     { FP_ZONE("update.progression"); update_Progression (dt);       }
     { FP_ZONE("update.highlight"  ); update_Highlighting();         }
 
-    input.look_x = 0;
-    input.look_y = 0;
+    input.look_x   = 0;
+    input.look_y   = 0;
     input.scroll_x = 0;
     input.scroll_y = 0;
     input.commands.clear();
@@ -731,8 +731,8 @@ GameState::update_Input(FrameInput& input, double dt)
 void
 GameState::update_Objects(double dt, const GlRenderer* gl)
 {
-    for (Wall::Label& lbl : _wall_labels)
-        lbl.update(dt, *_ctx.camera);
+    for (Wall::Label& label : _wall_labels)
+        label.update(dt, *_ctx.camera);
 
     carriedline_Update();
 
@@ -747,8 +747,8 @@ GameState::update_Objects(double dt, const GlRenderer* gl)
     _pult_sys ->update(dt, *_ctx.camera);
     _plate_sys->update(dt, *_ctx.player, _level_director->get_StepPlates());
 
-    for (Text::Handler* h : _text_walls)
-        if (h) h->update(dt, *_ctx.camera);
+    for (Text::Handler* handler : _text_walls)
+        if (handler) handler->update(dt, *_ctx.camera);
 
     _wall_connection.update(dt, *_ctx.camera, gl->get_Aspect(), gl->get_Fov_y());
 
@@ -823,23 +823,23 @@ GameState::render(SDL_Window& window, GlRenderer& renderer)
     { FP_ZONE("render.world");        _ctx.world ->draw(renderer, *_ctx.camera, *_ctx.light); }
 
     { FP_ZONE("render.text_walls");
-        for (Text::Handler* t : _text_walls)
-            if (t) t->render(renderer, *_ctx.camera, *_ctx.light);
+        for (Text::Handler* handler : _text_walls)
+            if (handler) handler->render(renderer, *_ctx.camera, *_ctx.light);
     }
 
     { FP_ZONE("render.scenery");
-        for (const GameObjectPtr& s : _ctx.scenery)
-            if (s) s->draw(renderer, *_ctx.camera, *_ctx.light);
+        for (const GameObjectPtr& scenery : _ctx.scenery)
+            if (scenery) scenery->draw(renderer, *_ctx.camera, *_ctx.light);
     }
 
     { FP_ZONE("render.words");
-        for (const Text::TokenPtr& t : _ctx.words)
-            if (t) t->draw(renderer, *_ctx.camera, *_ctx.light);
+        for (const Text::TokenPtr& word : _ctx.words)
+            if (word) word->draw(renderer, *_ctx.camera, *_ctx.light);
     }
 
     { FP_ZONE("render.wall_labels");
-        for (const Wall::Label& lbl : _wall_labels)
-            lbl.draw(renderer, *_ctx.camera, *_ctx.light);
+        for (const Wall::Label& label : _wall_labels)
+            label.draw(renderer, *_ctx.camera, *_ctx.light);
     }
 
     { FP_ZONE("render._carried");
@@ -850,32 +850,32 @@ GameState::render(SDL_Window& window, GlRenderer& renderer)
     }
 
     { FP_ZONE("render.anims");
-        for (const WordAnim_Add& a : _anims_add)
-            if (a.word) a.word->draw(renderer, *_ctx.camera, *_ctx.light);
-        for (const WordAnim_Drop& d : _anims_drop)
-            if (d.word) d.word->draw(renderer, *_ctx.camera, *_ctx.light);
+        for (const WordAnim_Add& anim : _anims_add)
+            if (anim.word) anim.word->draw(renderer, *_ctx.camera, *_ctx.light);
+        for (const WordAnim_Drop& drop : _anims_drop)
+            if (drop.word) drop.word->draw(renderer, *_ctx.camera, *_ctx.light);
     }
 
     { FP_ZONE("render.ai.stolen");
-        for (const Text::TokenPtr& t : _ctx.words) {
-            if (!t) continue;
-            for (const Text::TokenPtr& s : t->ai.stolen)
+        for (const Text::TokenPtr& word : _ctx.words) {
+            if (!word) continue;
+            for (const Text::TokenPtr& s : word->ai.stolen)
                 if (s) s->draw(renderer, *_ctx.camera, *_ctx.light);
         }
     }
 
     { FP_ZONE("render._projectiles");
         for (const Projectile& proj : _projectiles)
-            for (const Text::TokenPtr& wd : proj.words)
-                if (wd) wd->draw(renderer, *_ctx.camera, *_ctx.light);
+            for (const Text::TokenPtr& word : proj.words)
+                if (word) word->draw(renderer, *_ctx.camera, *_ctx.light);
     }
 
-    { FP_ZONE("render.hint");        _hint_sys    ->draw(renderer, *_ctx.camera, *_ctx.light); }
-    { FP_ZONE("render.pult_labels"); _pult_sys    ->draw_Labels(renderer, *_ctx.camera, *_ctx.light); }
-    { FP_ZONE("render.particles");   _particle_sys->draw(renderer, *_ctx.camera, *_ctx.light); }
-    { FP_ZONE("render.celebration"); _celebration_sys->draw(renderer, *_ctx.camera, *_ctx.light); }
-    { FP_ZONE("render.wall_edit");   _wall_connection.render(renderer, *_ctx.camera, *_ctx.light); }
-    { FP_ZONE("render.end_Frame");   renderer.end_Frame(&window); }
+    { FP_ZONE("render.hint"       ); _hint_sys        ->draw(renderer, *_ctx.camera, *_ctx.light); }
+    { FP_ZONE("render.pult_labels"); _pult_sys        ->draw_Labels(renderer, *_ctx.camera, *_ctx.light); }
+    { FP_ZONE("render.particles"  ); _particle_sys    ->draw(renderer, *_ctx.camera, *_ctx.light); }
+    { FP_ZONE("render.celebration"); _celebration_sys ->draw(renderer, *_ctx.camera, *_ctx.light); }
+    { FP_ZONE("render.wall_edit"  ); _wall_connection.render(renderer, *_ctx.camera, *_ctx.light); }
+    { FP_ZONE("render.end_Frame"  ); renderer.end_Frame(&window); }
 }
 
 
@@ -893,8 +893,8 @@ GameState::update_Physics(double dt)
 
     DynArray<GameObject*> colliders;
     colliders.reserve(_ctx.scenery.size() + _ctx.words.size());
-    for (const GameObjectPtr& p : _ctx.scenery) if (p) colliders.push_back(p.get());
-    for (const Text::TokenPtr&     p : _ctx.words)   if (p) colliders.push_back(p.get());
+    for (const GameObjectPtr&  s : _ctx.scenery) if (s) colliders.push_back(s.get());
+    for (const Text::TokenPtr& w : _ctx.words)   if (w) colliders.push_back(w.get());
 
     { FP_ZONE("updateworldsim.phys_objects");
         _physics_sys->update_Objects(colliders, dt, 25.0);
@@ -903,8 +903,8 @@ GameState::update_Physics(double dt)
     { FP_ZONE("updateworldsim.word_ai");
         DynArray<Text::TokenPtr> ai_dropped;
         _word_ai_sys->update(_ctx.words, *_ctx.player, _carried, ai_dropped, dt);
-        for (Text::TokenPtr& d : ai_dropped) {
-            if (d) _ctx.words.push_back(std::move(d));
+        for (Text::TokenPtr& drop : ai_dropped) {
+            if (drop) _ctx.words.push_back(std::move(drop));
         }
     }
 
@@ -917,12 +917,12 @@ GameState::update_Physics(double dt)
     DynArray<Text::Handler*> all_labels = _pult_sys->get_Labels();
     { FP_ZONE("updateworldsim.hint_and_labels");
         _hint_sys->update(dt, *_ctx.camera);
-        for (Text::Handler* lbl : all_labels)
-            lbl->update(dt, *_ctx.camera);
+        for (Text::Handler* label : all_labels)
+            label->update(dt, *_ctx.camera);
 
         all_labels.push_back(&_hint_sys->get_Label());
-        for (Wall::Label& wl : _wall_labels)
-            all_labels.push_back(&wl.label);
+        for (Wall::Label& label : _wall_labels)
+            all_labels.push_back(&label.label);
     }
 
     { FP_ZONE("updateworldsim.resolve_projectiles");
@@ -932,9 +932,9 @@ GameState::update_Physics(double dt)
     DynArray<WallTextHitTest> wall_text_hits;
     { FP_ZONE("updateworldsim.build_wall_hits");
         for (size_t h = 0; h < _text_walls.size(); ++h) {
-            Text::Handler* hw = _text_walls[h];
-            if (!hw) continue;
-            const auto& elines = hw->get_Lines();
+            Text::Handler* handler = _text_walls[h];
+            if (!handler) continue;
+            const auto& elines = handler->get_Lines();
             for (size_t li = 0; li < elines.size(); ++li) {
                 const DynArray<Text::TokenPtr>& toks = elines[li].tokens;
                 for (size_t ti = 0; ti < toks.size(); ++ti) {
diff --git a/src/text/handler.cpp b/src/text/handler.cpp
index eead608..6fc17de 100644
--- a/src/text/handler.cpp
+++ b/src/text/handler.cpp
@@ -568,7 +568,7 @@ Handler::classify_Impact(const Vec3& impact) const
     }
 
     // ── horizontal on row i: re-chunk the buffer line and apply 80/20 per token span ──
-    hit.row = i; hit.li = static_cast<size_t>(i);
+    hit.row = i; hit.line_id = static_cast<size_t>(i);
     const std::string& s = blines[static_cast<size_t>(i)];
     const double vcf = (_code_left_z - impact.z) / _char_w;   // fractional visual column
 
@@ -586,7 +586,7 @@ Handler::classify_Impact(const Vec3& impact) const
             if (ws) { hit.kind = HitKind::Insert; hit.col = b1; return hit; }  // split: word after the space
             const double center = vc + vs * 0.5;
             if (SDL_fabs(vcf - center) <= 0.4 * vs) {                          // central 80% → drop
-                hit.kind = HitKind::DropToken; hit.li = static_cast<size_t>(i); hit.ti = k;
+                hit.kind = HitKind::DropToken; hit.line_id = static_cast<size_t>(i); hit.token_id = k;
                 return hit;
             }
             hit.kind = HitKind::Insert;                                        // outer 20% → beside
diff --git a/src/text/handler.hpp b/src/text/handler.hpp
index c481f18..34738ce 100644
--- a/src/text/handler.hpp
+++ b/src/text/handler.hpp
@@ -69,7 +69,7 @@ public:
     
     
     enum class HitKind : uint8_t { Insert, NewLine, DropToken };
-    struct EditorHit { HitKind kind; int row; int col; size_t li; size_t ti; };
+    struct EditorHit { HitKind kind; int row; int col; size_t line_id; size_t token_id; };
     EditorHit classify_Impact(const Vec3& impact) const;
     bool      is_Mono() const { return _layout == LayoutMode::Mono; }
     void         clear_ToFloor(DynArray<TokenPtr>& out);