diff options
| author | groud <gilles.roudiere@gmail.com> | 2018-04-25 22:29:39 +0200 | 
|---|---|---|
| committer | groud <gilles.roudiere@gmail.com> | 2018-04-25 22:32:09 +0200 | 
| commit | 0aa8b35ee689fc8b3813ab3d35c85f9cf97775a9 (patch) | |
| tree | d01588ab07c3f4c33e2ec1d9f58517f23d40a8b8 | |
| parent | 6faa96fb89ab33fe3a6b37eecca1c7cf2934ff75 (diff) | |
Fixing input strength and the impossibility to erase action events
| -rw-r--r-- | core/input_map.cpp | 2 | ||||
| -rw-r--r-- | core/input_map.h | 2 | ||||
| -rw-r--r-- | core/os/input_event.cpp | 8 | 
3 files changed, 7 insertions, 5 deletions
diff --git a/core/input_map.cpp b/core/input_map.cpp index 973edcb5b5..67c0e4eb04 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -98,7 +98,7 @@ List<StringName> InputMap::get_actions() const {  	return actions;  } -List<Ref<InputEvent> >::Element *InputMap::_find_event(Action p_action, const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength) const { +List<Ref<InputEvent> >::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength) const {  	for (List<Ref<InputEvent> >::Element *E = p_action.inputs.front(); E; E = E->next()) { diff --git a/core/input_map.h b/core/input_map.h index a00be8c859..f497a2b86e 100644 --- a/core/input_map.h +++ b/core/input_map.h @@ -55,7 +55,7 @@ private:  	mutable Map<StringName, Action> input_map; -	List<Ref<InputEvent> >::Element *_find_event(Action p_action, const Ref<InputEvent> &p_event, bool *p_pressed = NULL, float *p_strength = NULL) const; +	List<Ref<InputEvent> >::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed = NULL, float *p_strength = NULL) const;  	Array _get_action_list(const StringName &p_action);  	Array _get_actions(); diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 5003be77ab..4ebb821a2f 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -656,12 +656,14 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *  	if (jm.is_null())  		return false; -	bool match = (axis == jm->axis && (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0)); +	bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.  	if (match) { +		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;  		if (p_pressed != NULL) -			*p_pressed = Math::abs(jm->get_axis_value()) >= p_deadzone; +			*p_pressed = pressed;  		if (p_strength != NULL) -			*p_strength = (*p_pressed) ? Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())) : 0.0f; +			*p_strength = pressed ? CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f) : 0.0f;  	}  	return match;  }  |