iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK. iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Tue, 15 Jul 2014 02:01:43 -0300
branchiOS-improvements
changeset 94896cd0275146b3
parent 9488 f15520430c94
child 9490 9eab796ea0b8
iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK.
include/SDL_hints.h
src/joystick/iphoneos/SDL_sysjoystick.m
     1.1 --- a/include/SDL_hints.h	Mon Jul 14 22:35:48 2014 -0300
     1.2 +++ b/include/SDL_hints.h	Tue Jul 15 02:01:43 2014 -0300
     1.3 @@ -261,8 +261,9 @@
     1.4  #define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS"
     1.5      
     1.6  /**
     1.7 - *  \brief  A variable controlling whether an Android built-in accelerometer should be
     1.8 - *  listed as a joystick device, rather than listing actual joysticks only.
     1.9 + *  \brief  A variable controlling whether the Android / iOS built-in
    1.10 + *  accelerometer should be listed as a joystick device, rather than listing
    1.11 + *  actual joysticks only.
    1.12   *
    1.13   *  This variable can be set to the following values:
    1.14   *    "0"       - List only real joysticks and accept input from them
     2.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Mon Jul 14 22:35:48 2014 -0300
     2.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Tue Jul 15 02:01:43 2014 -0300
     2.3 @@ -23,6 +23,7 @@
     2.4  /* This is the iOS implementation of the SDL joystick API */
     2.5  
     2.6  #include "SDL_joystick.h"
     2.7 +#include "SDL_hints.h"
     2.8  #include "SDL_stdinc.h"
     2.9  #include "../SDL_sysjoystick.h"
    2.10  #include "../SDL_joystick_c.h"
    2.11 @@ -32,9 +33,10 @@
    2.12  /* needed for SDL_IPHONE_MAX_GFORCE macro */
    2.13  #import "SDL_config_iphoneos.h"
    2.14  
    2.15 -const char *accelerometerName = "iOS accelerometer";
    2.16 +const char *accelerometerName = "iOS Accelerometer";
    2.17  
    2.18  static CMMotionManager *motionManager = nil;
    2.19 +static int numjoysticks = 0;
    2.20  
    2.21  /* Function to scan the system for joysticks.
    2.22   * This function should set SDL_numjoysticks to the number of available
    2.23 @@ -44,12 +46,18 @@
    2.24  int
    2.25  SDL_SYS_JoystickInit(void)
    2.26  {
    2.27 -    return (1);
    2.28 +    const char *hint = SDL_GetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK);
    2.29 +    if (!hint || SDL_atoi(hint)) {
    2.30 +        /* Default behavior, accelerometer as joystick */
    2.31 +        numjoysticks++;
    2.32 +    }
    2.33 +
    2.34 +    return numjoysticks;
    2.35  }
    2.36  
    2.37  int SDL_SYS_NumJoysticks()
    2.38  {
    2.39 -    return 1;
    2.40 +    return numjoysticks;
    2.41  }
    2.42  
    2.43  void SDL_SYS_JoystickDetect()
    2.44 @@ -165,6 +173,8 @@
    2.45          [motionManager release];
    2.46          motionManager = nil;
    2.47      }
    2.48 +
    2.49 +    numjoysticks = 0;
    2.50  }
    2.51  
    2.52  SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )