Should be finished for now, final checks to do

This commit is contained in:
mushgunAX 2022-12-30 15:56:36 +08:00
parent 43950400ae
commit 472f52af89
2 changed files with 272 additions and 170 deletions

View File

@ -105,12 +105,12 @@ namespace SHADE
//Write to lastKeys
memcpy(keysLast, keys, sizeof(keys));
//Poll
//Poll KB/M
unsigned char keyboardState[MAX_KEYS] = {};
SecureZeroMemory(keyboardState, sizeof(keyboardState));
//if (GetKeyboardState(keyboardState) == false) return;
bool keyboardStateGot = GetKeyboardState(keyboardState);
SHASSERT(keyboardStateGot, "SHInputManager:GetKeyboardState() failed ({})", GetLastError());
SHASSERT(keyboardStateGot, "SHInputManager::GetKeyboardState() failed ({})", GetLastError());
keyCount = 0;
keyToggleCount = 0;
for (size_t i = 0; i < MAX_KEYS; ++i)
@ -449,27 +449,41 @@ namespace SHADE
}
//Bindings//////////////////////////////////////////////////////////////////
for (std::pair<std::string, SHLogicalBindingData> binding : bindings)
for (auto& binding : bindings)
{
SHLogicalBindingData& data = binding.second;
if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_X)
//Set last value
data.positiveInputHeldLast = data.positiveInputHeld;
data.negativeInputHeldLast = data.negativeInputHeld;
//Reset held values
data.positiveInputHeld = false;
data.negativeInputHeld = false;
if (data.bindingType == SHInputManager::SH_BINDINGTYPE::MOUSE_X)
{
double velX = 0.0;
GetMouseVelocity(&velX, nullptr);
if (data.value > 0.0) data.positiveInputHeld = true;
else if (data.value < 0.0) data.negativeInputHeld = true;
data.value = velX * data.sensitivity * (data.inverted ? -1.0 : 1.0);
}
else if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_Y)
else if (data.bindingType == SHInputManager::SH_BINDINGTYPE::MOUSE_Y)
{
double velY = 0.0;
GetMouseVelocity(nullptr, &velY);
if (data.value > 0.0) data.positiveInputHeld = true;
else if (data.value < 0.0) data.negativeInputHeld = true;
data.value = velY * data.sensitivity * (data.inverted ? -1.0 : 1.0);
}
else if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_SCROLL)
else if (data.bindingType == SHInputManager::SH_BINDINGTYPE::MOUSE_SCROLL)
{
if (mouseWheelVerticalDelta > 0.0) data.positiveInputHeld = true;
else if (mouseWheelVerticalDelta < 0.0) data.negativeInputHeld = true;
data.value = mouseWheelVerticalDelta * data.sensitivity * (data.inverted ? -1.0 : 1.0);
}
else if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::KB_MB_CONTROLLER)
else if (data.bindingType == SHInputManager::SH_BINDINGTYPE::KB_MB_CONTROLLER)
{
//Prioritise the largest magnitude
double largestMagnitude = 0.0;
@ -477,27 +491,23 @@ namespace SHADE
//If digital input was in, use sensitivity
bool digitalInput = false;
//If data was read
bool positiveInputRead = false;
bool negativeInputRead = false;
//Over keycodes
for (SH_KEYCODE k : data.positiveKeyCodes)
{
if (GetKey(k))
{
if (std::abs(1.0) > std::abs(largestMagnitude)) largestMagnitude = 1.0;
if (std::abs(1.0) > std::abs(largestMagnitude)) largestMagnitude = 1.0 * (data.inverted ? -1.0 : 1.0);
digitalInput = true;
positiveInputRead = true;
data.positiveInputHeld = true;
}
}
for (SH_KEYCODE k : data.negativeKeyCodes)
{
if (GetKey(k))
{
if (std::abs(-1.0) > std::abs(largestMagnitude)) largestMagnitude = -1.0;
if (std::abs(-1.0) > std::abs(largestMagnitude)) largestMagnitude = -1.0 * (data.inverted ? -1.0 : 1.0);
digitalInput = true;
negativeInputRead = true;
data.negativeInputHeld = true;
}
}
@ -505,9 +515,10 @@ namespace SHADE
for (SH_CONTROLLERCODE c : data.positiveControllerCodes)
{
double newValue = 0.0;
if (GetControllerInput(c, &newValue))
GetControllerInput(c, &newValue);
if (std::abs(newValue) > std::abs(data.dead))
{
positiveInputRead = true;
data.positiveInputHeld = true;
if (static_cast<size_t>(c) < NUM_CONTROLLER_BUTTON)
{
digitalInput = true;
@ -520,9 +531,10 @@ namespace SHADE
for (SH_CONTROLLERCODE c : data.negativeControllerCodes)
{
double newValue = 0.0;
if (GetControllerInput(c, &newValue))
GetControllerInput(c, &newValue);
if (std::abs(newValue) > std::abs(data.dead))
{
negativeInputRead = true;
data.negativeInputHeld = true;
if (static_cast<size_t>(c) < NUM_CONTROLLER_BUTTON)
{
digitalInput = true;
@ -533,14 +545,14 @@ namespace SHADE
}
//If both positive and negative inputs read, do not modify value
if (positiveInputRead && negativeInputRead)
if (data.positiveInputHeld && data.negativeInputHeld)
{
data.value = data.value;
}
else
{
//If no data received, use gravity
if (!positiveInputRead && !negativeInputRead)
if (!data.positiveInputHeld && !data.negativeInputHeld)
{
if (data.value > 0.0)
{
@ -555,28 +567,79 @@ namespace SHADE
}
else //Either positive OR negative input was read
{
//If digital input was in, use sensitivity
//If digital input was in,
//sensitivity is used as a rate at which the axis value is changed
if (digitalInput)
{
//If the input is opposite the current value, gravity works
//with the sensitivity
if (data.value > 0.0 && largestMagnitude < 0.0)
data.value -= data.gravity * dt;
if (data.value < 0.0 && largestMagnitude > 0.0)
data.value += data.gravity * dt;
//Moved by sensitivity
data.value += data.sensitivity * largestMagnitude * dt;
if (data.value > 1.0) data.value = 1.0;
else if (data.value < -1.0) data.value = -1.0;
}
//If analog input was in,
//sensitivity is instead used as a multiplier
else
{
data.value = largestMagnitude;
data.value = largestMagnitude * data.sensitivity;
if (data.value > 1.0) data.value = 1.0;
else if (data.value < -1.0) data.value = -1.0;
}
if (data.snap) //Snapping
{
if (data.value > 0.0 && negativeInputRead)
if (data.value > 0.0 && data.negativeInputHeld)
data.value = 0.0;
if (data.value < 0.0 && positiveInputRead)
if (data.value < 0.0 && data.positiveInputHeld)
data.value = 0.0;
}
}
}
}
//Binding timings
//Positivie bindings
if (data.positiveInputHeld) //Input is down
{
if (!data.positiveInputHeldLast) //Input was just pressed
{
data.positiveHeldTime = 0.0; //Reset timer
}
data.positiveHeldTime += dt; //Tick up
}
else //Input is up
{
if (data.positiveInputHeldLast) //Input was just released
{
data.positiveReleasedTime = 0.0; //Reset timer
}
data.positiveReleasedTime += dt; //Tick up
}
if (data.negativeInputHeld) //Input is down
{
if (!data.negativeInputHeldLast) //Input was just pressed
{
data.negativeHeldTime = 0.0; //Reset timer
}
data.negativeHeldTime += dt; //Tick up
}
else //Input is up
{
if (data.negativeInputHeldLast) //Input was just released
{
data.negativeReleasedTime = 0.0; //Reset timer
}
data.negativeReleasedTime += dt; //Tick up
}
}
}
@ -710,8 +773,29 @@ namespace SHADE
return bindings[bindingName].value;
}
double SHInputManager::GetBindingAxisRaw(std::string const& bindingName, size_t cNum) noexcept
{
//Neutral if both positive and negative held
if (bindings[bindingName].positiveInputHeld && bindings[bindingName].negativeInputHeld)
{
return 0.0;
}
else if (bindings[bindingName].positiveInputHeld)
{
return 1.0;
}
else if (bindings[bindingName].negativeInputHeld)
{
return -1.0;
}
//No input means neutral
return 0.0;
}
bool SHInputManager::GetBindingPositiveButton(std::string const& bindingName, size_t cNum) noexcept
{
/*
if (cNum >= XUSER_MAX_COUNT) return false;
//Over keycodes
@ -726,11 +810,13 @@ namespace SHADE
if (GetControllerInput(c, nullptr, nullptr, nullptr, cNum)) return true;
}
return false;
return false;*/
return bindings[bindingName].positiveInputHeld;
}
bool SHInputManager::GetBindingNegativeButton(std::string const& bindingName, size_t cNum) noexcept
{
/*
if (cNum >= XUSER_MAX_COUNT) return false;
//Over keycodes
@ -745,11 +831,13 @@ namespace SHADE
if (GetControllerInput(c, nullptr, nullptr, nullptr, cNum)) return true;
}
return false;
return false;*/
return bindings[bindingName].negativeInputHeld;
}
bool SHInputManager::GetBindingPositiveButtonDown(std::string const& bindingName, size_t cNum) noexcept
{
/*
if (cNum >= XUSER_MAX_COUNT) return false;
//Over keycodes
@ -764,11 +852,13 @@ namespace SHADE
if (GetControllerInputDown(c, nullptr, cNum)) return true;
}
return false;
return false;*/
return (bindings[bindingName].positiveInputHeld && !bindings[bindingName].positiveInputHeldLast);
}
bool SHInputManager::GetBindingNegativeButtonDown(std::string const& bindingName, size_t cNum) noexcept
{
/*
if (cNum >= XUSER_MAX_COUNT) return false;
//Over keycodes
@ -783,11 +873,13 @@ namespace SHADE
if (GetControllerInputDown(c, nullptr, cNum)) return true;
}
return false;
return false;*/
return (bindings[bindingName].negativeInputHeld && !bindings[bindingName].negativeInputHeldLast);
}
bool SHInputManager::GetBindingPositiveButtonUp(std::string const& bindingName, size_t cNum) noexcept
{
/*
if (cNum >= XUSER_MAX_COUNT) return false;
//Over keycodes
@ -802,11 +894,13 @@ namespace SHADE
if (GetControllerInputUp(c, nullptr, cNum)) return true;
}
return false;
return false;*/
return (!bindings[bindingName].positiveInputHeld && bindings[bindingName].positiveInputHeldLast);
}
bool SHInputManager::GetBindingNegativeButtonUp(std::string const& bindingName, size_t cNum) noexcept
{
/*
if (cNum >= XUSER_MAX_COUNT) return false;
//Over keycodes
@ -821,93 +915,7 @@ namespace SHADE
if (GetControllerInputUp(c, nullptr, cNum)) return true;
}
return false;
return false;*/
return (!bindings[bindingName].positiveInputHeld && bindings[bindingName].positiveInputHeldLast);
}
//Fetches longest hold time
double SHInputManager::GetBindingPositiveHeldTime(std::string const& bindingName, size_t cNum) noexcept
{
if (cNum >= XUSER_MAX_COUNT) return 0.0;
double maxHeldTime = 0.0;
//Over keycodes
for (SH_KEYCODE k : bindings[bindingName].positiveKeyCodes)
{
if (GetKeyHeldTime(k) > maxHeldTime) maxHeldTime = GetKeyHeldTime(k);
}
//Over controller buttons
for (SH_CONTROLLERCODE c : bindings[bindingName].positiveControllerCodes)
{
if (GetControllerInputHeldTime(c, cNum) > maxHeldTime) maxHeldTime = GetControllerInputHeldTime(c);
}
return maxHeldTime;
}
double SHInputManager::GetBindingNegativeHeldTime(std::string const& bindingName, size_t cNum) noexcept
{
if (cNum >= XUSER_MAX_COUNT) return 0.0;
double maxHeldTime = 0.0;
//Over keycodes
for (SH_KEYCODE k : bindings[bindingName].negativeKeyCodes)
{
if (GetKeyHeldTime(k) > maxHeldTime) maxHeldTime = GetKeyHeldTime(k);
}
//Over controller buttons
for (SH_CONTROLLERCODE c : bindings[bindingName].negativeControllerCodes)
{
if (GetControllerInputHeldTime(c, cNum) > maxHeldTime) maxHeldTime = GetControllerInputHeldTime(c);
}
return maxHeldTime;
}
//Fetches shortest release time
double SHInputManager::GetBindingPositiveReleasedTime(std::string const& bindingName, size_t cNum) noexcept
{
if (cNum >= XUSER_MAX_COUNT) return 0.0;
double minReleaseTime = _HUGE_ENUF;
//Over keycodes
for (SH_KEYCODE k : bindings[bindingName].positiveKeyCodes)
{
if (GetKeyReleasedTime(k) < minReleaseTime) minReleaseTime = GetKeyReleasedTime(k);
}
//Over controller buttons
for (SH_CONTROLLERCODE c : bindings[bindingName].positiveControllerCodes)
{
if (GetControllerInputReleasedTime(c, cNum) < minReleaseTime) minReleaseTime = GetControllerInputReleasedTime(c);
}
return minReleaseTime;
}
double SHInputManager::GetBindingNegativeReleasedTime(std::string const& bindingName, size_t cNum) noexcept
{
if (cNum >= XUSER_MAX_COUNT) return 0.0;
double minReleaseTime = _HUGE_ENUF;
//Over keycodes
for (SH_KEYCODE k : bindings[bindingName].negativeKeyCodes)
{
if (GetKeyReleasedTime(k) < minReleaseTime) minReleaseTime = GetKeyReleasedTime(k);
}
//Over controller buttons
for (SH_CONTROLLERCODE c : bindings[bindingName].negativeControllerCodes)
{
if (GetControllerInputReleasedTime(c, cNum) < minReleaseTime) minReleaseTime = GetControllerInputReleasedTime(c);
}
return minReleaseTime;
}
} //namespace SHADE

View File

@ -300,12 +300,6 @@ namespace SHADE
RIGHT_THUMBSTICK_Y
};
private:
/*------------------------------------------------------------------------*/
/* Struct for logical bindings */
/*------------------------------------------------------------------------*/
struct SH_API SHLogicalBindingData
{
//BINDING TYPES///////////////////////////////////////////////////////////
enum class SH_BINDINGTYPE
{
@ -315,6 +309,14 @@ namespace SHADE
MOUSE_SCROLL
};
private:
/*------------------------------------------------------------------------*/
/* Struct for logical bindings */
/*------------------------------------------------------------------------*/
struct SH_API SHLogicalBindingData
{
//BINDINGS////////////////////////////////////////////////////////////////
//The type of the binding
@ -337,6 +339,12 @@ namespace SHADE
//The current value of the axis binding
double value = 0.0;
bool positiveInputHeld = false;
bool negativeInputHeld = false;
bool positiveInputHeldLast = false;
bool negativeInputHeldLast = false;
//Whether the input is inverted,
//If so, positive bindings will make the value negative,
// negative bindings will make the value positive,
@ -359,6 +367,18 @@ namespace SHADE
//If enabled, axis value will reset to zero when pressing a button
//that corresponds in the opposite direction
bool snap = false;
//How long the positive binding has been held for
double positiveHeldTime = 0.0;
//How long the positive binding has been released for
double positiveReleasedTime = 0.0;
//How long the negative binding has been held for
double negativeHeldTime = 0.0;
//How long the negative binding has been released for
double negativeReleasedTime = 0.0;
};
public:
@ -666,96 +686,144 @@ namespace SHADE
/*------------------------------------------------------------------------*/
//Get a read-only map of the bindings
static inline std::map<std::string, SHLogicalBindingData> const& getBindings() noexcept
static inline std::map<std::string, SHLogicalBindingData> const& GetBindings() noexcept
{
return bindings;
}
//Add a new binding to the map
static inline void BindingsAdd(std::string const& newBindingName) noexcept
static inline void AddBinding(std::string const& newBindingName) noexcept
{
bindings.insert({ newBindingName, SHLogicalBindingData() });
}
//Remove a binding and all its associated inputs from the list
//Returns 1 if found and removed, 0 if not found
static inline size_t BindingsRemove(std::string const& bindingName) noexcept
static inline size_t RemoveBinding(std::string const& bindingName) noexcept
{
return bindings.erase(bindingName);
}
//Clears all bindings from the list
static inline void BindingsClear() noexcept
static inline void ClearBindings() noexcept
{
bindings.clear();
}
//Get the number of bindings present
static inline size_t BindingsCount() noexcept
static inline size_t CountBindings() noexcept
{
return bindings.size();
}
//BINDING VALUES////////////////////////////////////////////////////////////
static inline bool BindingsGetInverted(std::string const& bindingName)
//Get whether the binding is inverted or not
//If inverted, positive inputs subtract the value of the binding
// negative inputs add to the value of the binding
// Moving mouse up / right will be negative
// Scrolling the mouse wheel up will be negative
static inline bool GetBindingInverted(std::string const& bindingName)
{
return bindings[bindingName].inverted;
}
static inline void BindingsSetInverted(std::string const& bindingName, bool const newValue)
//Set whether the binding is inverted or not
//If inverted, positive inputs subtract the value of the binding
// negative inputs add to the value of the binding
// Moving mouse up / right will be negative
// Scrolling the mouse wheel up will be negative
static inline void SetBindingInverted(std::string const& bindingName, bool const newValue)
{
bindings[bindingName].inverted = newValue;
}
static inline double BindingsGetGravity(std::string const& bindingName)
//Gets the gravity of the binding
//The rate at which the value moves to neutral if no input in the direction is read
//Should be non-negative
static inline double GetBindingGravity(std::string const& bindingName)
{
return bindings[bindingName].gravity;
}
static inline void BindingsSetGravity(std::string const& bindingName, double const newValue)
//Sets the gravity of the binding
//The rate at which the value moves to neutral if no input in the direction is read
//Should be non-negative
static inline void SetBindingGravity(std::string const& bindingName, double const newValue)
{
bindings[bindingName].gravity = newValue;
}
static inline double BindingsGetDead(std::string const& bindingName)
//Get the dead zone of the binding on a scale of 0 to 1,
//Any positive or negative analog input with magnitude less than this will be registered as neutral
//irrelvant for digital inputs
static inline double GetBindingDead(std::string const& bindingName)
{
return bindings[bindingName].dead;
}
static inline void BindingsSetDead(std::string const& bindingName, double const newValue)
//Get the dead zone of the binding on a scale of 0 to 1,
//Any positive or negative analog input with magnitude less than this will be registered as neutral
//irrelvant for digital inputs
static inline void SetBindingDead(std::string const& bindingName, double const newValue)
{
bindings[bindingName].dead = newValue;
}
static inline double BindingsGetSensitivity(std::string const& bindingName)
//Get the sensitivity of the binding
//Serves as a multiplier for mouse movement/scrolling
//For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative
//For other analog inputs, serves as a multiplier
static inline double GetBindingSensitivity(std::string const& bindingName)
{
return bindings[bindingName].sensitivity;
}
static inline void BindingsSetSensitivity(std::string const& bindingName, double const newValue)
//Set the sensitivity of the binding
//Serves as a multiplier for mouse movement/scrolling
//For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative
//For other analog inputs, serves as a multiplier
static inline void SetBindingSensitivity(std::string const& bindingName, double const newValue)
{
bindings[bindingName].sensitivity = newValue;
}
static inline bool BindingsGetSnap(std::string const& bindingName)
//Gets the snap of the binding
//If no other input on the axis is present and a input is made in the opposite direction of the current value,
//the binding's value will jump to neutral 0 before resuming in the input direction
static inline bool GetBindingSnap(std::string const& bindingName)
{
return bindings[bindingName].snap;
}
static inline void BindingsSetSnap(std::string const& bindingName, bool const newValue)
//Sets the snap of the binding
//If no other input on the axis is present and a input is made in the opposite direction of the current value,
//the binding's value will jump to neutral 0 before resuming in the input direction
static inline void SetBindingSnap(std::string const& bindingName, bool const newValue)
{
bindings[bindingName].snap = newValue;
}
//BINDING TYPE//////////////////////////////////////////////////////////////
static inline SHLogicalBindingData::SH_BINDINGTYPE BindingsGetType(std::string const& bindingName)
//Get the type of the binding
//There are four types:
//KB_MB_CONTROLLER Binding is connected to the keyboard, mouse and controller buttons and its analog inputs
//MOUSE_X Binding is connected to horizontal movement of the mouse
//MOUSE_Y Binding is connected to the vertical movement of the mouse
//MOUSE_SCROLL Binding is connected to the scrolling of the mouse wheel
static inline SH_BINDINGTYPE GetBindingType(std::string const& bindingName)
{
return bindings[bindingName].bindingType;
}
static inline void BindingsSetType(std::string const& bindingName, SHLogicalBindingData::SH_BINDINGTYPE const newType)
//Set the type of the binding
//There are four types:
//KB_MB_CONTROLLER Binding is connected to the keyboard, mouse and controller buttons and its analog inputs
//MOUSE_X Binding is connected to horizontal movement of the mouse
//MOUSE_Y Binding is connected to the vertical movement of the mouse
//MOUSE_SCROLL Binding is connected to the scrolling of the mouse wheel
static inline void SetBindingType(std::string const& bindingName, SH_BINDINGTYPE const newType)
{
bindings[bindingName].bindingType = newType;
}
@ -763,13 +831,13 @@ namespace SHADE
//POSITIVE KEYCODES/////////////////////////////////////////////////////////
//Check positive keycodes to binding
static inline std::set<SH_KEYCODE> const& BindingsGetPositiveKeyCodes(std::string const& bindingName) noexcept
static inline std::set<SH_KEYCODE> const& GetBindingPositiveKeyCodes(std::string const& bindingName) noexcept
{
return bindings[bindingName].positiveKeyCodes;
}
//Add positive SH_KEYCODE to binding
static inline void BindingsAddPositiveKeyCode(std::string const& bindingName,
static inline void AddBindingPositiveKeyCode(std::string const& bindingName,
SH_KEYCODE toAdd) noexcept
{
bindings[bindingName].positiveKeyCodes.insert(toAdd);
@ -777,14 +845,14 @@ namespace SHADE
//Remove positive SH_KEYCODE from binding
//If toRemove found and removed, returns 1. Otherwise, 0.
static inline size_t BindingsRemovePositiveKeyCode(std::string const& bindingName,
static inline size_t RemoveBindingPositiveKeyCode(std::string const& bindingName,
SH_KEYCODE toRemove) noexcept
{
return bindings[bindingName].positiveKeyCodes.erase(toRemove);
}
//Clear all positive SH_KEYCODEs from binding
static inline void BindingsClearPositiveKeyCodes(std::string const& bindingName) noexcept
static inline void ClearBindingPositiveKeyCodes(std::string const& bindingName) noexcept
{
bindings[bindingName].positiveKeyCodes.clear();
}
@ -792,13 +860,13 @@ namespace SHADE
//NEGATIVE KEYCODES/////////////////////////////////////////////////////////
//Check negative keycodes to binding
static inline std::set<SH_KEYCODE> const& BindingsGetNegativeKeyCodes(std::string const& bindingName) noexcept
static inline std::set<SH_KEYCODE> const& GetBindingNegativeKeyCodes(std::string const& bindingName) noexcept
{
return bindings[bindingName].negativeKeyCodes;
}
//Add negative SH_KEYCODE to binding
static inline void BindingsAddNegativeKeyCode(std::string const& bindingName,
static inline void AddBindingNegativeKeyCode(std::string const& bindingName,
SH_KEYCODE toAdd) noexcept
{
bindings[bindingName].negativeKeyCodes.insert(toAdd);
@ -806,14 +874,14 @@ namespace SHADE
//Remove negative SH_KEYCODE from binding
//If toRemove found and removed, returns 1. Otherwise, 0.
static inline size_t BindingsRemoveNegativeKeyCode(std::string const& bindingName,
static inline size_t RemoveBindingNegativeKeyCode(std::string const& bindingName,
SH_KEYCODE toRemove) noexcept
{
return bindings[bindingName].negativeKeyCodes.erase(toRemove);
}
//Clear all negative SH_KEYCODEs from binding
static inline void BindingsClearNegativeKeyCodes(std::string const& bindingName) noexcept
static inline void ClearBindingNegativeKeyCodes(std::string const& bindingName) noexcept
{
bindings[bindingName].negativeKeyCodes.clear();
}
@ -821,13 +889,13 @@ namespace SHADE
//POSITIVE CONTROLLERCODES//////////////////////////////////////////////////
//Check positive controllercodes to binding
static inline std::set<SH_CONTROLLERCODE> const& BindingsGetPositiveControllerCodes(std::string const& bindingName) noexcept
static inline std::set<SH_CONTROLLERCODE> const& GetBindingPositiveControllerCodes(std::string const& bindingName) noexcept
{
return bindings[bindingName].positiveControllerCodes;
}
//Add positive SH_CONTROLLERCODE to binding
static inline void BindingsAddPositiveControllerCode(std::string const& bindingName,
static inline void AddBindingPositiveControllerCode(std::string const& bindingName,
SH_CONTROLLERCODE toAdd) noexcept
{
bindings[bindingName].positiveControllerCodes.insert(toAdd);
@ -835,14 +903,14 @@ namespace SHADE
//Remove positive SH_CONTROLLERCODE from binding
//If toRemove found and removed, returns 1. Otherwise, 0.
static inline size_t BindingsRemovePositiveControllerCode(std::string const& bindingName,
static inline size_t RemoveBindingPositiveControllerCode(std::string const& bindingName,
SH_CONTROLLERCODE toRemove) noexcept
{
return bindings[bindingName].positiveControllerCodes.erase(toRemove);
}
//Clear all positive SH_CONTROLLERCODEs from binding
static inline void BindingsClearPositiveControllerCodes(std::string const& bindingName) noexcept
static inline void ClearBindingPositiveControllerCodes(std::string const& bindingName) noexcept
{
bindings[bindingName].positiveControllerCodes.clear();
}
@ -850,13 +918,13 @@ namespace SHADE
//NEGATIVE CONTROLLERCODES//////////////////////////////////////////////////
//Check negative controllercodes to binding
static inline std::set<SH_CONTROLLERCODE> const& BindingsGetNegativeControllerCodes(std::string const& bindingName) noexcept
static inline std::set<SH_CONTROLLERCODE> const& GetBindingNegativeControllerCodes(std::string const& bindingName) noexcept
{
return bindings[bindingName].negativeControllerCodes;
}
//Add negative SH_CONTROLLERCODE to binding
static inline void BindingsAddNegativeControllerCode(std::string const& bindingName,
static inline void AddBindingNegativeControllerCode(std::string const& bindingName,
SH_CONTROLLERCODE toAdd) noexcept
{
bindings[bindingName].negativeControllerCodes.insert(toAdd);
@ -864,48 +932,74 @@ namespace SHADE
//Remove negative SH_CONTROLLERCODE from binding
//If toRemove found and removed, returns 1. Otherwise, 0.
static inline size_t BindingsRemoveNegativeControllerCode(std::string const& bindingName,
static inline size_t RemoveBindingNegativeControllerCode(std::string const& bindingName,
SH_CONTROLLERCODE toRemove) noexcept
{
return bindings[bindingName].negativeControllerCodes.erase(toRemove);
}
//Clear all negative SH_CONTROLLERCODEs from binding
static inline void BindingsClearNegativeControllerCodes(std::string const& bindingName) noexcept
static inline void ClearBindingNegativeControllerCodes(std::string const& bindingName) noexcept
{
bindings[bindingName].negativeControllerCodes.clear();
}
//Get the axis value of binding, between -1 and 1 for non-mouse
//For mouse, it won't be between -1 and 1. It will also be multiplied by sensitivity
//Get the axis value of binding, between -1 and 1 for non-mouse movement/wheel
//For mouse movement/wheel, it won't be between -1 and 1. It will also be multiplied by sensitivity
//To avoid interference between mouse movement/wheel and keyboard/mouse/controller input,
//Set mouseXBound, mouseYBound and mouseScrollBound to false
//controllerNumber is not used
static double GetBindingAxis(std::string const& bindingName, size_t controllerNumber = 0) noexcept;
//Get the axis value of binding, which will be fixed among -1, 0 and 1 for non-mouse movement/wheel
//No difference between this and GetBindingAxis for mouse movement/wheel
//But for other inputs, does not consider smoothing options such as gravity and sensitivity
//If both positive and negative input is detected, returns neutral 0
//controllerNumber is not used
static double GetBindingAxisRaw(std::string const& bindingName, size_t controllerNumber = 0) noexcept;
//Whether binding is being held or not
//Does not work for mouse movement
//Does not work for mouse movement or wheel
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
//Does not work for mouse movement or wheel
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
//Does not work for mouse movement or wheel
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 const& bindingName, size_t controllerNumber = 0) noexcept;
static double GetBindingNegativeHeldTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept;
//Gets how long the binding has been considered positive
//Does not work for mouse movement or wheel
static inline double GetBindingPositiveHeldTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept
{
return bindings[bindingName].positiveHeldTime;
}
//Gets how long the binding has been considered negative
//Does not work for mouse movement or wheel
static inline double GetBindingNegativeHeldTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept
{
return bindings[bindingName].negativeHeldTime;
}
//Does not work for mouse movement
static double GetBindingPositiveReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept;
static double GetBindingNegativeReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept;
//Gets how long the binding has been not considered positive
//Does not work for mouse movement or wheel
static inline double GetBindingPositiveReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept
{
return bindings[bindingName].positiveReleasedTime;
}
//Gets how long the binding has been not considered negative
//Does not work for mouse movement or wheel
static inline double GetBindingNegativeReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept
{
return bindings[bindingName].negativeReleasedTime;
}
/*------------------------------------------------------------------------*/
/* Other Functions */