mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 04:06:14 +00:00
Merge pull request #6504 from Hinsbart/joy_axis
Fix input action pressed state not changing for quick joystick moveme…
This commit is contained in:
commit
1830b80719
@ -232,64 +232,6 @@ bool InputMap::event_is_action(const InputEvent& p_event, const StringName& p_ac
|
||||
return _find_event(E->get().inputs,p_event)!=NULL;
|
||||
}
|
||||
|
||||
bool InputMap::event_is_joy_motion_action_pressed(const InputEvent& p_event) const {
|
||||
|
||||
ERR_FAIL_COND_V(p_event.type!=InputEvent::JOYSTICK_MOTION,false);
|
||||
bool pressed=false;
|
||||
|
||||
//this could be optimized by having a separate list of joymotions?
|
||||
|
||||
for (Map<StringName, Action>::Element *A=input_map.front();A;A=A->next()) {
|
||||
|
||||
for (List<InputEvent>::Element *E=A->get().inputs.front();E;E=E->next()) {
|
||||
|
||||
const InputEvent& e=E->get();
|
||||
if(e.type!=p_event.type)
|
||||
continue;
|
||||
if (e.type!=InputEvent::KEY && e.device!=p_event.device)
|
||||
continue;
|
||||
|
||||
switch(p_event.type) {
|
||||
|
||||
case InputEvent::KEY: {
|
||||
|
||||
if (e.key.scancode==p_event.key.scancode && e.key.mod == p_event.key.mod)
|
||||
return e.key.pressed;
|
||||
|
||||
} break;
|
||||
case InputEvent::JOYSTICK_BUTTON: {
|
||||
|
||||
if (e.joy_button.button_index==p_event.joy_button.button_index) {
|
||||
return e.joy_button.pressed;
|
||||
}
|
||||
|
||||
} break;
|
||||
case InputEvent::MOUSE_BUTTON: {
|
||||
|
||||
if (e.mouse_button.button_index==p_event.mouse_button.button_index) {
|
||||
return e.mouse_button.pressed;
|
||||
}
|
||||
|
||||
} break;
|
||||
case InputEvent::JOYSTICK_MOTION: {
|
||||
|
||||
if (e.joy_motion.axis==p_event.joy_motion.axis) {
|
||||
if (
|
||||
(e.joy_motion.axis_value * p_event.joy_motion.axis_value >0) && //same axis
|
||||
ABS(e.joy_motion.axis_value)>0.5 && ABS(p_event.joy_motion.axis_value)>0.5 )
|
||||
pressed=true;
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return pressed;
|
||||
|
||||
}
|
||||
|
||||
const Map<StringName, InputMap::Action>& InputMap::get_action_map() const {
|
||||
return input_map;
|
||||
}
|
||||
|
@ -72,7 +72,6 @@ public:
|
||||
|
||||
const List<InputEvent> *get_action_list(const StringName& p_action);
|
||||
bool event_is_action(const InputEvent& p_event, const StringName& p_action) const;
|
||||
bool event_is_joy_motion_action_pressed(const InputEvent& p_event) const;
|
||||
|
||||
const Map<StringName, Action>& get_action_map() const;
|
||||
void load_from_globals();
|
||||
|
@ -204,7 +204,7 @@ bool InputEvent::is_pressed() const {
|
||||
case MOUSE_BUTTON: return mouse_button.pressed;
|
||||
case JOYSTICK_BUTTON: return joy_button.pressed;
|
||||
case SCREEN_TOUCH: return screen_touch.pressed;
|
||||
case JOYSTICK_MOTION: return InputMap::get_singleton()->event_is_joy_motion_action_pressed(*this);
|
||||
case JOYSTICK_MOTION: return ABS(joy_motion.axis_value) > 0.5;
|
||||
case ACTION: return action.pressed;
|
||||
default: {}
|
||||
}
|
||||
|
@ -849,6 +849,13 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co
|
||||
return p_last_id;
|
||||
}
|
||||
|
||||
if (ABS(joy.last_axis[p_axis]) > 0.5 && joy.last_axis[p_axis] * p_value.value < 0) {
|
||||
//changed direction quickly, insert fake event to release pending inputmap actions
|
||||
JoyAxis jx;
|
||||
jx.min = p_value.min;
|
||||
jx.value = p_value.value < 0 ? 0.1 : -0.1;
|
||||
p_last_id = joy_axis(p_last_id, p_device, p_axis, jx);
|
||||
}
|
||||
|
||||
joy.last_axis[p_axis] = p_value.value;
|
||||
float val = p_value.min == 0 ? -1.0f + 2.0f * p_value.value : p_value.value;
|
||||
|
Loading…
Reference in New Issue
Block a user