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.
This commit is contained in:
parent
7fc32b0248
commit
d99d9a68c8
10 changed files with 541 additions and 313 deletions
|
@ -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
|
||||
};
|
|
@ -1,230 +0,0 @@
|
|||
|
||||
#line 1 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
|
||||
#include <iostream>
|
||||
#include "gui/dnd_events.hpp"
|
||||
#include <any>
|
||||
#include "gui/guecstra.hpp"
|
||||
#include "gui/uisystems.hpp"
|
||||
#include <guecs/ui.hpp>
|
||||
#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<guecs::Entity> $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<guecs::GrabSource>(*$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;
|
||||
}
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
#include <iostream>
|
||||
#include "gui/dnd_events.hpp"
|
||||
#include <any>
|
||||
#include "gui/guecstra.hpp"
|
||||
#include "gui/uisystems.hpp"
|
||||
#include <guecs/ui.hpp>
|
||||
#include "gui/status_ui.hpp"
|
||||
#include "gui/loot_ui.hpp"
|
||||
#include "gui/event_router.hpp"
|
||||
|
||||
|
||||
%%{
|
||||
machine DNDLoot;
|
||||
alphtype int;
|
||||
|
||||
import "../gui/dnd_events.hpp";
|
||||
|
||||
action loot_close {
|
||||
$loot_ui.active = false;
|
||||
}
|
||||
|
||||
action loot_grab {
|
||||
// NOTE: when grab_source could work to do the if that was here
|
||||
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
|
||||
}
|
||||
|
||||
action inv_grab {
|
||||
$grab_source = UISystem::loot_grab($status_ui.$gui, data);
|
||||
}
|
||||
|
||||
action loot_drop {
|
||||
if(UISystem::loot_drop($status_ui.$gui,
|
||||
$loot_ui.$gui, $grab_source, data))
|
||||
{
|
||||
fnext looting;
|
||||
}
|
||||
}
|
||||
|
||||
action inv_drop {
|
||||
if(UISystem::loot_drop($loot_ui.$gui,
|
||||
$status_ui.$gui, $grab_source, data))
|
||||
{
|
||||
fnext looting;
|
||||
}
|
||||
}
|
||||
|
||||
action end {
|
||||
$grab_source = std::nullopt;
|
||||
}
|
||||
|
||||
action mouse_click {
|
||||
mouse_action(false);
|
||||
}
|
||||
|
||||
action mouse_move {
|
||||
if($grab_source) {
|
||||
auto& source = $loot_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
source.move($window.mapPixelToCoords($router.position));
|
||||
}
|
||||
mouse_action(true);
|
||||
}
|
||||
|
||||
mouse_click = (MOUSE_DRAG_START | MOUSE_CLICK | MOUSE_DROP);
|
||||
mouse_move = (MOUSE_MOVE | MOUSE_DRAG);
|
||||
|
||||
main :=
|
||||
start: (
|
||||
STARTED -> looting
|
||||
),
|
||||
looting: (
|
||||
LOOT_OPEN @loot_close -> looting |
|
||||
LOOT_SELECT @loot_grab -> loot_grab |
|
||||
INV_SELECT @inv_grab -> inv_grab |
|
||||
mouse_click @mouse_click -> looting |
|
||||
mouse_move @mouse_move -> looting
|
||||
),
|
||||
loot_grab: (
|
||||
LOOT_OPEN @loot_grab -> end |
|
||||
LOOT_SELECT @loot_grab -> looting |
|
||||
INV_SELECT @inv_drop -> looting |
|
||||
mouse_click @mouse_click -> loot_grab |
|
||||
mouse_move @mouse_move -> loot_grab
|
||||
),
|
||||
inv_grab: (
|
||||
LOOT_OPEN @loot_close -> end |
|
||||
LOOT_SELECT @loot_drop -> looting |
|
||||
INV_SELECT @inv_grab -> looting |
|
||||
mouse_click @mouse_click -> inv_grab |
|
||||
mouse_move @mouse_move -> inv_grab
|
||||
),
|
||||
end: (
|
||||
LOOT_ITEM @loot_grab -> loot_grab |
|
||||
LOOT_OPEN -> looting
|
||||
);
|
||||
}%%
|
||||
|
||||
%% write data;
|
||||
|
||||
namespace gui {
|
||||
|
||||
class DNDLoot2 {
|
||||
public:
|
||||
std::optional<guecs::Entity> $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;
|
||||
|
||||
%%write init;
|
||||
%%write exec;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "events.hpp"
|
||||
#include "fsm_events.hpp"
|
||||
#include "simplefsm.hpp"
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <numbers>
|
||||
#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<components::InventoryItem>(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();
|
||||
|
|
31
gui/fsm_events.hpp
Normal file
31
gui/fsm_events.hpp
Normal file
|
@ -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
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue