Skip to content

Commit

Permalink
Merge pull request #50985 from raulsntos/fix-50788
Browse files Browse the repository at this point in the history
[3.x] Set p_raw_strength in action_match methods
  • Loading branch information
akien-mga authored Jul 30, 2021
2 parents 78d9a4a + daa0721 commit 896e7a4
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions core/os/input_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,12 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed
if (p_pressed != nullptr) {
*p_pressed = key->is_pressed();
}
float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
*p_strength = strength;
}
if (p_raw_strength != nullptr) {
*p_raw_strength = strength;
}
}
return match;
Expand Down Expand Up @@ -476,8 +480,12 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p
if (p_pressed != nullptr) {
*p_pressed = mb->is_pressed();
}
float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
*p_strength = strength;
}
if (p_raw_strength != nullptr) {
*p_raw_strength = strength;
}
}

Expand Down Expand Up @@ -722,8 +730,9 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *

bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.
if (match) {
float jm_abs_axis_value = Math::abs(jm->get_axis_value());
bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false;
bool pressed = same_direction ? jm_abs_axis_value >= p_deadzone : false;
if (p_pressed != nullptr) {
*p_pressed = pressed;
}
Expand All @@ -732,12 +741,19 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *
if (p_deadzone == 1.0f) {
*p_strength = 1.0f;
} else {
*p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f);
*p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, jm_abs_axis_value), 0.0f, 1.0f);
}
} else {
*p_strength = 0.0f;
}
}
if (p_raw_strength != nullptr) {
if (same_direction) { // NOT pressed, because we want to ignore the deadzone.
*p_raw_strength = jm_abs_axis_value;
} else {
*p_raw_strength = 0.0f;
}
}
}
return match;
}
Expand Down Expand Up @@ -796,8 +812,12 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *
if (p_pressed != nullptr) {
*p_pressed = jb->is_pressed();
}
float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
*p_strength = strength;
}
if (p_raw_strength != nullptr) {
*p_raw_strength = strength;
}
}

Expand Down Expand Up @@ -1015,8 +1035,12 @@ bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pres
if (p_pressed != nullptr) {
*p_pressed = act->pressed;
}
float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
*p_strength = strength;
}
if (p_raw_strength != nullptr) {
*p_raw_strength = strength;
}
}
return match;
Expand Down

0 comments on commit 896e7a4

Please sign in to comment.