iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK.

This commit is contained in:
Alex Szpakowski 2014-07-15 02:01:43 -03:00
parent 3672409c51
commit 1506b3b8fb
2 changed files with 16 additions and 5 deletions

View File

@ -261,8 +261,9 @@ extern "C" {
#define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS" #define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS"
/** /**
* \brief A variable controlling whether an Android built-in accelerometer should be * \brief A variable controlling whether the Android / iOS built-in
* listed as a joystick device, rather than listing actual joysticks only. * accelerometer should be listed as a joystick device, rather than listing
* actual joysticks only.
* *
* This variable can be set to the following values: * This variable can be set to the following values:
* "0" - List only real joysticks and accept input from them * "0" - List only real joysticks and accept input from them

View File

@ -23,6 +23,7 @@
/* This is the iOS implementation of the SDL joystick API */ /* This is the iOS implementation of the SDL joystick API */
#include "SDL_joystick.h" #include "SDL_joystick.h"
#include "SDL_hints.h"
#include "SDL_stdinc.h" #include "SDL_stdinc.h"
#include "../SDL_sysjoystick.h" #include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h" #include "../SDL_joystick_c.h"
@ -32,9 +33,10 @@
/* needed for SDL_IPHONE_MAX_GFORCE macro */ /* needed for SDL_IPHONE_MAX_GFORCE macro */
#import "SDL_config_iphoneos.h" #import "SDL_config_iphoneos.h"
const char *accelerometerName = "iOS accelerometer"; const char *accelerometerName = "iOS Accelerometer";
static CMMotionManager *motionManager = nil; static CMMotionManager *motionManager = nil;
static int numjoysticks = 0;
/* Function to scan the system for joysticks. /* Function to scan the system for joysticks.
* This function should set SDL_numjoysticks to the number of available * This function should set SDL_numjoysticks to the number of available
@ -44,12 +46,18 @@ static CMMotionManager *motionManager = nil;
int int
SDL_SYS_JoystickInit(void) SDL_SYS_JoystickInit(void)
{ {
return (1); const char *hint = SDL_GetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK);
if (!hint || SDL_atoi(hint)) {
/* Default behavior, accelerometer as joystick */
numjoysticks++;
}
return numjoysticks;
} }
int SDL_SYS_NumJoysticks() int SDL_SYS_NumJoysticks()
{ {
return 1; return numjoysticks;
} }
void SDL_SYS_JoystickDetect() void SDL_SYS_JoystickDetect()
@ -165,6 +173,8 @@ SDL_SYS_JoystickQuit(void)
[motionManager release]; [motionManager release];
motionManager = nil; motionManager = nil;
} }
numjoysticks = 0;
} }
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )