Mouse handling is way better but still want to refine it more if I can.

This commit is contained in:
Zed A. Shaw 2026-04-24 00:54:28 -04:00
parent e41651aa38
commit 190748af3c
10 changed files with 47 additions and 22 deletions

View file

@ -65,7 +65,7 @@ debug: build
gdb --nx -x .gdbinit --ex run --args builddir/runtests gdb --nx -x .gdbinit --ex run --args builddir/runtests
debug_run: build 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 debug_walk: build test
gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/under_the_dome t gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/under_the_dome t

View file

@ -65,6 +65,9 @@ json = subproject('nlohmann_json').get_variable('nlohmann_json_dep')
freetype2 = subproject('freetype2').get_variable('freetype_dep') freetype2 = subproject('freetype2').get_variable('freetype_dep')
flac = subproject('flac').get_variable('flac_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') ogg = subproject('ogg').get_variable('libogg_dep')
vorbis = subproject('vorbis').get_variable('vorbis_dep') vorbis = subproject('vorbis').get_variable('vorbis_dep')
vorbisfile = subproject('vorbis').get_variable('vorbisfile_dep') vorbisfile = subproject('vorbis').get_variable('vorbisfile_dep')
@ -82,7 +85,7 @@ subdir('src')
subdir('tests') subdir('tests')
dependencies += [ dependencies += [
fmt, json, freetype2, fmt, json, freetype2, magic_enum,
flac, ogg, vorbis, vorbisfile, vorbisenc, flac, ogg, vorbis, vorbisfile, vorbisenc,
sfml_audio, sfml_graphics, sfml_audio, sfml_graphics,
sfml_network, sfml_system, sfml_network, sfml_system,

View file

@ -1,12 +1,12 @@
#pragma once #pragma once
#include <fmt/core.h> #include <fmt/core.h>
#ifndef FSM_DEBUG #ifndef FSM_DEBUG
#define FSM_STATE(C, S, E, ...) case C::S: S(E, ##__VA_ARGS__); break #define FSM_STATE(C, S, E, ...) case C::S: S(E, ##__VA_ARGS__); break
#else #else
#include <magic_enum/magic_enum.hpp>
static int last_event=-1; 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 #endif
template<typename S, typename E> template<typename S, typename E>
@ -21,7 +21,7 @@ public:
void state(S next_state) { void state(S next_state) {
#ifdef FSM_DEBUG #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 #endif
$state = next_state; $state = next_state;
} }

View file

@ -1,4 +1,4 @@
#define FSM_DEBUG 1 #define FSM_DEBUG "dnd_loot"
#include "gui/guecstra.hpp" #include "gui/guecstra.hpp"
#include "gui/dnd_loot.hpp" #include "gui/dnd_loot.hpp"

View file

@ -1,3 +1,4 @@
#define FSM_DEBUG "router"
#include "event_router.hpp" #include "event_router.hpp"
#include "dbc.hpp" #include "dbc.hpp"
#include "events.hpp" #include "events.hpp"

View file

@ -8,11 +8,11 @@
namespace gui { namespace gui {
namespace routing { namespace routing {
enum class State { enum class State {
START, START=__LINE__,
IDLE, IDLE=__LINE__,
MOUSE_ACTIVE, MOUSE_ACTIVE=__LINE__,
MOUSE_MOVING, MOUSE_MOVING=__LINE__,
MOUSE_DRAGGING MOUSE_DRAGGING=__LINE__
}; };
enum class Event { enum class Event {

View file

@ -1,4 +1,4 @@
#define FSM_DEBUG 1 #define FSM_DEBUG "fsm"
#include "gui/fsm.hpp" #include "gui/fsm.hpp"
#include <iostream> #include <iostream>
#include <chrono> #include <chrono>
@ -321,8 +321,15 @@ namespace gui {
break; // ignored break; // ignored
} }
} else { } else {
// event(gui_ev, {mouse_mods}); switch(gui_ev) {
case game::Event::MOUSE_DRAG_START:
case game::Event::MOUSE_CLICK:
case game::Event::MOUSE_DROP:
mouse_action(); mouse_action();
break;
default:
event(gui_ev, {mouse_mods});
}
} }
} }
} }

View file

@ -1,20 +1,22 @@
#include "gui/guecstra.hpp" #include "gui/guecstra.hpp"
#include "game/level.hpp" #include "game/level.hpp"
#include <magic_enum/magic_enum.hpp>
#include "dbc.hpp"
namespace guecs { namespace guecs {
Clickable make_action(guecs::Entity gui_id, game::Event event) { Clickable make_action(guecs::Entity gui_id, game::Event event, const std::source_location location) {
return {[&, gui_id, event](auto){ return {[&, gui_id, event, location](guecs::Modifiers mods){
auto world = GameDB::current_world(); 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<game::Event>(event, gui_id, {}); world->send<game::Event>(event, gui_id, {});
}}; }};
} }
Clickable make_action(guecs::Entity gui_id, game::Event event, std::any data) { Clickable make_action(guecs::Entity gui_id, game::Event event, std::any data, const std::source_location location) {
return {[&, event, data](auto){ return {[&, event, data, location](auto){
auto world = GameDB::current_world(); 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<game::Event>(event, gui_id, data); world->send<game::Event>(event, gui_id, data);
}}; }};
} }

View file

@ -5,8 +5,10 @@
#include "graphics/textures.hpp" #include "graphics/textures.hpp"
namespace guecs { namespace guecs {
Clickable make_action(guecs::Entity gui_id, game::Event event); Clickable make_action(guecs::Entity gui_id, game::Event event,
Clickable make_action(guecs::Entity gui_id, game::Event event, std::any data); 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 { struct GrabSource {
DinkyECS::Entity world_entity; DinkyECS::Entity world_entity;

10
wraps/magic_enum.wrap Normal file
View file

@ -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