From a28dc30b411071be95320e1f8d139e68edaf8d8d Mon Sep 17 00:00:00 2001 From: dandovlatov Date: Tue, 24 Nov 2026 22:05:04 +0400 Subject: [PATCH] FBC: NIGHT SHIFT - removed player stagger on enemy contact Damage no longer changes the player's animation or applies the full-body shader recoil. Hits only tint the actor; the walk cycle and movement continue uninterrupted. Removed the unused flinch overlay and added a regression test for movement through enemy contact. --- CMakeLists.txt | 17 +++++++++++ README.md | 5 +-- docs/ENV_ENHANCEMENT.md | 12 +++++--- src/render/models.cpp | 56 ---------------------------------- src/render/models.hpp | 17 ----------- src/render/presenter.cpp | 11 ++++--- tests/player_movement_test.cpp | 50 ++++++++++++++++++++++++++++++ 7 files changed, 84 insertions(+), 84 deletions(-) create mode 100644 tests/player_movement_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b59acde..b437de7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,23 @@ add_executable(level_core_test tests/level_core_test.cpp) target_link_libraries(level_core_test PRIVATE level_core) add_test(NAME level_core_test COMMAND level_core_test) +# Simulation-only test: the player must keep moving through enemy contact. +set(GAME_SIM_SOURCES + src/game/buffs.cpp + src/game/corruption.cpp + src/game/ritual.cpp + src/game/director.cpp + src/game/floor.cpp + src/game/player.cpp + src/game/enemies.cpp + src/game/weapons.cpp + src/game/pickups.cpp + src/game/game.cpp) +add_executable(player_movement_test tests/player_movement_test.cpp ${GAME_SIM_SOURCES}) +target_link_libraries(player_movement_test PRIVATE level_core) +add_dependencies(player_movement_test bake_level) +add_test(NAME player_movement_through_enemy_contact COMMAND player_movement_test) + set(LEVEL_JSON ${CMAKE_SOURCE_DIR}/assets/levels/floor01.json) set(BAKED_HPP ${CMAKE_SOURCE_DIR}/src/game/level_baked.hpp) add_custom_command( diff --git a/README.md b/README.md index 8018f28..ecc0bb5 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,9 @@ buffs and debuffs come from rituals and other world objects, never from a crysta The look is a brutalist 3D diorama with **sculpted low-poly Blender actors** (no 2D standees or box kits). The player is a dedicated reference-based, Blender-rigged FBC agent (yellow helmet, glowing respirator, -sage coveralls, radio, rifle with a red tip) with real Idle/Run/Dash/Fire/ -Stagger actions; the horde uses procedural walk/stagger rigs, +sage coveralls, radio, rifle with a red tip) with real Idle/Run/Dash/Fire +actions — taking a hit only tints the actor, it never staggers or stops the +walk; the horde uses procedural walk/stagger rigs, hit/kill sparks and corruption-keyed post FX with half-res bloom. A single tileable 2K concrete PBR set (generated by `tools/blender/build_materials.py`) is shared by floor, curbs and pillars via one triplanar shader and one merged mesh. diff --git a/docs/ENV_ENHANCEMENT.md b/docs/ENV_ENHANCEMENT.md index b15833c..6cd534b 100644 --- a/docs/ENV_ENHANCEMENT.md +++ b/docs/ENV_ENHANCEMENT.md @@ -334,8 +334,10 @@ markers / decals rather than Control's corruption creeping out of a body. stagger + phase from `hit_flash` / `bob_phase`). Mold, shards and props keep `uRigScale = 0`; the guard's yellow base ring is excluded by radius so it stays planted while the legs move. -- [x] **Stagger** — recoil rotates the whole body around the hips plus a short - nervous shake; reuses the existing hit-flash impulse, no new sim state. +- [x] **Stagger** — enemy-only recoil rotates the whole body around the hips + plus a short nervous shake; reuses the existing hit-flash impulse, no new + sim state. The player never gets this recoil — hits must not look like a + movement freeze. - [x] **Mold & shards** — `uRigMode` 2 gives Mold a height-weighted squash / stretch jelly wobble (amplitude scales with `e.speed`) and a hit recoil; mode 3 gives Resonance shards a normal-direction facet breath, driven by @@ -407,8 +409,10 @@ markers / decals rather than Control's corruption creeping out of a body. arm and leg chains) with painted hard weights and small joint blends; baked Idle (48f), Run (36f), Dash (18f), Fire (16f), Stagger (20f) actions. - [x] **Integration** — `assets/models/agent.glb` is skinned; `ModelBank` - loads/validates the clips, `Presenter` selects Idle/Run/Dash/Stagger from - sim state, and raylib CPU skinning feeds the existing actor shader. + loads/validates the clips, `Presenter` selects Idle/Run/Dash/Fire from + sim state, and raylib CPU skinning feeds the existing actor shader. The + baked Stagger action is unused: damage only tints the player, so enemy + contact never interrupts movement or the walk cycle. - *Accept: 1080p close-ups and bot captures show the reference silhouette and two distinct run frames; no shader changes needed for the horde.* diff --git a/src/render/models.cpp b/src/render/models.cpp index a7b659c..09eefaa 100644 --- a/src/render/models.cpp +++ b/src/render/models.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include @@ -137,29 +136,6 @@ void ModelBank::init() { TraceLog(LOG_INFO, "ACTOR: skinned agent — %d bones, %d animations (%d valid)", model.skeleton.boneCount, e.animation_count, valid); - - // One-frame overlay clip: the current locomotion pose plus a hit - // lean on the upper body only. Built once, reused every flinch. - const unsigned bones = model.skeleton.boneCount; - FlinchOverlay& f = e.flinch; - f.anim.boneCount = bones; - f.anim.keyframeCount = 1; - f.anim.keyframePoses = static_cast( - std::calloc(1, sizeof(Transform*))); - if (f.anim.keyframePoses != nullptr) { - f.anim.keyframePoses[0] = static_cast( - std::calloc(bones, sizeof(Transform))); - if (f.anim.keyframePoses[0] != nullptr) { - for (unsigned b = 0; b < bones; ++b) { - const char* name = model.skeleton.bones[b].name; - if (std::strcmp(name, "chest") == 0) f.chest = static_cast(b); - else if (std::strcmp(name, "head") == 0) f.head = static_cast(b); - else if (std::strcmp(name, "upperarm.L") == 0) f.arm_l = static_cast(b); - else if (std::strcmp(name, "upperarm.R") == 0) f.arm_r = static_cast(b); - } - f.ready = true; - } - } } TraceLog(LOG_INFO, "ACTOR: %s (%d meshes, %d materials)", file_name(id), model.meshCount, model.materialCount); @@ -179,11 +155,6 @@ void ModelBank::shutdown() { e.blend_from_clock = 0.0f; e.blend_time = 0.0f; e.blend_duration = 0.0f; - if (e.flinch.anim.keyframePoses != nullptr) { - std::free(e.flinch.anim.keyframePoses[0]); - std::free(e.flinch.anim.keyframePoses); - } - e.flinch = FlinchOverlay{}; if (e.loaded) UnloadModel(e.model); e.loaded = false; } @@ -322,33 +293,6 @@ void ModelBank::update_animation(ActorModel id, const char* name, float dt, } } -void ModelBank::flinch(ActorModel id, float amount) { - if (amount <= 0.0f) return; - const int index = static_cast(id); - if (index < 0 || index >= static_cast(ActorModel::Count)) return; - Entry& e = entries_[index]; - if (!e.loaded || !e.flinch.ready || e.model.currentPose == nullptr) return; - - Transform* pose = e.flinch.anim.keyframePoses[0]; - std::memcpy(pose, e.model.currentPose, - sizeof(Transform) * e.model.skeleton.boneCount); - - const float a = amount < 1.0f ? amount : 1.0f; - const Vector3 axis{1.0f, 0.0f, 0.0f}; - auto lean = [pose, a, axis](int bone, float angle) { - if (bone < 0) return; - pose[bone].rotation = QuaternionMultiply( - pose[bone].rotation, QuaternionFromAxisAngle(axis, angle * a)); - }; - lean(e.flinch.chest, -0.30f); - lean(e.flinch.head, -0.35f); - lean(e.flinch.arm_l, -0.35f); - lean(e.flinch.arm_r, 0.30f); - - // Single keyframe: re-applying it reproduces the base pose plus the lean. - UpdateModelAnimation(e.model, e.flinch.anim, 0.0f); -} - float ModelBank::height(ActorModel id) { switch (id) { case ActorModel::Guard: return 1.9f; diff --git a/src/render/models.hpp b/src/render/models.hpp index df0cff2..8c8a2e6 100644 --- a/src/render/models.hpp +++ b/src/render/models.hpp @@ -42,27 +42,11 @@ public: void update_animation(ActorModel id, const char* name, float dt, float blend_seconds = 0.0f); - // Layers a short upper-body flinch over the pose left by update_animation(). - // Legs/root keep their locomotion pose, so a hit never freezes the walk. - // Call after update_animation() with amount in 0..1. - void flinch(ActorModel id, float amount); - // Per-model visual height, used for health bars / floating labels. static float height(ActorModel id); static bool actor_from_name(const std::string& name, ActorModel& id); private: - // Single-frame clip holding the current locomotion pose plus a hit lean. - // Only chest/head/arms are changed, so re-applying it leaves the legs alone. - struct FlinchOverlay { - ModelAnimation anim{}; - int chest = -1; - int head = -1; - int arm_l = -1; - int arm_r = -1; - bool ready = false; - }; - struct Entry { Model model{}; ModelAnimation* animations = nullptr; @@ -73,7 +57,6 @@ private: float blend_from_clock = 0.0f; float blend_time = 0.0f; float blend_duration = 0.0f; // 0 => no cross-fade in progress - FlinchOverlay flinch{}; bool loaded = false; }; diff --git a/src/render/presenter.cpp b/src/render/presenter.cpp index ced6219..4328168 100644 --- a/src/render/presenter.cpp +++ b/src/render/presenter.cpp @@ -1303,17 +1303,18 @@ void Presenter::draw_scene(Game& game) { const float player_flash = actor_flash(game.player.hit_flash, 4.0f); // The Blender agent carries its own root bob; the old sine bob would - // double up on top of the skeletal Run/Idle clips. + // double up on top of the skeletal Run/Idle clips. Damage never changes + // the clip: hits only tint the actor, the walk keeps playing and the + // simulation never stops the player. const char* agent_clip = "Idle"; if (dash_pose_ > 0.0f) agent_clip = "Dash"; else if (fire_pose_ > 0.0f) agent_clip = "Fire"; else if (player_running_) agent_clip = "Run"; models_.update_animation(ActorModel::Guard, agent_clip, frame_dt, 0.12f); - // A hit used to swap in the Stagger clip, whose legs are locked at rest — - // the walk stopped dead. Keep locomotion and flinch the upper body only. - models_.flinch(ActorModel::Guard, player_flash * 0.9f); + // No stagger uniform for the player: a full-body recoil reads as the + // character freezing up on enemy contact. Only the red flash remains. models_.draw(ActorModel::Guard, {p.x, 0.0f, p.y}, player_yaw_, 1.0f, - WHITE, player_flash, true, player_walk_, player_flash, + WHITE, player_flash, true, player_walk_, 0.0f, anim_time_); // Enemies face the player; Hiss units add a nervous jitter. diff --git a/tests/player_movement_test.cpp b/tests/player_movement_test.cpp new file mode 100644 index 0000000..ba26767 --- /dev/null +++ b/tests/player_movement_test.cpp @@ -0,0 +1,50 @@ +// Regression: enemy contact must never stop the player from moving. +// Damage is damage — there is no hitstop / stagger / velocity zeroing in the +// simulation, so every tick (including the ticks with an active hit flash) +// advances the player by the full movement step. +#include +#include + +#include "game/game.hpp" + +namespace { + +constexpr float kDt = 1.0f / 60.0f; +constexpr int kTicks = 90; + +} // namespace + +int main() { + Game game(42); + game.player.pos = {0.0f, 0.0f}; + game.enemy_system.clear(); + // Spawn on top of the player so contact (and damage) happens at once. + game.enemy_system.spawn(EnemyType::HissBrute, {0.0f, 0.0f}, game.corruption); + + InputState in{}; + in.move_x = 1.0f; + const float expected_step = game.player.stats.move_speed * kDt; + + bool damaged = false; + bool stalled = false; + float previous_x = game.player.pos.x; + for (int tick = 0; tick < kTicks; ++tick) { + game.update(in, kDt); + const float step = game.player.pos.x - previous_x; + previous_x = game.player.pos.x; + if (game.player.hit_flash > 0.0f) damaged = true; + // Allow a little slack for float noise, but a hitstop would drop the + // step to zero and fail this outright. + if (step < expected_step * 0.9f) { + stalled = true; + std::printf("movement stalled on tick %d: step=%.4f expected=%.4f\n", + tick, step, expected_step); + } + game.events.clear(); + } + + const float travelled = game.player.pos.x; + std::printf("damaged=%d stalled=%d travelled=%.3f\n", damaged, stalled, travelled); + if (!damaged || stalled || travelled < expected_step * kTicks * 0.9f) return 1; + return 0; +}