From 7fd1401d915ee91c808695ca1f3647ca7a258a1f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 10 Sep 2017 01:11:39 +0300 Subject: Allow trigger input action on key press or/and release. By default all actions triggered on press key. --- src/input/inputmanager.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/input/inputmanager.cpp') diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index 42a4e3b25..cf8c75cd6 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -603,7 +603,7 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2 #endif // USE_SDL2 keyboard.refreshActiveKeys(); - updateConditionMask(); + updateConditionMask(true); if (handleAssignKey(event, InputType::KEYBOARD)) { BLOCK_END("InputManager::handleEvent") @@ -637,13 +637,13 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2 #endif // USE_SDL2 keyboard.refreshActiveKeys(); - updateConditionMask(); + updateConditionMask(false); keyboard.handleDeActicateKey(event); break; } case SDL_JOYBUTTONDOWN: { - updateConditionMask(); + updateConditionMask(true); // joystick.handleActicateButton(event); if (handleAssignKey(event, InputType::JOYSTICK)) { @@ -654,7 +654,7 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2 } case SDL_JOYBUTTONUP: { - updateConditionMask(); + updateConditionMask(false); // joystick.handleDeActicateButton(event); break; } @@ -693,6 +693,7 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2 switch (event.type) { case SDL_KEYDOWN: + case SDL_KEYUP: if (triggerAction(keyboard.getActionVector(event))) { BLOCK_END("InputManager::handleEvent") @@ -735,7 +736,7 @@ void InputManager::handleRepeat() joystick->handleRepeat(time); } -void InputManager::updateConditionMask() restrict2 +void InputManager::updateConditionMask(const bool pressed) restrict2 { mMask = 1; if (keyboard.isEnabled()) @@ -823,6 +824,10 @@ void InputManager::updateConditionMask() restrict2 { mMask |= InputCondition::NOTARGET; } + if (pressed == true) + mMask |= InputCondition::KEY_DOWN; + else + mMask |= InputCondition::KEY_UP; } bool InputManager::checkKey(const InputActionData *restrict const key) const -- cgit v1.2.3-60-g2f50