mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-26 16:15:39 +00:00
Merge pull request #58 from joolswills/xpad_trigger
workaround for analogue trigger configuration - eg with xpad.
This commit is contained in:
commit
684ab17e95
|
@ -89,7 +89,14 @@ 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];
|
||||||
std::fill(mPrevAxisValues[joyId], mPrevAxisValues[joyId] + numAxes, 0); //initialize array to 0
|
mInitAxisValues[joyId] = new int[numAxes];
|
||||||
|
|
||||||
|
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)
|
||||||
|
@ -170,21 +177,28 @@ 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;
|
||||||
|
int deadzone = DEADZONE;
|
||||||
switch(ev.type)
|
switch(ev.type)
|
||||||
{
|
{
|
||||||
case SDL_JOYAXISMOTION:
|
case SDL_JOYAXISMOTION:
|
||||||
|
axis = ev.jaxis.value;
|
||||||
|
if (mInitAxisValues[ev.jaxis.which][ev.jaxis.axis] == -32768)
|
||||||
|
{
|
||||||
|
deadzone /= 2;
|
||||||
|
axis = (axis + 32767) / 2;
|
||||||
|
}
|
||||||
//if it switched boundaries
|
//if it switched boundaries
|
||||||
if((abs(ev.jaxis.value) > DEADZONE) != (abs(mPrevAxisValues[ev.jaxis.which][ev.jaxis.axis]) > DEADZONE))
|
if((abs(axis) > deadzone) != (abs(mPrevAxisValues[ev.jaxis.which][ev.jaxis.axis]) > deadzone))
|
||||||
{
|
{
|
||||||
int normValue;
|
int normValue;
|
||||||
if(abs(ev.jaxis.value) <= DEADZONE)
|
if(abs(axis) <= deadzone)
|
||||||
normValue = 0;
|
normValue = 0;
|
||||||
else
|
else
|
||||||
if(ev.jaxis.value > 0)
|
if(axis > 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ private:
|
||||||
InputConfig* mKeyboardInputConfig;
|
InputConfig* mKeyboardInputConfig;
|
||||||
|
|
||||||
std::map<SDL_JoystickID, int*> mPrevAxisValues;
|
std::map<SDL_JoystickID, int*> mPrevAxisValues;
|
||||||
|
std::map<SDL_JoystickID, int*> mInitAxisValues;
|
||||||
|
|
||||||
bool initialized() const;
|
bool initialized() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue