- Instead of a huge switch statement, lets convert POV to axes by bitwise operations since we later assume we can do that for the button mapping anyways.

SVN r3609 (trunk)
This commit is contained in:
Braden Obrzut 2012-05-01 01:53:59 +00:00
parent c676f97fd8
commit 9e26f3b7a4

View file

@ -170,45 +170,21 @@ public:
AxisInfo &y = Axes[NumAxes + i*2 + 1]; AxisInfo &y = Axes[NumAxes + i*2 + 1];
buttonstate = SDL_JoystickGetHat(Device, i); buttonstate = SDL_JoystickGetHat(Device, i);
switch(buttonstate)
{ // If we're going to assume that we can pass SDL's value into
case SDL_HAT_LEFTUP: // Joy_GenerateButtonEvents then we might as well assume the format here.
x.Value = -1.0; if(buttonstate & 0x1) // Up
y.Value = -1.0; y.Value = -1.0;
break; else if(buttonstate & 0x4) // Down
case SDL_HAT_LEFT: y.Value = 1.0;
else
y.Value = 0.0;
if(buttonstate & 0x2) // Left
x.Value = 1.0;
else if(buttonstate & 0x8) // Right
x.Value = -1.0; x.Value = -1.0;
y.Value = 0.0; else
break;
case SDL_HAT_LEFTDOWN:
x.Value = -1.0;
y.Value = 1.0;
break;
case SDL_HAT_RIGHTUP:
x.Value = 1.0;
y.Value = -1.0;
break;
case SDL_HAT_RIGHT:
x.Value = 1.0;
y.Value = 0.0;
break;
case SDL_HAT_RIGHTDOWN:
x.Value = 1.0;
y.Value = 1.0;
break;
case SDL_HAT_UP:
x.Value = 0.0; x.Value = 0.0;
y.Value = -1.0;
break;
case SDL_HAT_DOWN:
x.Value = 0.0;
y.Value = 1.0;
break;
default:
x.Value = 0.0;
y.Value = 0.0;
break;
}
if(i < 4) if(i < 4)
{ {