Skip to content

Commit bab312f

Browse files
committed
Revert axis input changes
1 parent 61f5826 commit bab312f

4 files changed

Lines changed: 14 additions & 60 deletions

File tree

core/input/input.cpp

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,7 @@ void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) {
16761676
}
16771677

16781678
if (map.type == TYPE_AXIS) {
1679-
_axis_event(p_device, (JoyAxis)map.index, p_pressed ? map.value : 0.0, p_pressed ? 0.0 : map.value);
1679+
_axis_event(p_device, (JoyAxis)map.index, p_pressed ? map.value : 0.0);
16801680
}
16811681
// no event?
16821682
}
@@ -1696,13 +1696,10 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, float p_value) {
16961696
return;
16971697
}
16981698

1699-
float last_axis = joy.last_axis[(size_t)p_axis];
1700-
float last_val = last_axis;
17011699
joy.last_axis[(size_t)p_axis] = p_value;
1702-
float val = p_value;
17031700

17041701
if (joy.mapping == -1) {
1705-
_axis_event(p_device, p_axis, val, last_val);
1702+
_axis_event(p_device, p_axis, p_value);
17061703
return;
17071704
}
17081705

@@ -1753,7 +1750,7 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, float p_value) {
17531750
value = 0.5f + value / 2.0f;
17541751
}
17551752
#endif
1756-
_axis_event(p_device, axis, value, last_val);
1753+
_axis_event(p_device, axis, value);
17571754
return;
17581755
}
17591756
}
@@ -1797,7 +1794,7 @@ void Input::joy_hat(int p_device, BitField<HatMask> p_val) {
17971794
_button_event(p_device, (JoyButton)map[hat_direction].index, (int)p_val & hat_mask);
17981795
}
17991796
if (map[hat_direction].type == TYPE_AXIS) {
1800-
_axis_event(p_device, (JoyAxis)map[hat_direction].index, ((int)p_val & hat_mask) ? map[hat_direction].value : 0.0, ((int)p_val & hat_mask) ? 0.0 : map[hat_direction].value);
1797+
_axis_event(p_device, (JoyAxis)map[hat_direction].index, ((int)p_val & hat_mask) ? map[hat_direction].value : 0.0);
18011798
}
18021799
}
18031800
}
@@ -1836,30 +1833,14 @@ void Input::_button_event(int p_device, JoyButton p_index, bool p_pressed) {
18361833
parse_input_event(ievent);
18371834
}
18381835

1839-
void Input::_axis_event(int p_device, JoyAxis p_axis, float p_value, float p_last_value) {
1840-
bool sign_diff = (p_last_value < 0) != (p_value < 0);
1841-
// Release event
1842-
if ((p_value == 0 && p_last_value != 0) || sign_diff) {
1843-
Ref<InputEventJoypadMotion> ievent;
1844-
ievent.instantiate();
1845-
ievent->set_device(p_device);
1846-
ievent->set_axis(p_axis);
1847-
ievent->set_axis_value(p_last_value < 0 ? -CMP_EPSILON : CMP_EPSILON);
1848-
ievent->set_axis_last_value(p_last_value);
1849-
1850-
parse_input_event(ievent);
1851-
}
1852-
// Active event
1853-
if (p_value != 0) {
1854-
Ref<InputEventJoypadMotion> ievent;
1855-
ievent.instantiate();
1856-
ievent->set_device(p_device);
1857-
ievent->set_axis(p_axis);
1858-
ievent->set_axis_value(p_value);
1859-
ievent->set_axis_last_value(!sign_diff ? p_last_value : 0);
1836+
void Input::_axis_event(int p_device, JoyAxis p_axis, float p_value) {
1837+
Ref<InputEventJoypadMotion> ievent;
1838+
ievent.instantiate();
1839+
ievent->set_device(p_device);
1840+
ievent->set_axis(p_axis);
1841+
ievent->set_axis_value(p_value);
18601842

1861-
parse_input_event(ievent);
1862-
}
1843+
parse_input_event(ievent);
18631844
}
18641845

18651846
void Input::_update_action_cache(const StringName &p_action_name, ActionState &r_action_state) {

core/input/input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class Input : public Object {
298298
JoyButton _get_output_button(const String &output);
299299
JoyAxis _get_output_axis(const String &output);
300300
void _button_event(int p_device, JoyButton p_index, bool p_pressed);
301-
void _axis_event(int p_device, JoyAxis p_axis, float p_value, float p_last_value);
301+
void _axis_event(int p_device, JoyAxis p_axis, float p_value);
302302
void _update_action_cache(const StringName &p_action_name, ActionState &r_action_state);
303303
void _update_joypad_features(int p_device);
304304

core/input/input_event.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,46 +1130,24 @@ float InputEventJoypadMotion::get_axis_value() const {
11301130
return axis_value;
11311131
}
11321132

1133-
void InputEventJoypadMotion::set_axis_last_value(float p_value) {
1134-
1135-
axis_last_value = p_value;
1136-
}
1137-
1138-
float InputEventJoypadMotion::get_axis_last_value() const {
1139-
1140-
return axis_last_value;
1141-
}
1142-
1143-
/*bool InputEventJoypadMotion::is_pressed() const {
1144-
return Math::abs(axis_value) >= 0.5f;
1145-
}*/
1146-
1147-
bool InputEventJoypadMotion::is_echo() const {
1148-
return Math::abs(axis_last_value) >= 0.5f;
1149-
}
1150-
11511133
bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const {
11521134
Ref<InputEventJoypadMotion> jm = p_event;
11531135
if (jm.is_null()) {
11541136
return false;
11551137
}
11561138

1139+
// Matches even if not in the same direction, but returns a "not pressed" event.
11571140
bool match = axis == jm->axis;
11581141
if (p_exact_match) {
11591142
match &= (axis_value < 0) == (jm->axis_value < 0);
11601143
}
11611144
if (match) {
11621145
float jm_abs_axis_value = Math::abs(jm->get_axis_value());
1163-
bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || (axis_value != 0 && jm->axis_value == 0));
1164-
if(!same_direction)
1165-
return false;
1146+
bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
11661147
bool pressed_state = same_direction && jm_abs_axis_value >= p_deadzone;
11671148
if (r_pressed != nullptr) {
11681149
*r_pressed = pressed_state;
11691150
}
1170-
if(!pressed && Math::abs(jm->get_axis_last_value()) < p_deadzone) {
1171-
return false;
1172-
}
11731151
if (r_strength != nullptr) {
11741152
if (pressed_state) {
11751153
if (p_deadzone == 1.0f) {

core/input/input_event.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ class InputEventJoypadMotion : public InputEvent {
313313
GDCLASS(InputEventJoypadMotion, InputEvent);
314314
JoyAxis axis = (JoyAxis)0; ///< Joypad axis
315315
float axis_value = 0; ///< -1 to 1
316-
float axis_last_value = 0; ///< -1 to 1
317316

318317
protected:
319318
static void _bind_methods();
@@ -324,10 +323,6 @@ class InputEventJoypadMotion : public InputEvent {
324323

325324
void set_axis_value(float p_value);
326325
float get_axis_value() const;
327-
void set_axis_last_value(float p_value);
328-
float get_axis_last_value() const;
329-
330-
virtual bool is_echo() const override;
331326

332327
virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const override;
333328
virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;

0 commit comments

Comments
 (0)