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 Nov 16, 2014
2 parents e695ec9 + fb6d185 commit 0b02de7
Show file tree
Hide file tree
Showing 26 changed files with 882 additions and 833 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
3 changes: 3 additions & 0 deletions Xcode-iOS/Demos/src/fireworks.c
Expand Up @@ -387,6 +387,9 @@ main(int argc, char *argv[])
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

/* create main window and renderer */
window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_OPENGL |
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
10 changes: 10 additions & 0 deletions include/SDL_system.h
Expand Up @@ -70,6 +70,16 @@ extern DECLSPEC SDL_bool SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *a
extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);

/* Returns the OpenGL Renderbuffer Object associated with the window's main view.
The Renderbuffer must be bound when calling SDL_GL_SwapWindow.
*/
extern DECLSPEC Uint32 SDLCALL SDL_iPhoneGetViewRenderbuffer(SDL_Window * window);

/* Returns the OpenGL Framebuffer Object associated with the window's main view.
The Framebuffer must be bound when rendering to the screen.
*/
extern DECLSPEC Uint32 SDLCALL SDL_iPhoneGetViewFramebuffer(SDL_Window * window);

#endif /* __IPHONEOS__ */


Expand Down
5 changes: 2 additions & 3 deletions src/file/cocoa/SDL_rwopsbundlesupport.m
Expand Up @@ -50,14 +50,13 @@
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 {
} else {
fp = fopen(file, mode);
}

return fp;
}}

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

/* vi: set ts=4 sw=4 expandtab: */
5 changes: 4 additions & 1 deletion src/filesystem/cocoa/SDL_sysfilesystem.m
Expand Up @@ -41,6 +41,7 @@
const char* baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String];
const char *base = NULL;
char *retval = NULL;

if (baseType == NULL) {
baseType = "resource";
}
Expand All @@ -52,6 +53,7 @@
/* 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);
Expand All @@ -69,9 +71,10 @@
SDL_GetPrefPath(const char *org, const char *app)
{ @autoreleasepool
{
NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
char *retval = NULL;

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];
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
37 changes: 19 additions & 18 deletions src/power/uikit/SDL_syspower.m
Expand Up @@ -50,24 +50,24 @@
SDL_bool
SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent)
{
UIDevice *uidev = [UIDevice currentDevice];
@autoreleasepool {
UIDevice *uidev = [UIDevice currentDevice];

if (!SDL_UIKitLastPowerInfoQuery) {
SDL_assert([uidev isBatteryMonitoringEnabled] == NO);
[uidev setBatteryMonitoringEnabled:YES];
}
if (!SDL_UIKitLastPowerInfoQuery) {
SDL_assert(uidev.isBatteryMonitoringEnabled == NO);
uidev.batteryMonitoringEnabled = YES;
}

/* UIKit_GL_SwapWindow() (etc) will check this and disable the battery
* monitoring if the app hasn't queried it in the last X seconds.
* Apparently monitoring the battery burns battery life. :)
* Apple's docs say not to monitor the battery unless you need it.
*/
SDL_UIKitLastPowerInfoQuery = SDL_GetTicks();
/* UIKit_GL_SwapWindow() (etc) will check this and disable the battery
* monitoring if the app hasn't queried it in the last X seconds.
* Apparently monitoring the battery burns battery life. :)
* Apple's docs say not to monitor the battery unless you need it.
*/
SDL_UIKitLastPowerInfoQuery = SDL_GetTicks();

*seconds = -1; /* no API to estimate this in UIKit. */
*seconds = -1; /* no API to estimate this in UIKit. */

switch ([uidev batteryState])
{
switch (uidev.batteryState) {
case UIDeviceBatteryStateCharging:
*state = SDL_POWERSTATE_CHARGING;
break;
Expand All @@ -84,11 +84,12 @@
default:
*state = SDL_POWERSTATE_UNKNOWN;
break;
}
}

const float level = [uidev batteryLevel];
*percent = ( (level < 0.0f) ? -1 : ((int) ((level * 100) + 0.5f)) );
return SDL_TRUE; /* always the definitive answer on iOS. */
const float level = uidev.batteryLevel;
*percent = ( (level < 0.0f) ? -1 : ((int) ((level * 100) + 0.5f)) );
return SDL_TRUE; /* always the definitive answer on iOS. */
}
}

#endif /* SDL_POWER_UIKIT */
Expand Down

0 comments on commit 0b02de7

Please sign in to comment.