diff --git a/Makefile b/Makefile index 69472cf..2e9b647 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ debug: build gdb --nx -x .gdbinit --ex run --args builddir/runtests debug_run: build - gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/multiscreen + gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/under_the_dome debug_walk: build test gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/under_the_dome t diff --git a/meson.build b/meson.build index b207239..2e58334 100644 --- a/meson.build +++ b/meson.build @@ -65,6 +65,9 @@ json = subproject('nlohmann_json').get_variable('nlohmann_json_dep') freetype2 = subproject('freetype2').get_variable('freetype_dep') flac = subproject('flac').get_variable('flac_dep') +magic_enum_proj = subproject('magic_enum', default_options: { + 'test': false}) +magic_enum = magic_enum_proj.get_variable('magic_enum_dep') ogg = subproject('ogg').get_variable('libogg_dep') vorbis = subproject('vorbis').get_variable('vorbis_dep') vorbisfile = subproject('vorbis').get_variable('vorbisfile_dep') @@ -82,7 +85,7 @@ subdir('src') subdir('tests') dependencies += [ - fmt, json, freetype2, + fmt, json, freetype2, magic_enum, flac, ogg, vorbis, vorbisfile, vorbisenc, sfml_audio, sfml_graphics, sfml_network, sfml_system, diff --git a/src/algos/simplefsm.hpp b/src/algos/simplefsm.hpp index 4a40cb3..157de57 100644 --- a/src/algos/simplefsm.hpp +++ b/src/algos/simplefsm.hpp @@ -1,12 +1,12 @@ #pragma once - #include #ifndef FSM_DEBUG #define FSM_STATE(C, S, E, ...) case C::S: S(E, ##__VA_ARGS__); break #else +#include static int last_event=-1; -#define FSM_STATE(C, S, E, ...) case C::S: if(last_event != int(E)) { last_event = int(E); fmt::println(">> [{}] " #C " " #S " event={}, state={}", __FILE__, int(E), int($state));}; S(E, ##__VA_ARGS__); break +#define FSM_STATE(C, S, E, ...) case C::S: if(last_event != int(E)) { last_event = int(E); fmt::println(">> [{}:EVENT] " #S " event={}", FSM_DEBUG, magic_enum::enum_name(E));}; S(E, ##__VA_ARGS__); break #endif template @@ -21,7 +21,7 @@ public: void state(S next_state) { #ifdef FSM_DEBUG - fmt::println("<< STATE: {} -> {}", int($state), int(next_state)); + fmt::println(">> [{}:TRANS]: {} -> {}", FSM_DEBUG, magic_enum::enum_name($state), magic_enum::enum_name(next_state)); #endif $state = next_state; } diff --git a/src/gui/dnd_loot.cpp b/src/gui/dnd_loot.cpp index 322d960..b91f4e7 100644 --- a/src/gui/dnd_loot.cpp +++ b/src/gui/dnd_loot.cpp @@ -1,4 +1,4 @@ -#define FSM_DEBUG 1 +#define FSM_DEBUG "dnd_loot" #include "gui/guecstra.hpp" #include "gui/dnd_loot.hpp" diff --git a/src/gui/event_router.cpp b/src/gui/event_router.cpp index 4e489d6..469731d 100644 --- a/src/gui/event_router.cpp +++ b/src/gui/event_router.cpp @@ -1,3 +1,4 @@ +#define FSM_DEBUG "router" #include "event_router.hpp" #include "dbc.hpp" #include "events.hpp" diff --git a/src/gui/event_router.hpp b/src/gui/event_router.hpp index 1744c88..5445ac4 100644 --- a/src/gui/event_router.hpp +++ b/src/gui/event_router.hpp @@ -8,11 +8,11 @@ namespace gui { namespace routing { enum class State { - START, - IDLE, - MOUSE_ACTIVE, - MOUSE_MOVING, - MOUSE_DRAGGING + START=__LINE__, + IDLE=__LINE__, + MOUSE_ACTIVE=__LINE__, + MOUSE_MOVING=__LINE__, + MOUSE_DRAGGING=__LINE__ }; enum class Event { diff --git a/src/gui/fsm.cpp b/src/gui/fsm.cpp index a882a11..b3b53d5 100644 --- a/src/gui/fsm.cpp +++ b/src/gui/fsm.cpp @@ -1,4 +1,4 @@ -#define FSM_DEBUG 1 +#define FSM_DEBUG "fsm" #include "gui/fsm.hpp" #include #include @@ -321,8 +321,15 @@ namespace gui { break; // ignored } } else { - // event(gui_ev, {mouse_mods}); - mouse_action(); + switch(gui_ev) { + case game::Event::MOUSE_DRAG_START: + case game::Event::MOUSE_CLICK: + case game::Event::MOUSE_DROP: + mouse_action(); + break; + default: + event(gui_ev, {mouse_mods}); + } } } } diff --git a/src/gui/guecstra.cpp b/src/gui/guecstra.cpp index d79e1c9..ab3953f 100644 --- a/src/gui/guecstra.cpp +++ b/src/gui/guecstra.cpp @@ -1,20 +1,22 @@ #include "gui/guecstra.hpp" #include "game/level.hpp" +#include +#include "dbc.hpp" namespace guecs { - Clickable make_action(guecs::Entity gui_id, game::Event event) { - return {[&, gui_id, event](auto){ + Clickable make_action(guecs::Entity gui_id, game::Event event, const std::source_location location) { + return {[&, gui_id, event, location](guecs::Modifiers mods){ auto world = GameDB::current_world(); - fmt::println("!!!!! SENDING EVENT: {}", int(event)); + dbc::log($F("SENDING EVENT: {}: {}", magic_enum::enum_name(event), mods.to_string()), location); world->send(event, gui_id, {}); }}; } - Clickable make_action(guecs::Entity gui_id, game::Event event, std::any data) { - return {[&, event, data](auto){ + Clickable make_action(guecs::Entity gui_id, game::Event event, std::any data, const std::source_location location) { + return {[&, event, data, location](auto){ auto world = GameDB::current_world(); - fmt::println("!!!!! SENDING EVENT with data: {}", int(event)); + dbc::log($F("SENDING EVENT: {}", magic_enum::enum_name(event)), location); world->send(event, gui_id, data); }}; } diff --git a/src/gui/guecstra.hpp b/src/gui/guecstra.hpp index 63f7d6d..935b95e 100644 --- a/src/gui/guecstra.hpp +++ b/src/gui/guecstra.hpp @@ -5,8 +5,10 @@ #include "graphics/textures.hpp" namespace guecs { - Clickable make_action(guecs::Entity gui_id, game::Event event); - Clickable make_action(guecs::Entity gui_id, game::Event event, std::any data); + Clickable make_action(guecs::Entity gui_id, game::Event event, + const std::source_location location = std::source_location::current()); + Clickable make_action(guecs::Entity gui_id, game::Event event, std::any data, + const std::source_location location = std::source_location::current()); struct GrabSource { DinkyECS::Entity world_entity; diff --git a/wraps/magic_enum.wrap b/wraps/magic_enum.wrap new file mode 100644 index 0000000..031a625 --- /dev/null +++ b/wraps/magic_enum.wrap @@ -0,0 +1,10 @@ +[wrap-file] +directory = magic_enum-0.9.7 +source_url = https://github.com/Neargye/magic_enum/archive/refs/tags/v0.9.7.tar.gz +source_filename = magic_enum-v0.9.7.tar.gz +source_hash = b403d3dad4ef542fdc3024fa37d3a6cedb4ad33c72e31b6d9bab89dcaf69edf7 +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/magic_enum_0.9.7-1/magic_enum-v0.9.7.tar.gz +wrapdb_version = 0.9.7-1 + +[provide] +magic_enum = magic_enum_dep