Revert "InputManager: improve trigger axis calibration"

This commit is contained in:
Jools Wills 2019-04-06 02:33:16 +01:00 committed by GitHub
parent e45458dee6
commit 945a4c9cfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 20 deletions

View file

@ -101,14 +101,7 @@ void InputManager::addJoystickByDeviceIndex(int id)
// set up the prevAxisValues // set up the prevAxisValues
int numAxes = SDL_JoystickNumAxes(joy); int numAxes = SDL_JoystickNumAxes(joy);
mPrevAxisValues[joyId] = new int[numAxes]; mPrevAxisValues[joyId] = new int[numAxes];
mInitAxisValues[joyId] = new int[numAxes]; std::fill(mPrevAxisValues[joyId], mPrevAxisValues[joyId] + numAxes, 0); //initialize array to 0
int axis;
for (int i = 0; i< numAxes; i++) {
axis = SDL_JoystickGetAxis(joy, i);
mInitAxisValues[joyId][i] = axis;
mPrevAxisValues[joyId][i] = axis;
}
} }
void InputManager::removeJoystickByJoystickID(SDL_JoystickID joyId) void InputManager::removeJoystickByJoystickID(SDL_JoystickID joyId)
@ -205,28 +198,21 @@ InputConfig* InputManager::getInputConfigByDevice(int device)
bool InputManager::parseEvent(const SDL_Event& ev, Window* window) bool InputManager::parseEvent(const SDL_Event& ev, Window* window)
{ {
bool causedEvent = false; bool causedEvent = false;
int axis;
switch(ev.type) switch(ev.type)
{ {
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
axis = ev.jaxis.value;
// Check for ABS_Z/ABS_RZ trigger axes which rest at -32768
if ((ev.jaxis.axis == 2 || ev.jaxis.axis == 5) && mInitAxisValues[ev.jaxis.which][ev.jaxis.axis] == -32768)
{
// shift to 0 - 32767.
axis = axis / 2 + 16384;
}
//if it switched boundaries //if it switched boundaries
if((abs(axis) > DEADZONE) != (abs(mPrevAxisValues[ev.jaxis.which][ev.jaxis.axis]) > DEADZONE)) if((abs(ev.jaxis.value) > DEADZONE) != (abs(mPrevAxisValues[ev.jaxis.which][ev.jaxis.axis]) > DEADZONE))
{ {
int normValue; int normValue;
if(abs(axis) <= DEADZONE) if(abs(ev.jaxis.value) <= DEADZONE)
normValue = 0; normValue = 0;
else else
if(axis > 0) if(ev.jaxis.value > 0)
normValue = 1; normValue = 1;
else else
normValue = -1; normValue = -1;
window->input(getInputConfigByDevice(ev.jaxis.which), Input(ev.jaxis.which, TYPE_AXIS, ev.jaxis.axis, normValue, false)); window->input(getInputConfigByDevice(ev.jaxis.which), Input(ev.jaxis.which, TYPE_AXIS, ev.jaxis.axis, normValue, false));
causedEvent = true; causedEvent = true;
} }

View file

@ -27,7 +27,6 @@ private:
InputConfig* mCECInputConfig; InputConfig* mCECInputConfig;
std::map<SDL_JoystickID, int*> mPrevAxisValues; std::map<SDL_JoystickID, int*> mPrevAxisValues;
std::map<SDL_JoystickID, int*> mInitAxisValues;
bool initialized() const; bool initialized() const;