Skip to content

Commit

Permalink
Merged default into iOS-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Aug 6, 2014
2 parents 6299dae + 292eedf commit 02b06c6
Show file tree
Hide file tree
Showing 25 changed files with 858 additions and 745 deletions.
3 changes: 3 additions & 0 deletions .hgignore
Expand Up @@ -8,6 +8,9 @@ Makefile
sdl-config
SDL2.spec
build
Build
*xcuserdata*
*xcworkspacedata*

# for Xcode
*.orig
Expand Down
12 changes: 12 additions & 0 deletions Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj
Expand Up @@ -1274,8 +1274,14 @@
FD6526640DE8FCCB002AD96B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
COPY_PHASE_STRIP = NO;
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES;
GCC_WARN_STRICT_SELECTOR_MATCH = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
PRODUCT_NAME = SDL2;
SKIP_INSTALL = YES;
};
Expand All @@ -1284,8 +1290,14 @@
FD6526650DE8FCCB002AD96B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
COPY_PHASE_STRIP = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES;
GCC_WARN_STRICT_SELECTOR_MATCH = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
PRODUCT_NAME = SDL2;
SKIP_INSTALL = YES;
};
Expand Down
7 changes: 4 additions & 3 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 Expand Up @@ -345,7 +346,7 @@ extern "C" {


/**
* \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac)
* \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac and iOS)
*/
#define SDL_HINT_VIDEO_HIGHDPI_DISABLED "SDL_VIDEO_HIGHDPI_DISABLED"

Expand Down
8 changes: 4 additions & 4 deletions include/SDL_syswm.h
Expand Up @@ -209,19 +209,19 @@ struct SDL_SysWMinfo
struct
{
#if defined(__OBJC__) && __has_feature(objc_arc)
NSWindow __unsafe_unretained *window; /* The Cocoa window */
NSWindow * __unsafe_unretained window; /* The Cocoa window */
#else
NSWindow *window; /* The Cocoa window */
NSWindow *window; /* The Cocoa window */
#endif
} cocoa;
#endif
#if defined(SDL_VIDEO_DRIVER_UIKIT)
struct
{
#if defined(__OBJC__) && __has_feature(objc_arc)
UIWindow __unsafe_unretained *window; /* The UIKit window */
UIWindow * __unsafe_unretained window; /* The UIKit window */
#else
UIWindow *window; /* The UIKit window */
UIWindow *window; /* The UIKit window */
#endif
} uikit;
#endif
Expand Down
30 changes: 13 additions & 17 deletions src/file/cocoa/SDL_rwopsbundlesupport.m
Expand Up @@ -41,27 +41,23 @@
return fopen(file, mode);
}

NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];


NSFileManager* file_manager = [NSFileManager defaultManager];
NSString* resource_path = [[NSBundle mainBundle] resourcePath];

NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];

NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
if([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
}
else {
fp = fopen(file, mode);
@autoreleasepool {
NSFileManager* file_manager = [NSFileManager defaultManager];
NSString* resource_path = [[NSBundle mainBundle] resourcePath];

NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];

NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
if([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
} else {
fp = fopen(file, mode);
}
}

[autorelease_pool drain];

return fp;
}

#endif /* __MACOSX__ */
#endif /* __APPLE__ */

/* vi: set ts=4 sw=4 expandtab: */
88 changes: 45 additions & 43 deletions src/filesystem/cocoa/SDL_sysfilesystem.m
Expand Up @@ -36,67 +36,69 @@
char *
SDL_GetBasePath(void)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSBundle *bundle = [NSBundle mainBundle];
const char* baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String];
const char *base = NULL;
char *retval = NULL;
if (baseType == NULL) {
baseType = "resource";
}
if (SDL_strcasecmp(baseType, "bundle")==0) {
base = [[bundle bundlePath] fileSystemRepresentation];
} else if (SDL_strcasecmp(baseType, "parent")==0) {
base = [[[bundle bundlePath] stringByDeletingLastPathComponent] fileSystemRepresentation];
} else {
/* this returns the exedir for non-bundled and the resourceDir for bundled apps */
base = [[bundle resourcePath] fileSystemRepresentation];
}
if (base) {
const size_t len = SDL_strlen(base) + 2;
retval = (char *) SDL_malloc(len);
if (retval == NULL) {
SDL_OutOfMemory();

@autoreleasepool {
const char *base = NULL;
NSBundle *bundle = [NSBundle mainBundle];
const char* baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String];
if (baseType == NULL) {
baseType = "resource";
}
if (SDL_strcasecmp(baseType, "bundle")==0) {
base = [[bundle bundlePath] fileSystemRepresentation];
} else if (SDL_strcasecmp(baseType, "parent")==0) {
base = [[[bundle bundlePath] stringByDeletingLastPathComponent] fileSystemRepresentation];
} else {
SDL_snprintf(retval, len, "%s/", base);
/* this returns the exedir for non-bundled and the resourceDir for bundled apps */
base = [[bundle resourcePath] fileSystemRepresentation];
}

if (base) {
const size_t len = SDL_strlen(base) + 2;
retval = (char *) SDL_malloc(len);
if (retval == NULL) {
SDL_OutOfMemory();
} else {
SDL_snprintf(retval, len, "%s/", base);
}
}
}

[pool release];
return retval;
}

char *
SDL_GetPrefPath(const char *org, const char *app)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
char *retval = NULL;

if ([array count] > 0) { /* we only want the first item in the list. */
NSString *str = [array objectAtIndex:0];
const char *base = [str fileSystemRepresentation];
if (base) {
const size_t len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
retval = (char *) SDL_malloc(len);
if (retval == NULL) {
SDL_OutOfMemory();
} else {
char *ptr;
SDL_snprintf(retval, len, "%s/%s/%s/", base, org, app);
for (ptr = retval+1; *ptr; ptr++) {
if (*ptr == '/') {
*ptr = '\0';
mkdir(retval, 0700);
*ptr = '/';
@autoreleasepool {
NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);

if ([array count] > 0) { /* we only want the first item in the list. */
NSString *str = [array objectAtIndex:0];
const char *base = [str fileSystemRepresentation];
if (base) {
const size_t len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
retval = (char *) SDL_malloc(len);
if (retval == NULL) {
SDL_OutOfMemory();
} else {
char *ptr;
SDL_snprintf(retval, len, "%s/%s/%s/", base, org, app);
for (ptr = retval+1; *ptr; ptr++) {
if (*ptr == '/') {
*ptr = '\0';
mkdir(retval, 0700);
*ptr = '/';
}
}
mkdir(retval, 0700);
}
mkdir(retval, 0700);
}
}
}

[pool release];
return retval;
}

Expand Down
47 changes: 31 additions & 16 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 = 1;
}

return numjoysticks;
}

int SDL_SYS_NumJoysticks()
{
return 1;
return numjoysticks;
}

void SDL_SYS_JoystickDetect()
Expand Down Expand Up @@ -82,13 +90,15 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
joystick->nballs = 0;
joystick->nbuttons = 0;

if (motionManager == nil) {
motionManager = [[CMMotionManager alloc] init];
}
@autoreleasepool {
if (motionManager == nil) {
motionManager = [[CMMotionManager alloc] init];
}

/* Shorter times between updates can significantly increase CPU usage. */
motionManager.accelerometerUpdateInterval = 0.1;
[motionManager startAccelerometerUpdates];
/* Shorter times between updates can significantly increase CPU usage. */
motionManager.accelerometerUpdateInterval = 0.1;
[motionManager startAccelerometerUpdates];
}

return 0;
}
Expand All @@ -105,11 +115,13 @@ static void SDL_SYS_AccelerometerUpdate(SDL_Joystick * joystick)
const SInt16 maxsint16 = 0x7FFF;
CMAcceleration accel;

if (!motionManager.accelerometerActive) {
return;
}
@autoreleasepool {
if (!motionManager.accelerometerActive) {
return;
}

accel = [[motionManager accelerometerData] acceleration];
accel = motionManager.accelerometerData.acceleration;
}

/*
Convert accelerometer data from floating point to Sint16, which is what
Expand Down Expand Up @@ -153,18 +165,21 @@ static void SDL_SYS_AccelerometerUpdate(SDL_Joystick * joystick)
void
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
{
[motionManager stopAccelerometerUpdates];
@autoreleasepool {
[motionManager stopAccelerometerUpdates];
}
joystick->closed = 1;
}

/* Function to perform any system-specific joystick related cleanup */
void
SDL_SYS_JoystickQuit(void)
{
if (motionManager != nil) {
[motionManager release];
@autoreleasepool {
motionManager = nil;
}

numjoysticks = 0;
}

SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
Expand Down

0 comments on commit 02b06c6

Please sign in to comment.