Skip to content

Commit

Permalink
iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Jul 15, 2014
1 parent 3672409 commit 1506b3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions include/SDL_hints.h
Expand Up @@ -261,8 +261,9 @@ extern "C" {
#define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS"

/**
* \brief A variable controlling whether an Android built-in accelerometer should be
* listed as a joystick device, rather than listing actual joysticks only.
* \brief A variable controlling whether the Android / iOS built-in
* accelerometer should be listed as a joystick device, rather than listing
* actual joysticks only.
*
* This variable can be set to the following values:
* "0" - List only real joysticks and accept input from them
Expand Down
16 changes: 13 additions & 3 deletions src/joystick/iphoneos/SDL_sysjoystick.m
Expand Up @@ -23,6 +23,7 @@
/* This is the iOS implementation of the SDL joystick API */

#include "SDL_joystick.h"
#include "SDL_hints.h"
#include "SDL_stdinc.h"
#include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h"
Expand All @@ -32,9 +33,10 @@
/* needed for SDL_IPHONE_MAX_GFORCE macro */
#import "SDL_config_iphoneos.h"

const char *accelerometerName = "iOS accelerometer";
const char *accelerometerName = "iOS Accelerometer";

static CMMotionManager *motionManager = nil;
static int numjoysticks = 0;

/* Function to scan the system for joysticks.
* This function should set SDL_numjoysticks to the number of available
Expand All @@ -44,12 +46,18 @@
int
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()
{
return 1;
return numjoysticks;
}

void SDL_SYS_JoystickDetect()
Expand Down Expand Up @@ -165,6 +173,8 @@ static void SDL_SYS_AccelerometerUpdate(SDL_Joystick * joystick)
[motionManager release];
motionManager = nil;
}

numjoysticks = 0;
}

SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
Expand Down

0 comments on commit 1506b3b

Please sign in to comment.