From adcfbb883e84fc7988a1cdaa54fedf69bfe7852b Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 10 Aug 2026 14:30:05 -0400 Subject: [PATCH] FSM now working better with animations spawning again. Still need to resolve enemies that run away jumping around, which is caused by run_systems() too much. --- Makefile | 2 +- src/game/systems.cpp | 7 +++-- src/gui/fsm.cpp | 71 ++++++++++++++++++++++++++++++++------------ src/gui/fsm.hpp | 2 ++ 4 files changed, 59 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 0379c2c..db308ff 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ tracy_build: meson compile -j 10 -C builddir test: build - ./builddir/fuc2it -d yes + ./builddir/fuc2it yes run: build test ifeq '$(OS)' 'Windows_NT' diff --git a/src/game/systems.cpp b/src/game/systems.cpp index 4080f95..2d35fc7 100644 --- a/src/game/systems.cpp +++ b/src/game/systems.cpp @@ -190,7 +190,7 @@ void System::distribute_loot(Position target_pos) { } set_position(world, *level.collision, loot_entity, target_pos); - level.world->send(game::Event::ENTITY_SPAWN, loot_entity, {}); + level.world->send(game::Event::ENTITY_SPAWN, loot_entity, {loot_entity}); } void System::death() { @@ -209,8 +209,9 @@ void System::death() { // we won't change out the player's components later dead_things.push_back(ent); } + // we need to send this event for everything that dies - world.send(game::Event::DEATH, ent, {}); + world.send(game::Event::DEATH, ent, {ent}); } else if(combat.almost_dead()) { // if enemies are below 50% health they are marked with bad health if(world.has(ent)) { @@ -473,7 +474,7 @@ void System::drop_item(Entity item) { set_position(world, *level.collision, item, drop_spot); level.world->not_constant(item); - level.world->send(game::Event::ENTITY_SPAWN, item, {}); + level.world->send(game::Event::ENTITY_SPAWN, item, {item}); } // NOTE: I think pickup and this need to be different diff --git a/src/gui/fsm.cpp b/src/gui/fsm.cpp index 0b10f33..058b7a9 100644 --- a/src/gui/fsm.cpp +++ b/src/gui/fsm.cpp @@ -1,3 +1,4 @@ +#define FSM_DEBUG 1 #include "gui/fsm.hpp" #include #include @@ -75,11 +76,29 @@ namespace gui { } void FSM::ATTACKING(Event ev, std::any data) { - // BUG: the way this locks animations is weird - if(!$main_ui.hands_playing()) { - // run combat one more time - $systems.runCombat(0); - state(State::IDLE); + using enum Event; + + switch(ev) { + case ENTITY_SPAWN: + entity_spawned(std::any_cast(data)); + break; + case COMBAT: + break; + case COMBAT_START: + break; + case DEATH: + something_died(std::any_cast(data)); + break; + case TICK: + run_systems(); + + if(!$main_ui.hands_playing()) { + // run combat one more time + state(State::IDLE); + } + break; + default: + dbc::log($F("Unhandled attacking event: {}", magic_enum::enum_name(ev))); } } @@ -142,7 +161,6 @@ namespace gui { case ATTACK: $main_ui.play_hands(); $main_ui.dirty(); - sound::play("sword_hit_1"); $systems.runCombat(0); run_systems(); $status_ui.update(); @@ -204,24 +222,38 @@ namespace gui { case NEW_RITUAL: $combat_ui.init(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT); break; - case DEATH: { - // BUG: this is hot dogshit - auto world = GameDB::current_world(); - auto player = world->get_the(); - auto entity = std::any_cast(data); - - $status_ui.update(); - if(entity != player.entity) { - $main_ui.dead_entity(entity); - } else { - dbc::log("NEED TO HANDLE PLAYER DYING."); - } - } break; + case DEATH: + something_died(std::any_cast(data)); + break; + case ENTITY_SPAWN: + entity_spawned(std::any_cast(data)); + break; default: break; // ignore everything else } } + void FSM::entity_spawned(DinkyECS::Entity entity) { + auto world = GameDB::current_world(); + auto& sprite = world->get(entity); + $main_ui.$rayview->update_sprite(entity, sprite); + $main_ui.dirty(); + run_systems(); + } + + void FSM::something_died(DinkyECS::Entity entity) { + auto world = GameDB::current_world(); + auto player = world->get_the(); + + $status_ui.update(); + + if(entity != player.entity) { + $main_ui.dead_entity(entity); + } else { + dbc::log("NEED TO HANDLE PLAYER DYING."); + } + } + void FSM::CUT_SCENE_PLAYING(Event ev, std::any data) { if($boss_scene->playing()) { if(ev == game::Event::MOUSE_CLICK) { @@ -241,6 +273,7 @@ namespace gui { void FSM::try_move(int dir, bool strafe) { auto& level = GameDB::current_level(); using enum State; + // prevent moving into occupied space Point move_to = $main_ui.plan_move(dir, strafe); diff --git a/src/gui/fsm.hpp b/src/gui/fsm.hpp index b391f38..d8a208c 100644 --- a/src/gui/fsm.hpp +++ b/src/gui/fsm.hpp @@ -80,5 +80,7 @@ namespace gui { void next_level(bool bossfight); void debug_render(); void take_screenshot(); + void something_died(DinkyECS::Entity entity); + void entity_spawned(DinkyECS::Entity entity); }; }