From d99d9a68c8936415600c248a83b51f5136f99d89 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 14 Jun 2025 12:34:27 -0400 Subject: [PATCH] Tried to use Ragel to create state machines but its lacking an incremental mode and doesn't do any logging of state activity so debugging is harder. Put it in scratchpad for reference though. --- Makefile | 10 +- events.hpp | 30 -- gui/dnd_events.hpp | 14 - gui/dnd_loot_2.cpp | 230 ---------------- gui/event_router.hpp | 1 + gui/fsm.cpp | 2 + gui/fsm_events.hpp | 31 +++ meson.build | 1 - scratchpad/dnd_loot_2.cpp | 436 ++++++++++++++++++++++++++++++ {gui => scratchpad}/dnd_loot_2.rl | 99 ++++--- 10 files changed, 541 insertions(+), 313 deletions(-) delete mode 100644 gui/dnd_events.hpp delete mode 100644 gui/dnd_loot_2.cpp create mode 100644 gui/fsm_events.hpp create mode 100644 scratchpad/dnd_loot_2.cpp rename {gui => scratchpad}/dnd_loot_2.rl (61%) diff --git a/Makefile b/Makefile index 47f78bf..77b1ba6 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,15 @@ else endif %.cpp : %.rl - ragel -G1 -o $@ $< + ragel -I $(ROOT_DIR) -G1 -o $@ $< -build: $(ROOT_DIR)/gui/dnd_loot_2.cpp +%.dot: %.rl + ragel -Vp -I $(ROOT_DIR) -o $@ $< + +%.png: %.dot + dot -Tpng $< -o $@ + +build: meson compile -j 10 -C $(ROOT_DIR)/builddir release_build: diff --git a/events.hpp b/events.hpp index 88f3ab3..c5b810d 100644 --- a/events.hpp +++ b/events.hpp @@ -15,33 +15,3 @@ namespace Events { int enemy_did; }; } - -namespace gui { - enum class Event { - STARTED=0, - TICK=1, - MOVE_FORWARD = 2, - MOVE_BACK = 3, - MOVE_LEFT = 4, - MOVE_RIGHT = 5, - MAP_OPEN = 6, - CLOSE = 7, - ROTATE_LEFT = 8, - ROTATE_RIGHT = 9, - ATTACK = 10, - START_COMBAT = 11, - STOP_COMBAT = 12, - STAIRS_DOWN = 13, - LOOT_OPEN=14, - LOOT_ITEM=15, - LOOT_SELECT=16, - INV_SELECT=17, - QUIT = 18, - MOUSE_CLICK=19, - MOUSE_MOVE=20, - MOUSE_DRAG=21, - MOUSE_DRAG_START=22, - MOUSE_DROP=23, - KEY_PRESS=24 - }; -} diff --git a/gui/dnd_events.hpp b/gui/dnd_events.hpp deleted file mode 100644 index 723f0e3..0000000 --- a/gui/dnd_events.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -enum class DNDEvent { - STARTED=0, - LOOT_OPEN=14, - LOOT_ITEM=15, - LOOT_SELECT=16, - INV_SELECT=17, - MOUSE_CLICK=19, - MOUSE_MOVE=20, - MOUSE_DRAG=21, - MOUSE_DRAG_START=22, - MOUSE_DROP=23 -}; diff --git a/gui/dnd_loot_2.cpp b/gui/dnd_loot_2.cpp deleted file mode 100644 index 88cbefc..0000000 --- a/gui/dnd_loot_2.cpp +++ /dev/null @@ -1,230 +0,0 @@ - -#line 1 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" -#include -#include "gui/dnd_events.hpp" -#include -#include "gui/guecstra.hpp" -#include "gui/uisystems.hpp" -#include -#include "gui/status_ui.hpp" -#include "gui/loot_ui.hpp" -#include "gui/event_router.hpp" - - - -#line 95 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" - - - -#line 15 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.cpp" -static const int DNDLoot_start = 1; -static const int DNDLoot_first_final = 6; -static const int DNDLoot_error = 0; - -static const int DNDLoot_en_main = 1; -static const int DNDLoot_en_main_looting = 2; - - -#line 98 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" - -namespace gui { - - class DNDLoot2 { - public: - std::optional $grab_source = std::nullopt; - StatusUI& $status_ui; - LootUI& $loot_ui; - sf::RenderWindow& $window; - routing::Router& $router; - - DNDLoot2(StatusUI& status_ui, - LootUI& loot_ui, sf::RenderWindow& window, - routing::Router& router); - - bool event(DNDEvent ev, std::any data={}); - void mouse_action(bool hover); - sf::Vector2f mouse_position(); - }; - - sf::Vector2f DNDLoot2::mouse_position() { - return $window.mapPixelToCoords($router.position); - } - - void DNDLoot2::mouse_action(bool hover) { - sf::Vector2f pos = mouse_position(); - $status_ui.mouse(pos.x, pos.y, hover); - if($loot_ui.active) $loot_ui.mouse(pos.x, pos.y, hover); - } - - DNDLoot2::DNDLoot2(StatusUI& status_ui, LootUI& loot_ui, sf::RenderWindow &window, routing::Router& router) : - $status_ui(status_ui), - $loot_ui(loot_ui), - $window(window), - $router(router) - { - event(DNDEvent::STARTED); - } - - bool DNDLoot2::event(DNDEvent event, std::any data) { - - int cs = 0; - int *p = (int *)&event; - int *pe = p+1; - - -#line 67 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.cpp" - { - cs = DNDLoot_start; - } - -#line 144 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" - -#line 70 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.cpp" - { - if ( p == pe ) - goto _test_eof; - if ( cs == 0 ) - goto _out; -_resume: - switch ( cs ) { -case 1: - if ( (*p) == 0 ) - goto tr0; - goto tr1; -case 0: - goto _out; -case 2: - switch( (*p) ) { - case 14: goto tr2; - case 16: goto tr3; - case 17: goto tr4; - case 19: goto tr5; - } - if ( (*p) > 21 ) { - if ( 22 <= (*p) && (*p) <= 23 ) - goto tr5; - } else if ( (*p) >= 20 ) - goto tr6; - goto tr1; -case 3: - switch( (*p) ) { - case 14: goto tr7; - case 16: goto tr8; - case 17: goto tr9; - case 19: goto tr10; - } - if ( (*p) > 21 ) { - if ( 22 <= (*p) && (*p) <= 23 ) - goto tr10; - } else if ( (*p) >= 20 ) - goto tr11; - goto tr1; -case 4: - switch( (*p) ) { - case 14: goto tr0; - case 15: goto tr3; - } - goto tr1; -case 5: - switch( (*p) ) { - case 14: goto tr12; - case 16: goto tr13; - case 17: goto tr14; - case 19: goto tr15; - } - if ( (*p) > 21 ) { - if ( 22 <= (*p) && (*p) <= 23 ) - goto tr15; - } else if ( (*p) >= 20 ) - goto tr16; - goto tr1; - } - - tr1: cs = 0; goto _again; - tr0: cs = 2; goto _again; - tr2: cs = 2; goto f0; - tr8: cs = 2; goto f1; - tr14: cs = 2; goto f2; - tr5: cs = 2; goto f3; - tr6: cs = 2; goto f4; - tr9: cs = 2; goto f5; - tr13: cs = 2; goto f6; - tr3: cs = 3; goto f1; - tr10: cs = 3; goto f3; - tr11: cs = 3; goto f4; - tr12: cs = 4; goto f0; - tr7: cs = 4; goto f1; - tr4: cs = 5; goto f2; - tr15: cs = 5; goto f3; - tr16: cs = 5; goto f4; - -f0: -#line 18 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" - { - $loot_ui.active = false; - } - goto _again; -f1: -#line 22 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" - { - // NOTE: when grab_source could work to do the if that was here - $grab_source = UISystem::loot_grab($loot_ui.$gui, data); - } - goto _again; -f2: -#line 27 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" - { - $grab_source = UISystem::loot_grab($status_ui.$gui, data); - } - goto _again; -f6: -#line 31 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" - { - if(UISystem::loot_drop($status_ui.$gui, - $loot_ui.$gui, $grab_source, data)) - { - cs = 2; - } - } - goto _again; -f5: -#line 39 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" - { - if(UISystem::loot_drop($loot_ui.$gui, - $status_ui.$gui, $grab_source, data)) - { - cs = 2; - } - } - goto _again; -f3: -#line 51 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" - { - mouse_action(false); - } - goto _again; -f4: -#line 55 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" - { - if($grab_source) { - auto& source = $loot_ui.$gui.get(*$grab_source); - source.move($window.mapPixelToCoords($router.position)); - } - mouse_action(true); - } - goto _again; - -_again: - if ( cs == 0 ) - goto _out; - if ( ++p != pe ) - goto _resume; - _test_eof: {} - _out: {} - } - -#line 145 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" - - return false; - } -} diff --git a/gui/event_router.hpp b/gui/event_router.hpp index 8de0e15..b720973 100644 --- a/gui/event_router.hpp +++ b/gui/event_router.hpp @@ -1,5 +1,6 @@ #pragma once #include "events.hpp" +#include "fsm_events.hpp" #include "simplefsm.hpp" #include diff --git a/gui/fsm.cpp b/gui/fsm.cpp index cf6cf51..e4be389 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -7,6 +7,7 @@ #include #include "systems.hpp" #include "gui/uisystems.hpp" +#include "gui/fsm_events.hpp" #include "events.hpp" #include "sound.hpp" #include "shaders.hpp" @@ -455,6 +456,7 @@ namespace gui { case eGUI::LOOT_ITEM: { dbc::check(world.has(entity), "INVALID LOOT_ITEM, that entity has no InventoryItem"); + dbc::log("@@@@ SENDING LOOT_ITEM"); auto gui_id = $loot_ui.$gui.entity("item_0"); $loot_ui.contents.insert_or_assign(gui_id, entity); $loot_ui.update(); diff --git a/gui/fsm_events.hpp b/gui/fsm_events.hpp new file mode 100644 index 0000000..bdb6bad --- /dev/null +++ b/gui/fsm_events.hpp @@ -0,0 +1,31 @@ +#pragma once + +namespace gui { + enum class Event { + STARTED=0, + TICK=1, + MOVE_FORWARD = 2, + MOVE_BACK = 3, + MOVE_LEFT = 4, + MOVE_RIGHT = 5, + MAP_OPEN = 6, + CLOSE = 7, + ROTATE_LEFT = 8, + ROTATE_RIGHT = 9, + ATTACK = 10, + START_COMBAT = 11, + STOP_COMBAT = 12, + STAIRS_DOWN = 13, + LOOT_OPEN=14, + LOOT_ITEM=15, + LOOT_SELECT=16, + INV_SELECT=17, + QUIT = 18, + MOUSE_CLICK=19, + MOUSE_MOVE=20, + MOUSE_DRAG=21, + MOUSE_DRAG_START=22, + MOUSE_DROP=23, + KEY_PRESS=24 + }; +} diff --git a/meson.build b/meson.build index 41f8737..647c36d 100644 --- a/meson.build +++ b/meson.build @@ -96,7 +96,6 @@ sources = [ 'gui/combat_ui.cpp', 'gui/debug_ui.cpp', 'gui/dnd_loot.cpp', - 'gui/dnd_loot_2.cpp', 'gui/event_router.cpp', 'gui/fsm.cpp', 'gui/guecstra.cpp', diff --git a/scratchpad/dnd_loot_2.cpp b/scratchpad/dnd_loot_2.cpp new file mode 100644 index 0000000..10d5578 --- /dev/null +++ b/scratchpad/dnd_loot_2.cpp @@ -0,0 +1,436 @@ + +#line 1 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" +#include "gui/dnd_loot_2.hpp" +#include "gui/guecstra.hpp" +#include "gui/uisystems.hpp" +#include +#include +#include "dbc.hpp" + +#define _log(M, F) {$cur_state = F; fmt::println("| {}:{} action={}, fcurs={}", __FILE_NAME__, __LINE__, #M, F);} + + + +#line 131 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + + + +#line 14 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.cpp" +static const char _DNDLoot_eof_actions[] = { + 0, 0, 0, 0, 0, 10, 0, 10 +}; + +static const int DNDLoot_start = 1; +static const int DNDLoot_first_final = 8; +static const int DNDLoot_error = 0; + +static const int DNDLoot_en_main = 1; +static const int DNDLoot_en_main_looting = 2; + + +#line 134 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + +namespace gui { + sf::Vector2f DNDLoot2::mouse_position() { + return $window.mapPixelToCoords($router.position); + } + + void DNDLoot2::mouse_action(bool hover) { + sf::Vector2f pos = mouse_position(); + $status_ui.mouse(pos.x, pos.y, hover); + if($loot_ui.active) $loot_ui.mouse(pos.x, pos.y, hover); + } + + DNDLoot2::DNDLoot2(StatusUI& status_ui, LootUI& loot_ui, sf::RenderWindow &window, routing::Router& router) : + $status_ui(status_ui), + $loot_ui(loot_ui), + $window(window), + $router(router) + { + +#line 43 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.cpp" + { + cs = DNDLoot_start; + } + +#line 153 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + + dbc::log("===================================="); + event(Event::STARTED); + dbc::log("---------------- END CONSTRICT ------"); + } + + bool DNDLoot2::event(Event event, std::any data) { + if(event == Event::TICK) return true; + + int *p = (int *)&event; + int *pe = p+1; + int *eof = pe; + + dbc::log(fmt::format(">>>> DND EVENT {}, state={}, cs={}, end={}", + int(event), $cur_state, cs, $at_end)); + + +#line 62 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.cpp" + { + int _ps = 0; + if ( cs == 0 ) + goto _out; +_resume: + switch ( cs ) { +case 1: + if ( (*p) == 0 ) + goto tr0; + goto tr1; +case 0: + goto _out; +case 2: + switch( (*p) ) { + case 14: goto tr2; + case 17: goto tr4; + case 19: goto tr5; + } + if ( (*p) < 20 ) { + if ( 15 <= (*p) && (*p) <= 16 ) + goto tr3; + } else if ( (*p) > 21 ) { + if ( 22 <= (*p) && (*p) <= 23 ) + goto tr5; + } else + goto tr6; + goto tr1; +case 3: + switch( (*p) ) { + case 14: goto tr7; + case 16: goto tr8; + case 17: goto tr9; + case 19: goto tr10; + } + if ( (*p) > 21 ) { + if ( 22 <= (*p) && (*p) <= 23 ) + goto tr10; + } else if ( (*p) >= 20 ) + goto tr11; + goto tr1; +case 4: + switch( (*p) ) { + case 14: goto tr12; + case 15: goto tr13; + } + goto tr1; +case 5: + switch( (*p) ) { + case 14: goto tr15; + case 17: goto tr17; + case 19: goto tr18; + } + if ( (*p) < 20 ) { + if ( 15 <= (*p) && (*p) <= 16 ) + goto tr16; + } else if ( (*p) > 21 ) { + if ( 22 <= (*p) && (*p) <= 23 ) + goto tr18; + } else + goto tr19; + goto tr14; +case 6: + switch( (*p) ) { + case 14: goto tr20; + case 16: goto tr21; + case 17: goto tr22; + case 19: goto tr23; + } + if ( (*p) > 21 ) { + if ( 22 <= (*p) && (*p) <= 23 ) + goto tr23; + } else if ( (*p) >= 20 ) + goto tr24; + goto tr1; +case 7: + switch( (*p) ) { + case 14: goto tr25; + case 16: goto tr26; + case 17: goto tr27; + case 19: goto tr28; + } + if ( (*p) > 21 ) { + if ( 22 <= (*p) && (*p) <= 23 ) + goto tr28; + } else if ( (*p) >= 20 ) + goto tr29; + goto tr14; + } + + tr1: cs = 0; goto _again; + tr14: _ps = cs;cs = 0; goto f9; + tr0: _ps = cs;cs = 2; goto f0; + tr2: _ps = cs;cs = 2; goto f1; + tr8: _ps = cs;cs = 2; goto f2; + tr22: _ps = cs;cs = 2; goto f3; + tr5: _ps = cs;cs = 2; goto f4; + tr6: _ps = cs;cs = 2; goto f5; + tr9: _ps = cs;cs = 2; goto f6; + tr15: _ps = cs;cs = 2; goto f10; + tr26: _ps = cs;cs = 2; goto f11; + tr18: _ps = cs;cs = 2; goto f13; + tr19: _ps = cs;cs = 2; goto f14; + tr21: _ps = cs;cs = 2; goto f15; + tr27: _ps = cs;cs = 2; goto f16; + tr3: _ps = cs;cs = 3; goto f2; + tr10: _ps = cs;cs = 3; goto f4; + tr11: _ps = cs;cs = 3; goto f5; + tr16: _ps = cs;cs = 3; goto f11; + tr28: _ps = cs;cs = 3; goto f13; + tr29: _ps = cs;cs = 3; goto f14; + tr20: _ps = cs;cs = 4; goto f1; + tr7: _ps = cs;cs = 4; goto f2; + tr25: _ps = cs;cs = 4; goto f11; + tr12: _ps = cs;cs = 5; goto f7; + tr4: _ps = cs;cs = 6; goto f3; + tr23: _ps = cs;cs = 6; goto f4; + tr24: _ps = cs;cs = 6; goto f5; + tr17: _ps = cs;cs = 6; goto f12; + tr13: _ps = cs;cs = 7; goto f8; + +f9: +#line 17 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + $cur_state = (_ps); + fmt::println("!!! ERROR fcurs={}", (_ps)); + } + goto _again; +f0: +#line 22 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(started, (_ps)); + {p++; goto _out; } + } + goto _again; +f1: +#line 27 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(loot_close, (_ps)); + $loot_ui.active = false; + {p++; goto _out; } + } + goto _again; +f2: +#line 33 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(loot_grab, (_ps)); + // NOTE: when grab_source could work to do the if that was here + $grab_source = UISystem::loot_grab($loot_ui.$gui, data); + {p++; goto _out; } + } + goto _again; +f3: +#line 40 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(inv_grab, (_ps)); + $grab_source = UISystem::loot_grab($status_ui.$gui, data); + {p++; goto _out; } + } + goto _again; +f15: +#line 46 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(loot_drop, (_ps)); + if(UISystem::loot_drop($status_ui.$gui, + $loot_ui.$gui, $grab_source, data)) + { + cs = 2; + } + + {p++; goto _out; } + } + goto _again; +f6: +#line 57 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(inv_drop, (_ps)); + if(UISystem::loot_drop($loot_ui.$gui, + $status_ui.$gui, $grab_source, data)) + { + cs = 2; + } + + {p++; goto _out; } + } + goto _again; +f7: +#line 68 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(at_end, (_ps)); + fmt::println("> AT END"); + $grab_source = std::nullopt; + $at_end = true; + {p++; goto _out; } + } + goto _again; +f4: +#line 83 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(mouse_click, (_ps)); + mouse_action(false); + {p++; goto _out; } + } + goto _again; +f5: +#line 89 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(mouse_move, (_ps)); + if($grab_source) { + auto& source = $loot_ui.$gui.get(*$grab_source); + source.move($window.mapPixelToCoords($router.position)); + } + mouse_action(true); + {p++; goto _out; } + } + goto _again; +f10: +#line 27 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(loot_close, (_ps)); + $loot_ui.active = false; + {p++; goto _out; } + } +#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(not_end, (_ps)); + fmt::println("% NOT_END"); + $at_end = false; + {p++; goto _out; } + } + goto _again; +f11: +#line 33 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(loot_grab, (_ps)); + // NOTE: when grab_source could work to do the if that was here + $grab_source = UISystem::loot_grab($loot_ui.$gui, data); + {p++; goto _out; } + } +#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(not_end, (_ps)); + fmt::println("% NOT_END"); + $at_end = false; + {p++; goto _out; } + } + goto _again; +f12: +#line 40 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(inv_grab, (_ps)); + $grab_source = UISystem::loot_grab($status_ui.$gui, data); + {p++; goto _out; } + } +#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(not_end, (_ps)); + fmt::println("% NOT_END"); + $at_end = false; + {p++; goto _out; } + } + goto _again; +f16: +#line 57 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(inv_drop, (_ps)); + if(UISystem::loot_drop($loot_ui.$gui, + $status_ui.$gui, $grab_source, data)) + { + cs = 2; + } + + {p++; goto _out; } + } +#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(not_end, (_ps)); + fmt::println("% NOT_END"); + $at_end = false; + {p++; goto _out; } + } + goto _again; +f8: +#line 68 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(at_end, (_ps)); + fmt::println("> AT END"); + $grab_source = std::nullopt; + $at_end = true; + {p++; goto _out; } + } +#line 33 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(loot_grab, (_ps)); + // NOTE: when grab_source could work to do the if that was here + $grab_source = UISystem::loot_grab($loot_ui.$gui, data); + {p++; goto _out; } + } + goto _again; +f13: +#line 83 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(mouse_click, (_ps)); + mouse_action(false); + {p++; goto _out; } + } +#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(not_end, (_ps)); + fmt::println("% NOT_END"); + $at_end = false; + {p++; goto _out; } + } + goto _again; +f14: +#line 89 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(mouse_move, (_ps)); + if($grab_source) { + auto& source = $loot_ui.$gui.get(*$grab_source); + source.move($window.mapPixelToCoords($router.position)); + } + mouse_action(true); + {p++; goto _out; } + } +#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + _log(not_end, (_ps)); + fmt::println("% NOT_END"); + $at_end = false; + {p++; goto _out; } + } + goto _again; + +_again: + if ( cs == 0 ) + goto _out; + p += 1; + goto _resume; + if ( p == eof ) + { + switch ( _DNDLoot_eof_actions[cs] ) { + case 10: +#line 17 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + { + $cur_state = (_ps); + fmt::println("!!! ERROR fcurs={}", (_ps)); + } + break; +#line 385 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.cpp" + } + } + + _out: {} + } + +#line 170 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl" + + dbc::log(fmt::format("<<<< DND EVENT {}, state={}, cs={}, end={}", + int(event), $cur_state, cs, $at_end)); + return $at_end; + } +} diff --git a/gui/dnd_loot_2.rl b/scratchpad/dnd_loot_2.rl similarity index 61% rename from gui/dnd_loot_2.rl rename to scratchpad/dnd_loot_2.rl index 21394fa..8d82ff9 100644 --- a/gui/dnd_loot_2.rl +++ b/scratchpad/dnd_loot_2.rl @@ -1,74 +1,110 @@ -#include -#include "gui/dnd_events.hpp" -#include +#include "gui/dnd_loot_2.hpp" #include "gui/guecstra.hpp" #include "gui/uisystems.hpp" #include -#include "gui/status_ui.hpp" -#include "gui/loot_ui.hpp" -#include "gui/event_router.hpp" +#include +#include "dbc.hpp" + +#define _log(M, F) {$cur_state = F; fmt::println("| {}:{} action={}, fcurs={}", __FILE_NAME__, __LINE__, #M, F);} %%{ machine DNDLoot; alphtype int; - import "../gui/dnd_events.hpp"; + import "gui/fsm_events.hpp"; + + action error { + $cur_state = fcurs; + fmt::println("!!! ERROR fcurs={}", fcurs); + } + + action started { + _log(started, fcurs); + fbreak; + } action loot_close { + _log(loot_close, fcurs); $loot_ui.active = false; + fbreak; } action loot_grab { + _log(loot_grab, fcurs); // NOTE: when grab_source could work to do the if that was here $grab_source = UISystem::loot_grab($loot_ui.$gui, data); + fbreak; } action inv_grab { + _log(inv_grab, fcurs); $grab_source = UISystem::loot_grab($status_ui.$gui, data); + fbreak; } action loot_drop { + _log(loot_drop, fcurs); if(UISystem::loot_drop($status_ui.$gui, $loot_ui.$gui, $grab_source, data)) { fnext looting; } + + fbreak; } action inv_drop { + _log(inv_drop, fcurs); if(UISystem::loot_drop($loot_ui.$gui, $status_ui.$gui, $grab_source, data)) { fnext looting; } + + fbreak; } - action end { + action at_end { + _log(at_end, fcurs); + fmt::println("> AT END"); $grab_source = std::nullopt; + $at_end = true; + fbreak; + } + + action not_end { + _log(not_end, fcurs); + fmt::println("% NOT_END"); + $at_end = false; + fbreak; } action mouse_click { + _log(mouse_click, fcurs); mouse_action(false); + fbreak; } action mouse_move { + _log(mouse_move, fcurs); if($grab_source) { auto& source = $loot_ui.$gui.get(*$grab_source); source.move($window.mapPixelToCoords($router.position)); } mouse_action(true); + fbreak; } mouse_click = (MOUSE_DRAG_START | MOUSE_CLICK | MOUSE_DROP); mouse_move = (MOUSE_MOVE | MOUSE_DRAG); -main := -start: ( - STARTED -> looting +main := start: ( + STARTED @started -> looting ), looting: ( LOOT_OPEN @loot_close -> looting | + LOOT_ITEM @loot_grab -> loot_grab | LOOT_SELECT @loot_grab -> loot_grab | INV_SELECT @inv_grab -> inv_grab | mouse_click @mouse_click -> looting | @@ -91,30 +127,12 @@ inv_grab: ( end: ( LOOT_ITEM @loot_grab -> loot_grab | LOOT_OPEN -> looting -); +) >at_end %not_end %err(error); }%% %% write data; namespace gui { - - class DNDLoot2 { - public: - std::optional $grab_source = std::nullopt; - StatusUI& $status_ui; - LootUI& $loot_ui; - sf::RenderWindow& $window; - routing::Router& $router; - - DNDLoot2(StatusUI& status_ui, - LootUI& loot_ui, sf::RenderWindow& window, - routing::Router& router); - - bool event(DNDEvent ev, std::any data={}); - void mouse_action(bool hover); - sf::Vector2f mouse_position(); - }; - sf::Vector2f DNDLoot2::mouse_position() { return $window.mapPixelToCoords($router.position); } @@ -131,18 +149,27 @@ namespace gui { $window(window), $router(router) { - event(DNDEvent::STARTED); + %%write init; + + dbc::log("===================================="); + event(Event::STARTED); + dbc::log("---------------- END CONSTRICT ------"); } - bool DNDLoot2::event(DNDEvent event, std::any data) { + bool DNDLoot2::event(Event event, std::any data) { + if(event == Event::TICK) return true; - int cs = 0; int *p = (int *)&event; int *pe = p+1; + int *eof = pe; - %%write init; - %%write exec; + dbc::log(fmt::format(">>>> DND EVENT {}, state={}, cs={}, end={}", + int(event), $cur_state, cs, $at_end)); + + %%write exec noend; - return false; + dbc::log(fmt::format("<<<< DND EVENT {}, state={}, cs={}, end={}", + int(event), $cur_state, cs, $at_end)); + return $at_end; } }