diff --git a/src/defs.h b/src/defs.h
index e0f9da0..cc3df57 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -33,6 +33,7 @@ along with this program. If not, see .
#define RANDRANGE(x, y) (((x) < (y)) ? ((x) + (rand() % (long)(1 + (y) - (x)))) : (x))
#define DRAND ((double)rand() / RAND_MAX)
#define _(s) gettext(s)
+#define CSDLP(x) (((x) == SDL_PRESSED) ? 1 : 0)
// A soft dependency defines these as well, so check if they are
// defined before defining (avoids compiler warnings)
diff --git a/src/engine.c b/src/engine.c
index 3988b45..f159258 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -265,6 +265,9 @@ void engine_setMode()
int autoPause = 0;
int radioLife = DEFAULT_RADIO_LIFE;
char lang[STRMAX_SHORT];
+ int i;
+ int use_gc;
+
strcpy(lang, "default");
strcpy(engine.configDirectory, "");
@@ -272,7 +275,7 @@ void engine_setMode()
engine_setupConfigDirectory();
/* Initialize the SDL library */
- if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK) < 0)
+ if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER) < 0)
{
printf("Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
@@ -329,8 +332,27 @@ void engine_setMode()
SDL_ShowCursor(SDL_DISABLE);
SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE);
- SDL_JoystickEventState(SDL_ENABLE);
- SDL_JoystickOpen(0);
+ // Determine if the GameController API can be used
+ use_gc = 1;
+ for (i=0; i= 16384;
+ if (joyleft != prevjoyleft)
+ engine.keyState[KEY_LEFT] = prevjoyleft = joyleft;
+ if (joyright != prevjoyright)
+ engine.keyState[KEY_RIGHT] = prevjoyright = joyright;
+ }
+ else if (engine.event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY)
+ {
+ joyup = engine.event.caxis.value < -16384;
+ joydown = engine.event.caxis.value >= 16384;
+ if (joyup != prevjoyup)
+ engine.keyState[KEY_UP] = prevjoyup = joyup;
+ if (joydown != prevjoydown)
+ engine.keyState[KEY_DOWN] = prevjoydown = joydown;
+ }
+ } else {
+ val = MIN(1, (double)(abs(engine.event.caxis.value)) / JS_MAX);
+ if (val < JS_DEADZONE)
+ val = 0;
+
+ if (engine.event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX)
+ engine.xaxis = copysign(val, engine.event.caxis.value);
+ else if (engine.event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY)
+ engine.yaxis = copysign(val, engine.event.caxis.value);
+ }
+
+ break;
+
case SDL_WINDOWEVENT:
if (engine.event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
{