Added separate controller deadzone values for the triggers and thumbsticks.

This commit is contained in:
Leon Styhre 2021-07-01 17:39:08 +02:00
parent 4dc6355a34
commit 3185083ca5
2 changed files with 12 additions and 4 deletions

View file

@ -374,12 +374,19 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window)
} }
axisValue = event.caxis.value; axisValue = event.caxis.value;
int deadzone = 0;
if (event.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT ||
event.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT)
deadzone = DEADZONE_TRIGGERS;
else
deadzone = DEADZONE_THUMBSTICKS;
// Check if the input value switched boundaries. // Check if the input value switched boundaries.
if ((abs(axisValue) > DEADZONE) != (abs(mPrevAxisValues[ if ((abs(axisValue) > deadzone) != (abs(mPrevAxisValues[
std::make_pair(event.caxis.which, event.caxis.axis)]) > DEADZONE)) { std::make_pair(event.caxis.which, event.caxis.axis)]) > deadzone)) {
int normValue; int normValue;
if (abs(axisValue) <= DEADZONE) { if (abs(axisValue) <= deadzone) {
normValue = 0; normValue = 0;
} }
else { else {

View file

@ -64,7 +64,8 @@ private:
void removeControllerByJoystickID(SDL_JoystickID joyID); void removeControllerByJoystickID(SDL_JoystickID joyID);
static InputManager* sInstance; static InputManager* sInstance;
static const int DEADZONE = 23000; static const int DEADZONE_TRIGGERS = 18000;
static const int DEADZONE_THUMBSTICKS = 23000;
bool mConfigFileExists; bool mConfigFileExists;
std::map<SDL_JoystickID, SDL_Joystick*> mJoysticks; std::map<SDL_JoystickID, SDL_Joystick*> mJoysticks;