+ return -1;
+}
+
+
+void Gamepad::Update(void)
+{
+// SDL_PollEvent(&event);
+ SDL_JoystickUpdate();
+
+ for(int i=0; i<numJoysticks; i++)
+ {
+ for(int j=0; j<numButtons[i]; j++)
+ button[i][j] = SDL_JoystickGetButton(pad[i], j);
+
+ for(int j=0; j<numHats[i]; j++)
+ hat[i][j] = SDL_JoystickGetHat(pad[i], j);
+
+ for(int j=0; j<numAxes[i]; j++)
+ axis[i][j] = SDL_JoystickGetAxis(pad[i], j);
+ }
+}
+
+
+void Gamepad::DumpJoystickStatesToLog(void)
+{
+ bool pressed = false;
+
+ for(int i=0; i<numJoysticks; i++)
+ {
+ for(int j=0; j<numButtons[i]; j++)
+ {
+ if (button[i][j])
+ {
+ pressed = true;
+ break;
+ break;
+ }
+ }
+
+ for(int j=0; j<numHats[i]; j++)
+ {
+ if (hat[i][j])
+ {
+ pressed = true;
+ break;
+ break;
+ }
+ }
+
+ for(int j=0; j<numAxes[i]; j++)
+ {
+ // We encode these as axis # (in bits 1-15), up or down in bit 0.
+ if (axis[i][j] > 32000)
+ {
+ pressed = true;
+ break;
+ break;
+ }
+
+ if (axis[i][j] < -32000)
+ {
+ pressed = true;
+ break;
+ break;
+ }
+ }
+ }
+
+ if (!pressed)
+ return;
+
+ WriteLog("Gamepad: CheckButtonPressed...\n");
+
+ for(int i=0; i<numJoysticks; i++)
+ {
+ for(int j=0; j<numButtons[i]; j++)
+ {
+ if (button[i][j])
+ WriteLog("Gamepad: Pad #%i, button %i down...\n", i, j);
+ }
+
+ for(int j=0; j<numHats[i]; j++)
+ {
+ if (hat[i][j])
+ WriteLog("Gamepad: Pad #%i, hat %i pushed...\n", i, j);
+ }
+
+ for(int j=0; j<numAxes[i]; j++)
+ {
+ // We encode these as axis # (in bits 1-15), up or down in bit 0.
+ if (axis[i][j] > 32000)
+ WriteLog("Gamepad: Pad #%i, axis %i pushed down...\n", i, j);
+
+ if (axis[i][j] < -32000)
+ WriteLog("Gamepad: Pad #%i, axis %i pushed up...\n", i, j);
+ }
+ }
+}
+
+
+// However, SDL 2 *does* support hot-plugging! :-D
+#if 0
+// Need to test this. It may be that the only time joysticks are detected is
+// when the program is first run. That would suck.
+// Well, it turns out that SDL doesn't do hot plugging. :-(
+void Gamepad::CheckConsistency(void)
+{
+ int currentNumJoysticks = SDL_NumJoysticks();
+
+ // Check to see if the # of joysticks reported by SDL changed
+ if (currentNumJoysticks == numJoysticks)
+ return;
+
+ // Either one or more joysticks were plugged in, or removed. Fix up our
+ // internal states to reflect this.
+
+