Refactored the FSM so that it uses a generic registry of systems to do what it needs.

This commit is contained in:
Zed A. Shaw 2026-03-23 12:47:16 -04:00
parent cbff127b40
commit e742b8772d
7 changed files with 150 additions and 118 deletions

View file

@ -58,7 +58,7 @@ namespace gui {
void FSM::MOVING(Event ) {
// this should be an optional that returns a point
if(auto move_to = $main_ui.play_move()) {
System::move_player(*move_to);
$systems.runMoving(*move_to);
run_systems();
$main_ui.dirty();
state(State::IDLE);
@ -70,7 +70,7 @@ namespace gui {
switch(ev) {
case TICK: {
dbc::log("!!!!!! FIX System::combat(0) doesn't use any weapons, only first");
System::combat(0);
$systems.runCombat(0);
run_systems();
state(State::IN_COMBAT);
} break;
@ -79,7 +79,7 @@ namespace gui {
break;
case ATTACK: {
int attack_id = std::any_cast<int>(data);
System::combat(attack_id);
$systems.runCombat(attack_id);
run_systems();
} break;
default:
@ -174,10 +174,8 @@ namespace gui {
case USE_ITEM: {
auto gui_id = std::any_cast<guecs::Entity>(data);
auto& slot_name = $status_ui.$gui.name_for(gui_id);
if(System::use_item(slot_name)) {
$status_ui.update();
}
$systems.runUseItem(slot_name);
$status_ui.update();
} break;
case MOUSE_CLICK:
mouse_action(guecs::NO_MODS);
@ -186,7 +184,7 @@ namespace gui {
mouse_action({1 << guecs::ModBit::hover});
} break;
case AIM_CLICK:
System::pickup();
$systems.runPickup();
break;
default:
break; // ignore everything else
@ -312,9 +310,6 @@ namespace gui {
$debug_ui.debug();
shaders::reload();
break;
case KEY::O:
autowalking = true;
break;
case KEY::L:
// This will go away as soon as containers work
$loot_ui.set_target($loot_ui.$temp_loot);
@ -360,10 +355,8 @@ namespace gui {
}
void FSM::render() {
$window.clear();
// this clears any attack animations, like fire
System::clear_attack();
$systems.runRender();
// BUG: this is the render for this class, and where I add an update
draw_gui();
@ -371,13 +364,7 @@ namespace gui {
}
void FSM::run_systems() {
System::generate_paths();
System::enemy_ai_initialize();
System::enemy_pathing();
System::motion();
System::collision();
System::lighting();
System::death();
$systems.runUpdate();
}
bool FSM::active() {

View file

@ -1,6 +1,7 @@
#pragma once
#include "constants.hpp"
#include "game/registry.hpp"
#include "algos/simplefsm.hpp"
#include "gui/debug_ui.hpp"
#include "gui/main_ui.hpp"
@ -35,12 +36,11 @@ namespace gui {
LootUI $loot_ui;
gui::routing::Router $router;
DNDLoot $dnd_loot;
System::Registry $systems;
FSM();
void event(game::Event ev, std::any data={});
void autowalk();
void start_autowalk(double rot_speed);
void START(game::Event ev);
void MOVING(game::Event ev);