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 Apr 6, 2015
2 parents f3590ab + 66867e6 commit df98b11
Show file tree
Hide file tree
Showing 32 changed files with 1,607 additions and 1,313 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
3 changes: 3 additions & 0 deletions include/SDL_config_iphoneos.h
Expand Up @@ -145,6 +145,9 @@
/* enable iPhone keyboard support */
#define SDL_IPHONE_KEYBOARD 1

/* enable iOS extended launch screen */
#define SDL_IPHONE_LAUNCHSCREEN 1

/* enable joystick subsystem */
#define SDL_JOYSTICK_DISABLED 0

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
14 changes: 14 additions & 0 deletions include/SDL_system.h
Expand Up @@ -76,6 +76,20 @@ 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);

/**
\brief 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);

/**
\brief 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
3 changes: 3 additions & 0 deletions premake/Xcode-iOS/SDL_config_premake.h
Expand Up @@ -126,6 +126,9 @@
#ifndef SDL_IPHONE_KEYBOARD
#define SDL_IPHONE_KEYBOARD 1
#endif
#ifndef SDL_IPHONE_LAUNCHSCREEN
#define SDL_IPHONE_LAUNCHSCREEN 1
#endif
#ifndef SDL_POWER_UIKIT
#define SDL_POWER_UIKIT 1
#endif
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.
* Joystick 0 should be the system default joystick.
Expand All @@ -43,12 +45,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 @@ -81,13 +89,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 @@ -104,11 +114,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 @@ -152,17 +164,20 @@ static void SDL_SYS_AccelerometerUpdate(SDL_Joystick * joystick)
void
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
{
[motionManager stopAccelerometerUpdates];
@autoreleasepool {
[motionManager stopAccelerometerUpdates];
}
}

/* 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
9 changes: 9 additions & 0 deletions src/render/opengles/SDL_render_gles.c
Expand Up @@ -55,6 +55,7 @@ static const float inv255f = 1.0f / 255.0f;
static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags);
static void GLES_WindowEvent(SDL_Renderer * renderer,
const SDL_WindowEvent *event);
static int GLES_GetOutputSize(SDL_Renderer * renderer, int *w, int *h);
static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
Expand Down Expand Up @@ -321,6 +322,7 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
}

renderer->WindowEvent = GLES_WindowEvent;
renderer->GetOutputSize = GLES_GetOutputSize;
renderer->CreateTexture = GLES_CreateTexture;
renderer->UpdateTexture = GLES_UpdateTexture;
renderer->LockTexture = GLES_LockTexture;
Expand Down Expand Up @@ -438,6 +440,13 @@ GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
}
}

static int
GLES_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
{
SDL_GL_GetDrawableSize(renderer->window, w, h);
return 0;
}

static SDL_INLINE int
power_of_2(int input)
{
Expand Down
8 changes: 8 additions & 0 deletions src/render/opengles2/SDL_render_gles2.c
Expand Up @@ -369,6 +369,13 @@ GLES2_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
}
}

static int
GLES2_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
{
SDL_GL_GetDrawableSize(renderer->window, w, h);
return 0;
}

static int
GLES2_UpdateViewport(SDL_Renderer * renderer)
{
Expand Down Expand Up @@ -2059,6 +2066,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)

/* Populate the function pointers for the module */
renderer->WindowEvent = &GLES2_WindowEvent;
renderer->GetOutputSize = &GLES2_GetOutputSize;
renderer->CreateTexture = &GLES2_CreateTexture;
renderer->UpdateTexture = &GLES2_UpdateTexture;
renderer->UpdateTextureYUV = &GLES2_UpdateTextureYUV;
Expand Down

0 comments on commit df98b11

Please sign in to comment.