mirror of https://github.com/encounter/SDL.git
Misc. iOS code improvements.
- Use @autoreleasepool instead of NSAutoReleasePool. - Code style fixups.
This commit is contained in:
parent
96b613eab3
commit
734b523302
|
@ -8,6 +8,9 @@ Makefile
|
|||
sdl-config
|
||||
SDL2.spec
|
||||
build
|
||||
Build
|
||||
*xcuserdata*
|
||||
*xcworkspacedata*
|
||||
|
||||
# for Xcode
|
||||
*.orig
|
||||
|
|
|
@ -208,13 +208,21 @@ struct SDL_SysWMinfo
|
|||
#if defined(SDL_VIDEO_DRIVER_COCOA)
|
||||
struct
|
||||
{
|
||||
#if defined(__OBJC__) && __has_feature(objc_arc)
|
||||
NSWindow __unsafe_unretained *window; /* The Cocoa window */
|
||||
#else
|
||||
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 */
|
||||
#else
|
||||
UIWindow *window; /* The UIKit window */
|
||||
#endif
|
||||
} uikit;
|
||||
#endif
|
||||
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
|
||||
|
|
|
@ -41,9 +41,7 @@ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
|
|||
return fopen(file, mode);
|
||||
}
|
||||
|
||||
NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
@autoreleasepool {
|
||||
NSFileManager* file_manager = [NSFileManager defaultManager];
|
||||
NSString* resource_path = [[NSBundle mainBundle] resourcePath];
|
||||
|
||||
|
@ -56,12 +54,11 @@ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
|
|||
else {
|
||||
fp = fopen(file, mode);
|
||||
}
|
||||
|
||||
[autorelease_pool drain];
|
||||
}
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
#endif /* __MACOSX__ */
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -36,11 +36,12 @@
|
|||
char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
char *retval = NULL;
|
||||
|
||||
@autoreleasepool {
|
||||
const char *base = NULL;
|
||||
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";
|
||||
}
|
||||
|
@ -52,6 +53,7 @@ SDL_GetBasePath(void)
|
|||
/* 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);
|
||||
|
@ -61,18 +63,19 @@ SDL_GetBasePath(void)
|
|||
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;
|
||||
|
||||
@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];
|
||||
|
@ -95,8 +98,7 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ static UIWindow *launch_window;
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
/* store arguments */
|
||||
forward_argc = argc;
|
||||
|
@ -56,7 +55,9 @@ int main(int argc, char **argv)
|
|||
forward_argv[i] = NULL;
|
||||
|
||||
/* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
|
||||
@autoreleasepool {
|
||||
UIApplicationMain(argc, argv, NULL, [SDLUIKitDelegate getAppDelegateClassName]);
|
||||
}
|
||||
|
||||
/* free the memory we used to hold copies of argc and argv */
|
||||
for (i = 0; i < forward_argc; i++) {
|
||||
|
@ -64,7 +65,6 @@ int main(int argc, char **argv)
|
|||
}
|
||||
free(forward_argv);
|
||||
|
||||
[pool release];
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
|
@ -151,8 +151,8 @@ SDL_IdleTimerDisabledChanged(void *userdata, const char *name, const char *oldVa
|
|||
} else {
|
||||
image = self->splashPortrait;
|
||||
}
|
||||
if (image)
|
||||
{
|
||||
|
||||
if (image) {
|
||||
splash.image = image;
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ SDL_IdleTimerDisabledChanged(void *userdata, const char *name, const char *oldVa
|
|||
/* convenience method */
|
||||
+ (id) sharedAppDelegate
|
||||
{
|
||||
/* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */
|
||||
/* the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method */
|
||||
return [[UIApplication sharedApplication] delegate];
|
||||
}
|
||||
|
||||
|
|
|
@ -40,8 +40,9 @@ SDL_iPhoneSetEventPump(SDL_bool enabled)
|
|||
void
|
||||
UIKit_PumpEvents(_THIS)
|
||||
{
|
||||
if (!UIKit_EventPumpEnabled)
|
||||
if (!UIKit_EventPumpEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Let the run loop run for a short amount of time: long enough for
|
||||
touch events to get processed (which is important to get certain
|
||||
|
|
|
@ -71,17 +71,16 @@ int
|
|||
UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
||||
{
|
||||
int clicked;
|
||||
int i;
|
||||
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
UIAlertView* alert = [[UIAlertView alloc] init];
|
||||
|
||||
alert.title = [NSString stringWithUTF8String:messageboxdata->title];
|
||||
alert.message = [NSString stringWithUTF8String:messageboxdata->message];
|
||||
alert.delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked];
|
||||
|
||||
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
|
||||
int i;
|
||||
for (i = 0; i < messageboxdata->numbuttons; ++i) {
|
||||
[alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]];
|
||||
}
|
||||
|
@ -103,8 +102,7 @@ UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|||
|
||||
[alert.delegate release];
|
||||
[alert release];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ void _uikit_keyboard_init() ;
|
|||
CGPoint point = [touch locationInView: self];
|
||||
|
||||
/* Get the display scale and apply that to the input coordinates */
|
||||
SDL_Window *window = self->viewcontroller.window;
|
||||
SDL_Window *window = viewcontroller.window;
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
SDL_DisplayModeData *displaymodedata = (SDL_DisplayModeData *) display->current_mode.driverdata;
|
||||
|
||||
|
@ -83,18 +83,15 @@ void _uikit_keyboard_init() ;
|
|||
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
NSEnumerator *enumerator = [touches objectEnumerator];
|
||||
UITouch *touch = (UITouch*)[enumerator nextObject];
|
||||
|
||||
while (touch) {
|
||||
for (UITouch *touch in touches) {
|
||||
if (!leftFingerDown) {
|
||||
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
|
||||
|
||||
/* send moved event */
|
||||
SDL_SendMouseMotion(self->viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
|
||||
SDL_SendMouseMotion(viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
|
||||
|
||||
/* send mouse down event */
|
||||
SDL_SendMouseButton(self->viewcontroller.window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||
SDL_SendMouseButton(viewcontroller.window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||
|
||||
leftFingerDown = touch;
|
||||
}
|
||||
|
@ -118,19 +115,15 @@ void _uikit_keyboard_init() ;
|
|||
}
|
||||
}
|
||||
#endif
|
||||
touch = (UITouch*)[enumerator nextObject];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
NSEnumerator *enumerator = [touches objectEnumerator];
|
||||
UITouch *touch = (UITouch*)[enumerator nextObject];
|
||||
|
||||
while(touch) {
|
||||
for (UITouch *touch in touches) {
|
||||
if (touch == leftFingerDown) {
|
||||
/* send mouse up */
|
||||
SDL_SendMouseButton(self->viewcontroller.window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||
SDL_SendMouseButton(viewcontroller.window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||
leftFingerDown = nil;
|
||||
}
|
||||
|
||||
|
@ -149,7 +142,6 @@ void _uikit_keyboard_init() ;
|
|||
}
|
||||
}
|
||||
#endif
|
||||
touch = (UITouch*)[enumerator nextObject];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,15 +157,12 @@ void _uikit_keyboard_init() ;
|
|||
|
||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
NSEnumerator *enumerator = [touches objectEnumerator];
|
||||
UITouch *touch = (UITouch*)[enumerator nextObject];
|
||||
|
||||
while (touch) {
|
||||
for (UITouch *touch in touches) {
|
||||
if (touch == leftFingerDown) {
|
||||
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
|
||||
|
||||
/* send moved event */
|
||||
SDL_SendMouseMotion(self->viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
|
||||
SDL_SendMouseMotion(viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
|
||||
}
|
||||
|
||||
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
|
||||
|
@ -190,7 +179,6 @@ void _uikit_keyboard_init() ;
|
|||
}
|
||||
}
|
||||
#endif
|
||||
touch = (UITouch*)[enumerator nextObject];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue