sdl_runtime_compiler git · main
SDL3 game for running and compiling code at runtime
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.gzAdd Dynamic mode to sandbox boxes
assets/sandbox.c | 4 ++-- assets/sandbox.c.last_ok | 3 +-- src/states/game_state.cpp | 7 +++++++ src/systems/game_mod_abi.h | 1 + src/systems/physics_system.cpp | 6 +++--- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/assets/sandbox.c b/assets/sandbox.c index 5e72631..13c5095 100644 --- a/assets/sandbox.c +++ b/assets/sandbox.c @@ -20,8 +20,8 @@ n = n + 1 ; int game_build ( ModObject * out , int max ) { ( void ) max ; o = out ; n = 0 ; -box ( 0 , - 16 , 5 , 1 , 1 , 1 ) ; +box ( 0 , - 16 , 5 , 1 , 1 , 1, 0 ) ; text ( 0 , - 15 , 5 , "hi" ) ; -box ( 3 , - 16 , 5 , 1 , 6 , 1 ) ; +box ( 3 , - 16 , 5 , 1 , 6 , 1, 0 ) ; return n ; } diff --git a/assets/sandbox.c.last_ok b/assets/sandbox.c.last_ok index fe0c07a..a6049fc 100644 --- a/assets/sandbox.c.last_ok +++ b/assets/sandbox.c.last_ok @@ -22,7 +22,6 @@ int game_build ( ModObject * out , int max ) { o = out ; n = 0 ; box ( 0 , - 16 , 5 , 1 , 1 , 1 ) ; text ( 0 , - 15 , 5 , "hi" ) ; -#include <assert.h> -box ( 3 , - 16 , 5 , 1 , 6 , 1 ) ; assert(1); +box ( 3 , - 16 , 5 , 1 , 2 , 1 ) ; return n ; } diff --git a/src/states/game_state.cpp b/src/states/game_state.cpp index fd22a20..47341f4 100644 --- a/src/states/game_state.cpp +++ b/src/states/game_state.cpp @@ -74,7 +74,13 @@ GameState::GameState(size_t starting_level) Vec3{0, -15, -5}, Vec3{1.0, 0.5, 1.0} )); + ctx.scenery.push_back( + cpputils::make_unique<SolidBox>( + Vec3{3, -15, -5}, + Vec3{1.0, 0.5, 1.0} + )); */ + ctx.scenery.back()->body.mode = PhysicsMode::Dynamic; // debug_SpawnWords(5); } @@ -1055,6 +1061,7 @@ GameState::mod_Apply(const std::vector<ModObject>& objs) Vec3{ o.x, o.y, o.z }, Vec3{ o.hx, o.hy, o.hz }, SDL_FColor{ o.r, o.g, o.b, 1.0f }); + box->body.mode = o.dynamic ? PhysicsMode::Dynamic : PhysicsMode::Static; mod_scenery.push_back(box.get()); ctx.scenery.push_back(std::move(box)); } else { // MOD_TEXT diff --git a/src/systems/game_mod_abi.h b/src/systems/game_mod_abi.h index 24b4b0e..8ee2c8d 100644 --- a/src/systems/game_mod_abi.h +++ b/src/systems/game_mod_abi.h @@ -29,6 +29,7 @@ typedef enum { * SolidBox from them. Nothing the library allocates outlives dlclose(). */ typedef struct { int kind; /* ModObjKind */ + int dynamic; double x, y, z; /* world position (centre) */ double hx, hy, hz; /* half-extents — BOX only; ignored for TEXT */ float r, g, b; /* colour 0..1 */ diff --git a/src/systems/physics_system.cpp b/src/systems/physics_system.cpp index 8fef794..7159647 100644 --- a/src/systems/physics_system.cpp +++ b/src/systems/physics_system.cpp @@ -97,9 +97,9 @@ PhysicsSystem::resolve_PlayerVsObjects(Player& player, CarriedLine& carried, } double speed = SDL_sqrt(player.vel.x * player.vel.x + - player.vel.z * player.vel.z); - double kick = SDL_max(speed * 2.0, 4.0); - if (obj->body.mode != PhysicsMode::AiHover) + player.vel.z * player.vel.z); + double kick = SDL_max(speed * 2.0, 4.0); + if (obj->body.mode != PhysicsMode::AiHover && normal.y <= 0.0) obj->body.apply_KickImpulse({ -normal.x * kick, 0.3, -normal.z * kick }); }