Fixed and Enhanced Input Binding Management #298

Merged
mushgunAX merged 9 commits from SP3-10-input-management into main 2023-01-01 12:35:50 +08:00
2 changed files with 47 additions and 47 deletions
Showing only changes of commit 9a5dc52d77 - Show all commits

View File

@ -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;

View File

@ -319,8 +319,8 @@ namespace SHADE
std::set<SH_CONTROLLERCODE> 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<SH_KEYCODE> const& BindingsGetPositiveKeyCodes(std::string bindingName) noexcept
static inline std::set<SH_KEYCODE> 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<SH_KEYCODE> const& BindingsGetNegativeKeyCodes(std::string bindingName) noexcept
static inline std::set<SH_KEYCODE> 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<SH_CONTROLLERCODE> const& BindingsGetPositiveControllerCodes(std::string bindingName) noexcept
static inline std::set<SH_CONTROLLERCODE> 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<SH_CONTROLLERCODE> const& BindingsGetNegativeControllerCodes(std::string bindingName) noexcept
static inline std::set<SH_CONTROLLERCODE> 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 */