diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/input_default.cpp | 18 | ||||
-rw-r--r-- | main/input_default.h | 2 |
2 files changed, 16 insertions, 4 deletions
diff --git a/main/input_default.cpp b/main/input_default.cpp index 1c73ecf2d2..3c40be5082 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -127,6 +127,14 @@ bool InputDefault::is_action_just_released(const StringName &p_action) const { } } +float InputDefault::get_action_strength(const StringName &p_action) const { + const Map<StringName, Action>::Element *E = action_state.find(p_action); + if (!E) + return 0.0f; + + return E->get().strength; +} + float InputDefault::get_joy_axis(int p_device, int p_axis) const { _THREAD_SAFE_METHOD_ @@ -330,16 +338,18 @@ void InputDefault::parse_input_event(const Ref<InputEvent> &p_event) { } } - if (!p_event->is_echo()) { - for (const Map<StringName, InputMap::Action>::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) { + for (const Map<StringName, InputMap::Action>::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) { + if (InputMap::get_singleton()->event_is_action(p_event, E->key())) { - if (InputMap::get_singleton()->event_is_action(p_event, E->key()) && is_action_pressed(E->key()) != p_event->is_pressed()) { + // Save the action's state + if (!p_event->is_echo() && is_action_pressed(E->key()) != p_event->is_action_pressed(E->key())) { Action action; action.physics_frame = Engine::get_singleton()->get_physics_frames(); action.idle_frame = Engine::get_singleton()->get_idle_frames(); - action.pressed = p_event->is_pressed(); + action.pressed = p_event->is_action_pressed(E->key()); action_state[E->key()] = action; } + action_state[E->key()].strength = p_event->get_action_strength(E->key()); } } diff --git a/main/input_default.h b/main/input_default.h index 384b04cf41..6dd88cd31e 100644 --- a/main/input_default.h +++ b/main/input_default.h @@ -55,6 +55,7 @@ class InputDefault : public Input { uint64_t physics_frame; uint64_t idle_frame; bool pressed; + float strength; }; Map<StringName, Action> action_state; @@ -182,6 +183,7 @@ public: virtual bool is_action_pressed(const StringName &p_action) const; virtual bool is_action_just_pressed(const StringName &p_action) const; virtual bool is_action_just_released(const StringName &p_action) const; + virtual float get_action_strength(const StringName &p_action) const; virtual float get_joy_axis(int p_device, int p_axis) const; String get_joy_name(int p_idx); |