diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-03-04 23:13:26 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-03-04 23:13:26 +0300 |
commit | 70e54365d660a52884af35487cfdf89d0d53ac9a (patch) | |
tree | 5cdbf55b2d977523364a554f2ea1c1bd46628da4 /src/input | |
parent | 8ea8b11a39ad94f521d66d2f182312655ad587b2 (diff) | |
download | ManaVerse-70e54365d660a52884af35487cfdf89d0d53ac9a.tar.gz ManaVerse-70e54365d660a52884af35487cfdf89d0d53ac9a.tar.bz2 ManaVerse-70e54365d660a52884af35487cfdf89d0d53ac9a.tar.xz ManaVerse-70e54365d660a52884af35487cfdf89d0d53ac9a.zip |
Improve performance in getting printable key for actions.
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/inputfunction.h | 5 | ||||
-rw-r--r-- | src/input/inputmanager.cpp | 28 | ||||
-rw-r--r-- | src/input/inputmanager.h | 2 |
3 files changed, 27 insertions, 8 deletions
diff --git a/src/input/inputfunction.h b/src/input/inputfunction.h index 58c4b0efc..21d1cd732 100644 --- a/src/input/inputfunction.h +++ b/src/input/inputfunction.h @@ -23,12 +23,15 @@ #include "input/inputitem.h" +#include <string> + #include "localconsts.h" -const unsigned int inputFunctionSize = 3; +const size_t inputFunctionSize = 3U; struct InputFunction final { + std::string keyStr; InputItem values[inputFunctionSize]; }; diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index 837e1d811..e5d13f027 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -90,6 +90,7 @@ void InputManager::init() restrict2 i ++) { InputFunction &kf = mKey[i]; + kf.keyStr.clear(); for (unsigned int f = 0; f < inputFunctionSize; f ++) { InputItem &ki = kf.values[f]; @@ -130,14 +131,17 @@ void InputManager::retrieve() restrict2 #else const std::string cf = inputActionData[i].configField; #endif + InputFunction &restrict kf = mKey[i]; if (!cf.empty()) { mNameMap[cf] = static_cast<InputActionT>(i); - InputFunction &restrict kf = mKey[i]; const std::string keyStr = config.getValue(cf, ""); const size_t keyStrSize = keyStr.size(); if (keyStr.empty()) + { + updateKeyString(kf); continue; + } StringVect keys; splitToStringVector(keys, keyStr, ','); @@ -173,6 +177,7 @@ void InputManager::retrieve() restrict2 } } } + updateKeyString(kf); } } @@ -264,6 +269,7 @@ void InputManager::resetKey(const InputActionT i) restrict2 val0.value = kd.defaultValue1; val1.value = kd.defaultValue2; #endif + updateKeyString(key); } void InputManager::resetKeys() restrict2 @@ -411,12 +417,9 @@ std::string InputManager::getKeyStringLong(const InputActionT index) const return keyStr; } -std::string InputManager::getKeyValueString(const InputActionT index) const - restrict2 +void InputManager::updateKeyString(InputFunction &ki) const restrict2 { std::string keyStr; - const InputFunction &restrict ki = mKey[CAST_SIZE(index)]; - for (size_t i = 0; i < inputFunctionSize; i ++) { const InputItem &restrict key = ki.values[i]; @@ -451,9 +454,18 @@ std::string InputManager::getKeyValueString(const InputActionT index) const if (keyStr.empty()) { // TRANSLATORS: unknown short key type. must be short - return _("u key"); + ki.keyStr = _("u key"); } - return keyStr; + else + { + ki.keyStr = keyStr; + } +} + +std::string InputManager::getKeyValueString(const InputActionT index) const + restrict2 +{ + return mKey[CAST_SIZE(index)].keyStr; } std::string InputManager::getKeyValueByName(const std::string &restrict @@ -508,6 +520,7 @@ void InputManager::addActionKey(const InputActionT action, } key.values[idx] = InputItem(type, val); + updateKeyString(key); } void InputManager::setNewKey(const SDL_Event &event, @@ -535,6 +548,7 @@ void InputManager::unassignKey() restrict2 val.type = InputType::UNKNOWN; val.value = -1; } + updateKeyString(key); update(); } diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h index 8b2d3ae84..177bb2ae2 100644 --- a/src/input/inputmanager.h +++ b/src/input/inputmanager.h @@ -160,6 +160,8 @@ class InputManager final static bool isActionActive0(const InputActionT index) A_WARN_UNUSED; + void updateKeyString(InputFunction &ki) const restrict2; + /** Reference to setup window */ Setup_Input *mSetupInput A_NONNULLPOINTER; /** Index of new key to be assigned */ |