From 9a5dc52d776f47aaf77478289a6b2d185dc58ad5 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Mon, 5 Dec 2022 23:25:43 +0800 Subject: [PATCH] Minor fixes to input manager - Pass binding names into functions by const reference instead of by value - Fixed oversight of not being able to modify or read mouse Y positive multiplier for a binding --- SHADE_Engine/src/Input/SHInputManager.cpp | 24 ++++---- SHADE_Engine/src/Input/SHInputManager.h | 70 +++++++++++------------ 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index 4849a772..f6b58a94 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -575,7 +575,7 @@ namespace SHADE } //Only get of largest magnitude - double SHInputManager::GetBindingAxis(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingAxis(std::string const& bindingName, size_t cNum) noexcept { //Over keycodes, prioritise positive for (SH_KEYCODE k : bindings[bindingName].positiveKeyCodes) @@ -606,7 +606,7 @@ namespace SHADE return largestMagnitude; } - bool SHInputManager::GetBindingPositiveButton(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingPositiveButton(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -625,7 +625,7 @@ namespace SHADE return false; } - bool SHInputManager::GetBindingNegativeButton(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingNegativeButton(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -644,7 +644,7 @@ namespace SHADE return false; } - bool SHInputManager::GetBindingPositiveButtonDown(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingPositiveButtonDown(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -663,7 +663,7 @@ namespace SHADE return false; } - bool SHInputManager::GetBindingNegativeButtonDown(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingNegativeButtonDown(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -682,7 +682,7 @@ namespace SHADE return false; } - bool SHInputManager::GetBindingPositiveButtonUp(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingPositiveButtonUp(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -701,7 +701,7 @@ namespace SHADE return false; } - bool SHInputManager::GetBindingNegativeButtonUp(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingNegativeButtonUp(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -721,7 +721,7 @@ namespace SHADE } //Fetches longest hold time - double SHInputManager::GetBindingPositiveHeldTime(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingPositiveHeldTime(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return 0.0; @@ -742,7 +742,7 @@ namespace SHADE return maxHeldTime; } - double SHInputManager::GetBindingNegativeHeldTime(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingNegativeHeldTime(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return 0.0; @@ -764,7 +764,7 @@ namespace SHADE } //Fetches shortest release time - double SHInputManager::GetBindingPositiveReleasedTime(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingPositiveReleasedTime(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return 0.0; @@ -785,7 +785,7 @@ namespace SHADE return minReleaseTime; } - double SHInputManager::GetBindingNegativeReleasedTime(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingNegativeReleasedTime(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return 0.0; @@ -808,7 +808,7 @@ namespace SHADE //Only for mouse movement //Get largest delta - double SHInputManager::GetBindingMouseVelocity(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingMouseVelocity(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return 0.0; diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 04e5871d..ce3e69aa 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -319,8 +319,8 @@ namespace SHADE std::set negativeControllerCodes; //Mouse movement mapped to axes? - double mouseXPositiveMultiplier; - double mouseYPositiveMultiplier; + double mouseXPositiveMultiplier = 0.0f; + double mouseYPositiveMultiplier = 0.0f; }; public: @@ -484,7 +484,7 @@ namespace SHADE } /*------------------------------------------------------------------------*/ - /* Input state accessors (KB & M) */ + /* Input state accessors (Controller) */ /*------------------------------------------------------------------------*/ //How many controller inputs of any kind are being used now @@ -622,14 +622,14 @@ namespace SHADE /*------------------------------------------------------------------------*/ //Add a new binding to the map - static inline void BindingsAdd(std::string newBindingName) noexcept + static inline void BindingsAdd(std::string const& newBindingName) noexcept { bindings.insert({ newBindingName, SHLogicalBindingData() }); } //Remove a binding from the map //Returns 1 if found and removed, 0 if not found - static inline size_t BindingsRemove(std::string targetBindingName) noexcept + static inline size_t BindingsRemove(std::string const& targetBindingName) noexcept { return bindings.erase(targetBindingName); } @@ -647,13 +647,13 @@ namespace SHADE } //Check positive keycodes to binding - static inline std::set const& BindingsGetPositiveKeyCodes(std::string bindingName) noexcept + static inline std::set const& BindingsGetPositiveKeyCodes(std::string const& bindingName) noexcept { return bindings[bindingName].positiveKeyCodes; } //Add positive SH_KEYCODE to binding - static inline void BindingsAddPositiveKeyCode(std::string targetBindingName, + static inline void BindingsAddPositiveKeyCode(std::string const& targetBindingName, SH_KEYCODE toAdd) noexcept { bindings[targetBindingName].positiveKeyCodes.insert(toAdd); @@ -661,20 +661,20 @@ namespace SHADE //Remove positive SH_KEYCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemovePositiveKeyCode(std::string targetBindingName, + static inline size_t BindingsRemovePositiveKeyCode(std::string const& targetBindingName, SH_KEYCODE toRemove) noexcept { return bindings[targetBindingName].positiveKeyCodes.erase(toRemove); } //Check negative keycodes to binding - static inline std::set const& BindingsGetNegativeKeyCodes(std::string bindingName) noexcept + static inline std::set const& BindingsGetNegativeKeyCodes(std::string const& bindingName) noexcept { return bindings[bindingName].negativeKeyCodes; } //Add negative SH_KEYCODE to binding - static inline void BindingsAddNegativeKeyCode(std::string targetBindingName, + static inline void BindingsAddNegativeKeyCode(std::string const& targetBindingName, SH_KEYCODE toAdd) noexcept { bindings[targetBindingName].negativeKeyCodes.insert(toAdd); @@ -682,20 +682,20 @@ namespace SHADE //Remove negative SH_KEYCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemoveNegativeKeyCode(std::string targetBindingName, + static inline size_t BindingsRemoveNegativeKeyCode(std::string const& targetBindingName, SH_KEYCODE toRemove) noexcept { return bindings[targetBindingName].negativeKeyCodes.erase(toRemove); } //Check positive controllercodes to binding - static inline std::set const& BindingsGetPositiveControllerCodes(std::string bindingName) noexcept + static inline std::set const& BindingsGetPositiveControllerCodes(std::string const& bindingName) noexcept { return bindings[bindingName].positiveControllerCodes; } //Add positive SH_CONTROLLERCODE to binding - static inline void BindingsAddPositiveControllerCode(std::string targetBindingName, + static inline void BindingsAddPositiveControllerCode(std::string const& targetBindingName, SH_CONTROLLERCODE toAdd) noexcept { bindings[targetBindingName].positiveControllerCodes.insert(toAdd); @@ -703,20 +703,20 @@ namespace SHADE //Remove positive SH_CONTROLLERCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemovePositiveControllerCode(std::string targetBindingName, + static inline size_t BindingsRemovePositiveControllerCode(std::string const& targetBindingName, SH_CONTROLLERCODE toRemove) noexcept { return bindings[targetBindingName].positiveControllerCodes.erase(toRemove); } //Check negative controllercodes to binding - static inline std::set const& BindingsGetNegativeControllerCodes(std::string bindingName) noexcept + static inline std::set const& BindingsGetNegativeControllerCodes(std::string const& bindingName) noexcept { return bindings[bindingName].negativeControllerCodes; } //Add negative SH_CONTROLLERCODE to binding - static inline void BindingsAddNegativeControllerCode(std::string targetBindingName, + static inline void BindingsAddNegativeControllerCode(std::string const& targetBindingName, SH_CONTROLLERCODE toAdd) noexcept { bindings[targetBindingName].negativeControllerCodes.insert(toAdd); @@ -724,7 +724,7 @@ namespace SHADE //Remove negative SH_CONTROLLERCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemoveNegativeControllerCode(std::string targetBindingName, + static inline size_t BindingsRemoveNegativeControllerCode(std::string const& targetBindingName, SH_CONTROLLERCODE toRemove) noexcept { return bindings[targetBindingName].negativeControllerCodes.erase(toRemove); @@ -732,57 +732,57 @@ namespace SHADE //Mouse movement bindings - static inline double const BindingsGetMouseXPositiveMultiplier(std::string bindingName) noexcept + static inline double const BindingsGetMouseXPositiveMultiplier(std::string const& bindingName) noexcept { return bindings[bindingName].mouseXPositiveMultiplier; } - static inline void BindingsSetMouseXPositiveMultiplier(std::string bindingName, double newValue) noexcept + static inline void BindingsSetMouseXPositiveMultiplier(std::string const& bindingName, double newValue) noexcept { bindings[bindingName].mouseXPositiveMultiplier = newValue; } - static inline double const BindingsGetMouseYPositiveMultiplier(std::string bindingName) noexcept + static inline double const BindingsGetMouseYPositiveMultiplier(std::string const& bindingName) noexcept { - return bindings[bindingName].mouseXPositiveMultiplier; + return bindings[bindingName].mouseYPositiveMultiplier; } - static inline void BindingsSetMouseYPositiveMultiplier(std::string bindingName, double newValue) noexcept + static inline void BindingsSetMouseYPositiveMultiplier(std::string const& bindingName, double newValue) noexcept { - bindings[bindingName].mouseXPositiveMultiplier = newValue; + bindings[bindingName].mouseYPositiveMultiplier = newValue; } //Get the axis value of binding, between -1 and 1 - static double GetBindingAxis(std::string bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingAxis(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Whether binding is being held or not //Does not work for mouse movement - static bool GetBindingPositiveButton(std::string bindingName, size_t controllerNumber = 0) noexcept; - static bool GetBindingNegativeButton(std::string bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingPositiveButton(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingNegativeButton(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Whether binding is pressed down IN THIS FRAME ONLY //Does not work for mouse movement - static bool GetBindingPositiveButtonDown(std::string bindingName, size_t controllerNumber = 0) noexcept; - static bool GetBindingNegativeButtonDown(std::string bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingPositiveButtonDown(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingNegativeButtonDown(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Whether binding is released IN THIS FRAME ONLY //Does not work for mouse movement - static bool GetBindingPositiveButtonUp(std::string bindingName, size_t controllerNumber = 0) noexcept; - static bool GetBindingNegativeButtonUp(std::string bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingPositiveButtonUp(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingNegativeButtonUp(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Binding times //Does not work for mouse movement - static double GetBindingPositiveHeldTime(std::string bindingName, size_t controllerNumber = 0) noexcept; - static double GetBindingNegativeHeldTime(std::string bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingPositiveHeldTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingNegativeHeldTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Does not work for mouse movement - static double GetBindingPositiveReleasedTime(std::string bindingName, size_t controllerNumber = 0) noexcept; - static double GetBindingNegativeReleasedTime(std::string bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingPositiveReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingNegativeReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Binding mouse velocity //Only for mouse movement - static double GetBindingMouseVelocity(std::string bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingMouseVelocity(std::string const& bindingName, size_t controllerNumber = 0) noexcept; /*------------------------------------------------------------------------*/ /* Other Functions */