diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-02-07 16:18:13 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-02-07 16:18:13 +0300 |
commit | 9fe21fcd8883b37bdc30224822e6e42afb35b8f0 (patch) | |
tree | 798117abd4dc7e610997d59d530a96ddc1509f53 /src/input | |
parent | 4429cb14e9e187edef27aba692a4266733f79c17 (diff) | |
download | manaplus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.gz manaplus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.bz2 manaplus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.xz manaplus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.zip |
Replace most static_cast<Type> to shorter versions from defines.
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/inputactionmap.h | 2 | ||||
-rw-r--r-- | src/input/inputactionoperators.cpp | 6 | ||||
-rw-r--r-- | src/input/inputactionsortfunctor.h | 4 | ||||
-rw-r--r-- | src/input/inputmanager.cpp | 56 | ||||
-rw-r--r-- | src/input/inputmanager.h | 2 | ||||
-rw-r--r-- | src/input/keyboardconfig.cpp | 6 | ||||
-rw-r--r-- | src/input/touch/touchmanager.cpp | 6 | ||||
-rw-r--r-- | src/input/touch/touchmanager.h | 8 |
8 files changed, 45 insertions, 45 deletions
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h index 91b8d8368..1bd74708d 100644 --- a/src/input/inputactionmap.h +++ b/src/input/inputactionmap.h @@ -56,7 +56,7 @@ // keyData must be in same order as enum keyAction. static const InputActionData inputActionData - [static_cast<size_t>(InputAction::TOTAL)] = { + [CAST_SIZE(InputAction::TOTAL)] = { {"keyMoveUp", addKey(SDLK_UP), emptyKey, diff --git a/src/input/inputactionoperators.cpp b/src/input/inputactionoperators.cpp index 23d742544..39de5b782 100644 --- a/src/input/inputactionoperators.cpp +++ b/src/input/inputactionoperators.cpp @@ -24,17 +24,17 @@ InputActionT operator+(InputActionT action, const int& i) { - action = static_cast<InputActionT>(static_cast<int>(action) + i); + action = static_cast<InputActionT>(CAST_S32(action) + i); return action; } InputActionT operator+(InputActionT action, const unsigned int& i) { - action = static_cast<InputActionT>(static_cast<unsigned int>(action) + i); + action = static_cast<InputActionT>(CAST_U32(action) + i); return action; } int operator-(const InputActionT &action1, const InputActionT &action2) { - return static_cast<int>(action1) - static_cast<int>(action2); + return CAST_S32(action1) - CAST_S32(action2); } diff --git a/src/input/inputactionsortfunctor.h b/src/input/inputactionsortfunctor.h index 334185977..6a3a72245 100644 --- a/src/input/inputactionsortfunctor.h +++ b/src/input/inputactionsortfunctor.h @@ -31,8 +31,8 @@ class InputActionSortFunctor final bool operator() (const InputActionT key1, const InputActionT key2) const { - return keys[static_cast<size_t>(key1)].priority - >= keys[static_cast<size_t>(key2)].priority; + return keys[CAST_SIZE(key1)].priority + >= keys[CAST_SIZE(key2)].priority; } const InputActionData *keys A_NONNULLPOINTER; diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index 46d97b836..b6ed13524 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -85,7 +85,7 @@ InputManager::InputManager() : void InputManager::init() restrict2 { for (unsigned int i = 0; - i < static_cast<unsigned int>(InputAction::TOTAL); + i < CAST_U32(InputAction::TOTAL); i ++) { InputFunction &kf = mKey[i]; @@ -113,7 +113,7 @@ void InputManager::update() void InputManager::retrieve() restrict2 { - for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i ++) + for (int i = 0; i < CAST_S32(InputAction::TOTAL); i ++) { const std::string &restrict cmd = inputActionData[i].chatCommand; if (!cmd.empty()) @@ -177,7 +177,7 @@ void InputManager::retrieve() restrict2 void InputManager::store() const restrict2 { - for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i ++) + for (int i = 0; i < CAST_S32(InputAction::TOTAL); i ++) { #ifdef USE_SDL2 const std::string cf = std::string("sdl2") @@ -233,7 +233,7 @@ void InputManager::store() const restrict2 void InputManager::resetKey(const InputActionT i) restrict2 { - InputFunction &restrict key = mKey[static_cast<size_t>(i)]; + InputFunction &restrict key = mKey[CAST_SIZE(i)]; for (size_t i2 = 1; i2 < inputFunctionSize; i2 ++) { InputItem &restrict ki2 = key.values[i2]; @@ -241,7 +241,7 @@ void InputManager::resetKey(const InputActionT i) restrict2 ki2.value = -1; } const InputActionData &restrict kd = - inputActionData[static_cast<size_t>(i)]; + inputActionData[CAST_SIZE(i)]; InputItem &restrict val0 = key.values[0]; val0.type = kd.defaultType1; InputItem &restrict val1 = key.values[1]; @@ -263,7 +263,7 @@ void InputManager::resetKey(const InputActionT i) restrict2 void InputManager::resetKeys() restrict2 { - for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i++) + for (int i = 0; i < CAST_S32(InputAction::TOTAL); i++) resetKey(static_cast<InputActionT>(i)); } @@ -283,7 +283,7 @@ bool InputManager::hasConflicts(InputActionT &restrict key1, * No need to parse the square matrix: only check one triangle * that's enough to detect conflicts */ - for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i++) + for (int i = 0; i < CAST_S32(InputAction::TOTAL); i++) { const InputActionData &restrict kdi = inputActionData[i]; if (!*kdi.configField) @@ -297,7 +297,7 @@ bool InputManager::hasConflicts(InputActionT &restrict key1, continue; size_t j; - for (j = i, j++; j < static_cast<int>(InputAction::TOTAL); j++) + for (j = i, j++; j < CAST_S32(InputAction::TOTAL); j++) { if ((kdi.grp & inputActionData[j].grp) == 0 || !*kdi.configField) @@ -338,7 +338,7 @@ bool InputManager::isActionActive(const InputActionT index) const restrict2 return false; const InputActionData &restrict key = - inputActionData[static_cast<size_t>(index)]; + inputActionData[CAST_SIZE(index)]; // logger->log("isActionActive mask=%d, condition=%d, index=%d", // mMask, key.condition, index); if ((key.condition & mMask) != key.condition) @@ -357,16 +357,16 @@ bool InputManager::isActionActive0(const InputActionT index) InputFunction &InputManager::getKey(InputActionT index) restrict2 { - if (static_cast<int>(index) < 0 || index >= InputAction::TOTAL) + if (CAST_S32(index) < 0 || index >= InputAction::TOTAL) index = InputAction::MOVE_UP; - return mKey[static_cast<size_t>(index)]; + return mKey[CAST_SIZE(index)]; } std::string InputManager::getKeyStringLong(const InputActionT index) const restrict2 { std::string keyStr; - const InputFunction &restrict ki = mKey[static_cast<size_t>(index)]; + const InputFunction &restrict ki = mKey[CAST_SIZE(index)]; for (size_t i = 0; i < inputFunctionSize; i ++) { @@ -410,7 +410,7 @@ std::string InputManager::getKeyValueString(const InputActionT index) const restrict2 { std::string keyStr; - const InputFunction &restrict ki = mKey[static_cast<size_t>(index)]; + const InputFunction &restrict ki = mKey[CAST_SIZE(index)]; for (size_t i = 0; i < inputFunctionSize; i ++) { @@ -475,18 +475,18 @@ void InputManager::addActionKey(const InputActionT action, const InputTypeT type, const int val) restrict2 { - if (static_cast<int>(action) < 0 || action >= InputAction::TOTAL) + if (CAST_S32(action) < 0 || action >= InputAction::TOTAL) return; int idx = -1; - InputFunction &restrict key = mKey[static_cast<size_t>(action)]; + InputFunction &restrict key = mKey[CAST_SIZE(action)]; for (size_t i = 0; i < inputFunctionSize; i ++) { const InputItem &restrict val2 = key.values[i]; if (val2.type == InputType::UNKNOWN || (val2.type == type && val2.value == val)) { - idx = static_cast<int>(i); + idx = CAST_S32(i); break; } } @@ -523,7 +523,7 @@ void InputManager::setNewKey(const SDL_Event &event, void InputManager::unassignKey() restrict2 { - InputFunction &restrict key = mKey[static_cast<size_t>(mNewKeyIndex)]; + InputFunction &restrict key = mKey[CAST_SIZE(mNewKeyIndex)]; for (size_t i = 0; i < inputFunctionSize; i ++) { InputItem &restrict val = key.values[i]; @@ -796,7 +796,7 @@ bool InputManager::invokeKey(const InputActionData *restrict const key, { InputEvent evt(keyNum, mMask); ActionFuncPtr func = *(inputActionData[ - static_cast<size_t>(keyNum)].action); + CAST_SIZE(keyNum)].action); if (func && func(evt)) return true; } @@ -809,7 +809,7 @@ void InputManager::executeAction(const InputActionT keyNum) restrict2 return; InputEvent evt(keyNum, mMask); - ActionFuncPtr func = *(inputActionData[static_cast<size_t>( + ActionFuncPtr func = *(inputActionData[CAST_SIZE( keyNum)].action); if (func) func(evt); @@ -859,9 +859,9 @@ bool InputManager::executeChatCommand(const InputActionT keyNum, const std::string &restrict args, ChatTab *restrict const tab) restrict2 { - if (static_cast<int>(keyNum) < 0 || keyNum >= InputAction::TOTAL) + if (CAST_S32(keyNum) < 0 || keyNum >= InputAction::TOTAL) return false; - ActionFuncPtr func = *(inputActionData[static_cast<size_t>( + ActionFuncPtr func = *(inputActionData[CAST_SIZE( keyNum)].action); if (func) { @@ -880,7 +880,7 @@ void InputManager::updateKeyActionMap(KeyToActionMap &restrict actionMap, actionMap.clear(); keyTimeMap.clear(); - for (size_t i = 0; i < static_cast<size_t>(InputAction::TOTAL); i ++) + for (size_t i = 0; i < CAST_SIZE(InputAction::TOTAL); i ++) { const InputFunction &restrict key = mKey[i]; const InputActionData &restrict kd = inputActionData[i]; @@ -936,10 +936,10 @@ bool InputManager::triggerAction(const KeysVector *restrict const ptrs) FOR_EACHP (KeysVectorCIter, it, ptrs) { const InputActionT keyNum = *it; - if (static_cast<int>(keyNum) < 0 || keyNum >= InputAction::TOTAL) + if (CAST_S32(keyNum) < 0 || keyNum >= InputAction::TOTAL) continue; - if (invokeKey(&inputActionData[static_cast<size_t>(keyNum)], keyNum)) + if (invokeKey(&inputActionData[CAST_SIZE(keyNum)], keyNum)) return true; } return false; @@ -949,7 +949,7 @@ InputActionT InputManager::getKeyIndex(const int value, const int grp, const InputTypeT type) const restrict2 { - for (size_t i = 0; i < static_cast<size_t>(InputAction::TOTAL); i++) + for (size_t i = 0; i < CAST_SIZE(InputAction::TOTAL); i++) { const InputFunction &restrict key = mKey[i]; const InputActionData &restrict kd = inputActionData[i]; @@ -973,8 +973,8 @@ InputActionT InputManager::getActionByKey(const SDL_Event &restrict event) if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) { const InputActionT idx = keyboard.getActionId(event); - if (static_cast<int>(idx) >= 0 && - checkKey(&inputActionData[static_cast<size_t>(idx)])) + if (CAST_S32(idx) >= 0 && + checkKey(&inputActionData[CAST_SIZE(idx)])) { return idx; } @@ -985,7 +985,7 @@ InputActionT InputManager::getActionByKey(const SDL_Event &restrict event) void InputManager::addChatCommands(std::list<std::string> &restrict arr) restrict { - const int sz = static_cast<int>(InputAction::TOTAL); + const int sz = CAST_S32(InputAction::TOTAL); for (int i = 0; i < sz; i++) { const InputActionData &restrict ad = inputActionData[i]; diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h index 306de4df6..8b2d3ae84 100644 --- a/src/input/inputmanager.h +++ b/src/input/inputmanager.h @@ -170,7 +170,7 @@ class InputManager final StringInpActionMap mNameMap; StringIntMap mChatMap; - InputFunction mKey[static_cast<size_t>(InputAction::TOTAL)]; + InputFunction mKey[CAST_SIZE(InputAction::TOTAL)]; }; extern InputManager inputManager; diff --git a/src/input/keyboardconfig.cpp b/src/input/keyboardconfig.cpp index 9c82dd0d0..2c821807b 100644 --- a/src/input/keyboardconfig.cpp +++ b/src/input/keyboardconfig.cpp @@ -65,7 +65,7 @@ int KeyboardConfig::getKeyValueFromEvent(const SDL_Event &event) return event.key.keysym.scancode; #else if (event.key.keysym.sym) - return static_cast<int>(event.key.keysym.sym); + return CAST_S32(event.key.keysym.sym); else if (event.key.keysym.scancode > 1) return -event.key.keysym.scancode; return 0; @@ -98,7 +98,7 @@ std::string KeyboardConfig::getKeyName(const int key) } // TRANSLATORS: long key name, should be short - return strprintf(_("key_%d"), static_cast<int>(key)); + return strprintf(_("key_%d"), CAST_S32(key)); } std::string KeyboardConfig::getKeyShortString(const std::string &key) @@ -266,7 +266,7 @@ void KeyboardConfig::handleRepeat(const int time) { int &keyTime = (*it).second; if (time > keyTime && abs(time - keyTime) - > static_cast<signed>(mRepeatTime)) + > CAST_S32(mRepeatTime)) { keyTime = time; inputManager.triggerAction(getActionVectorByKey(key)); diff --git a/src/input/touch/touchmanager.cpp b/src/input/touch/touchmanager.cpp index e0c08b16c..5c7de8189 100644 --- a/src/input/touch/touchmanager.cpp +++ b/src/input/touch/touchmanager.cpp @@ -328,12 +328,12 @@ bool TouchManager::processEvent(const MouseInput &mouseInput) restrict2 bool TouchManager::isActionActive(const InputActionT index) restrict2 const { - if (static_cast<int>(index) < 0 || - static_cast<int>(index) >= actionsSize) + if (CAST_S32(index) < 0 || + CAST_S32(index) >= actionsSize) { return false; } - return mActions[static_cast<size_t>(index)]; + return mActions[CAST_SIZE(index)]; } void TouchManager::resize(const int width, const int height) restrict2 diff --git a/src/input/touch/touchmanager.h b/src/input/touch/touchmanager.h index 3e88c4f6a..676167e13 100644 --- a/src/input/touch/touchmanager.h +++ b/src/input/touch/touchmanager.h @@ -38,7 +38,7 @@ class MouseInput; typedef void (*TouchFuncPtr) (const MouseInput &restrict mouseInput); -const int actionsSize = static_cast<int>(InputAction::TOTAL); +const int actionsSize = CAST_S32(InputAction::TOTAL); const int buttonsCount = 12; struct TouchItem final @@ -145,10 +145,10 @@ class TouchManager final : public ConfigListener void setActionActive(const InputActionT index, const bool value) restrict2 { - if (static_cast<int>(index) >= 0 && - static_cast<int>(index) < actionsSize) + if (CAST_S32(index) >= 0 && + CAST_S32(index) < actionsSize) { - mActions[static_cast<size_t>(index)] = value; + mActions[CAST_SIZE(index)] = value; } } |