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

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

Fix snap to line if close to wall With Claude

Christian Immanuel · 2026-05-31 07:13 · c5b89fc1eefb1a7eca41f91863d1a2adada9d6f7

 assets/sandbox.c.last_ok          |  3 ++-
 assets/sandbox.c.orig             | 27 +++++++++++++++++++++++++++
 src/systems/mod_loader.hpp        |  2 +-
 src/systems/projectile_system.cpp | 28 +++++++++++++++++++++++-----
 src/systems/projectile_system.hpp |  1 +
 src/wall/editor_wall.cpp          | 14 +++++++-------
 6 files changed, 61 insertions(+), 14 deletions(-)

diff --git a/assets/sandbox.c.last_ok b/assets/sandbox.c.last_ok
index 5e72631..fe0c07a 100644
--- a/assets/sandbox.c.last_ok
+++ b/assets/sandbox.c.last_ok
@@ -22,6 +22,7 @@ int game_build ( ModObject * out , int max ) {
 o = out ; n = 0 ;
 box ( 0 , - 16 , 5 , 1 , 1 , 1 ) ;
 text ( 0 , - 15 , 5 , "hi" ) ;
-box ( 3 , - 16 , 5 , 1 , 6 , 1 ) ;
+#include <assert.h>
+box ( 3 , - 16 , 5 , 1 , 6 , 1 ) ; assert(1);
 return n ;
 }
diff --git a/assets/sandbox.c.orig b/assets/sandbox.c.orig
new file mode 100644
index 0000000..5e72631
--- /dev/null
+++ b/assets/sandbox.c.orig
@@ -0,0 +1,27 @@
+# include "game_mod_abi.h"
+static int n ;
+static ModObject * o ;
+static void box ( double x , double y , double z , double hx , double hy , double hz ) {
+o [ n ] .kind = MOD_BOX ;
+o [ n ] .x = x ; o [ n ] .y = y ; o [ n ] .z = z ;
+o [ n ] .hx = hx ; o [ n ] .hy = hy ; o [ n ] .hz = hz ;
+o [ n ] .r = 0.6 ; o [ n ] .g = 0.6 ; o [ n ] .b = 0.8 ;
+n = n + 1 ;
+}
+static void text ( double x , double y , double z , char * t ) {
+o [ n ] .kind = MOD_TEXT ;
+o [ n ] .x = x ; o [ n ] .y = y ; o [ n ] .z = z ;
+o [ n ] .r = 1 ; o [ n ] .g = 1 ; o [ n ] .b = 1 ;
+int i = 0 ;
+while ( t [ i ] != 0 ) { o [ n ] .text [ i ] = t [ i ] ; i = i + 1 ; }
+o [ n ] .text [ i ] = 0 ;
+n = n + 1 ;
+}
+int game_build ( ModObject * out , int max ) {
+( void ) max ;
+o = out ; n = 0 ;
+box ( 0 , - 16 , 5 , 1 , 1 , 1 ) ;
+text ( 0 , - 15 , 5 , "hi" ) ;
+box ( 3 , - 16 , 5 , 1 , 6 , 1 ) ;
+return n ;
+}
diff --git a/src/systems/mod_loader.hpp b/src/systems/mod_loader.hpp
index 0b1f5ce..23aaf2c 100644
--- a/src/systems/mod_loader.hpp
+++ b/src/systems/mod_loader.hpp
@@ -34,6 +34,6 @@ private:
 
     void*       handle_ { nullptr };   // current dlopen handle
 
-    static constexpr float line_height = 0.4f;
+    static constexpr float line_height = 0.25f;
     static constexpr float start_y     = -15.0f;
 };
diff --git a/src/systems/projectile_system.cpp b/src/systems/projectile_system.cpp
index 011acba..4457bcd 100644
--- a/src/systems/projectile_system.cpp
+++ b/src/systems/projectile_system.cpp
@@ -235,7 +235,23 @@ begin_EditorStick(Projectile& p, Wall::Position hit_pos)
 
     const Vec3   c_pos = Text3d::words_centroid(p.words);
     const double c_tan = wall_tangent(hit_pos, c_pos.x, c_pos.z);
-    const double c_y   = c_pos.y;
+
+    // Project along the flight direction to the wall plane, so the stick y is
+    // where the shot is HEADED on the wall, not the centroid's current height.
+    // Up close the centroid hasn't traveled, so its raw y is the spawn height;
+    // extrapolating to the plane gives the aimed-at y at any distance.
+    const double plane = wall_plane_coord(hit_pos, WORLD_BOX_SCALE);
+    const bool   x_wall = (hit_pos == Wall::Position::NegX || hit_pos == Wall::Position::PosX);
+    const double from   = x_wall ? p.launch_origin.x : p.launch_origin.z;
+    const double along  = x_wall ? p.dir.x : p.dir.z;
+
+    double c_y;
+    if (SDL_fabs(along) > 1e-6) {
+        const double t = (plane - from) / along;   // launch origin is in front → t > 0
+        c_y = p.launch_origin.y + p.dir.y * t;
+    } else {
+        c_y = c_pos.y;   // shooting parallel to wall; fall back
+    }
 
     for (Text3dPtr& w : p.words) {
         if (!w || w->type != ObjectType::Text) continue;
@@ -349,10 +365,12 @@ ProjectileSystem::launch(std::vector<Projectile>&   out,
     }
 
     Projectile proj;
-    proj.vel          = fwd * SHOOT_SPEED;
-    proj.yaw          = yaw;
-    proj.bounce_state = 0;
-    proj.words        = std::move(words);
+    proj.vel           = fwd * SHOOT_SPEED;
+    proj.yaw           = yaw;
+    proj.bounce_state  = 0;
+    proj.words         = std::move(words);
+    proj.dir           = fwd;
+    proj.launch_origin = centroid;
     out.push_back(std::move(proj));
 }
 
diff --git a/src/systems/projectile_system.hpp b/src/systems/projectile_system.hpp
index 4bede90..d786bcc 100644
--- a/src/systems/projectile_system.hpp
+++ b/src/systems/projectile_system.hpp
@@ -15,6 +15,7 @@ struct Projectile {
     Vec3     vel{};
     Vec3     dir{};
     Vec3     prev_centroid{};
+    Vec3     launch_origin{};
     double   yaw;
     uint8_t        bounce_state = 0;
     bool           sticking     = false;
diff --git a/src/wall/editor_wall.cpp b/src/wall/editor_wall.cpp
index 1bbd37b..2061dad 100644
--- a/src/wall/editor_wall.cpp
+++ b/src/wall/editor_wall.cpp
@@ -17,14 +17,13 @@ EditorWall::clear()
 EditorWall::Line*
 EditorWall::find_NearestLine(double y)
 {
-    Line*  best     = nullptr;
-    double best_dy  = SNAP_THRESHOLD_Y;
+    Line*  best    = nullptr;
+    double best_dy = SNAP_THRESHOLD_Y;
     for (Line& l : lines_) {
-        const double dy = SDL_fabs(l.y - y);
-        if (dy <= best_dy) {
-            best    = &l;
-            best_dy = dy;
-        }
+        if (l.words.empty()) continue;
+        const double center_y = l.words.front()->pos.y;   // any word on the row; they share y
+        const double dy = SDL_fabs(center_y - y);
+        if (dy <= best_dy) { best = &l; best_dy = dy; }
     }
     return best;
 }
@@ -100,6 +99,7 @@ EditorWall::on_WordPlaced(Text3d* word, const Vec3& impact_pos)
     target->words.insert(
         target->words.begin() + static_cast<std::ptrdiff_t>(p.insert_index),
         word);
+
     return snapped;
 }