Merge pull request #16902 from groud/analog_action_system

Allow actions to provide an analog value
This commit is contained in:
Juan Linietsky
2018-04-18 07:21:29 -03:00
committed by GitHub
12 changed files with 274 additions and 126 deletions

View File

@@ -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());
}
}