src/joystick/iphoneos/SDL_sysjoystick.m
branchiOS-improvements
changeset 9489 6cd0275146b3
parent 8921 4a9feef61c85
child 9490 9eab796ea0b8
     1.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Mon Jul 14 22:35:48 2014 -0300
     1.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Tue Jul 15 02:01:43 2014 -0300
     1.3 @@ -23,6 +23,7 @@
     1.4  /* This is the iOS implementation of the SDL joystick API */
     1.5  
     1.6  #include "SDL_joystick.h"
     1.7 +#include "SDL_hints.h"
     1.8  #include "SDL_stdinc.h"
     1.9  #include "../SDL_sysjoystick.h"
    1.10  #include "../SDL_joystick_c.h"
    1.11 @@ -32,9 +33,10 @@
    1.12  /* needed for SDL_IPHONE_MAX_GFORCE macro */
    1.13  #import "SDL_config_iphoneos.h"
    1.14  
    1.15 -const char *accelerometerName = "iOS accelerometer";
    1.16 +const char *accelerometerName = "iOS Accelerometer";
    1.17  
    1.18  static CMMotionManager *motionManager = nil;
    1.19 +static int numjoysticks = 0;
    1.20  
    1.21  /* Function to scan the system for joysticks.
    1.22   * This function should set SDL_numjoysticks to the number of available
    1.23 @@ -44,12 +46,18 @@
    1.24  int
    1.25  SDL_SYS_JoystickInit(void)
    1.26  {
    1.27 -    return (1);
    1.28 +    const char *hint = SDL_GetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK);
    1.29 +    if (!hint || SDL_atoi(hint)) {
    1.30 +        /* Default behavior, accelerometer as joystick */
    1.31 +        numjoysticks++;
    1.32 +    }
    1.33 +
    1.34 +    return numjoysticks;
    1.35  }
    1.36  
    1.37  int SDL_SYS_NumJoysticks()
    1.38  {
    1.39 -    return 1;
    1.40 +    return numjoysticks;
    1.41  }
    1.42  
    1.43  void SDL_SYS_JoystickDetect()
    1.44 @@ -165,6 +173,8 @@
    1.45          [motionManager release];
    1.46          motionManager = nil;
    1.47      }
    1.48 +
    1.49 +    numjoysticks = 0;
    1.50  }
    1.51  
    1.52  SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )