Skip to content

Commit

Permalink
Merge pull request #24 from godotengine/3.x
Browse files Browse the repository at this point in the history
3.x
  • Loading branch information
illlustr authored Oct 1, 2024
2 parents 7aff775 + 019ca01 commit e91dc0a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main/input_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ bool InputDefault::is_action_pressed(const StringName &p_action, bool p_exact) c
}

bool InputDefault::is_action_just_pressed(const StringName &p_action, bool p_exact) const {
#ifdef TOOLS_ENABLED
if (_currently_parsing_input) {
WARN_PRINT_ONCE("Prefer InputEvent.is_action_pressed() within input event callbacks to prevent detecting duplicates.");
}
#endif

ERR_FAIL_COND_V_MSG(!InputMap::get_singleton()->has_action(p_action), false, InputMap::get_singleton()->suggest_actions(p_action));
const Map<StringName, Action>::Element *E = action_state.find(p_action);
if (!E) {
Expand All @@ -132,6 +138,12 @@ bool InputDefault::is_action_just_pressed(const StringName &p_action, bool p_exa
}

bool InputDefault::is_action_just_released(const StringName &p_action, bool p_exact) const {
#ifdef TOOLS_ENABLED
if (_currently_parsing_input) {
WARN_PRINT_ONCE("Prefer InputEvent.is_action_released() within input event callbacks to prevent detecting duplicates.");
}
#endif

ERR_FAIL_COND_V_MSG(!InputMap::get_singleton()->has_action(p_action), false, InputMap::get_singleton()->suggest_actions(p_action));
const Map<StringName, Action>::Element *E = action_state.find(p_action);
if (!E) {
Expand Down Expand Up @@ -327,6 +339,10 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
// Regardless where the event came from originally, this has to happen on the main thread.
DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());

#ifdef TOOLS_ENABLED
InputGuard guard(_currently_parsing_input);
#endif

// Notes on mouse-touch emulation:
// - Emulated mouse events are parsed, that is, re-routed to this method, so they make the same effects
// as true mouse events. The only difference is the situation is flagged as emulated so they are not
Expand Down
14 changes: 14 additions & 0 deletions main/input_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ class InputDefault : public Input {

CursorShape default_shape;

#ifdef TOOLS_ENABLED
// Simple single-threaded detection of whether
// inside `_parse_input_event_impl()`.
bool _currently_parsing_input = false;
class InputGuard {
bool &_currently_parsing;

public:
InputGuard(bool &r_currently_parsing) :
_currently_parsing(r_currently_parsing) { _currently_parsing = true; }
~InputGuard() { _currently_parsing = false; }
};
#endif

public:
enum HatMask {
HAT_MASK_CENTER = 0,
Expand Down

0 comments on commit e91dc0a

Please sign in to comment.