Skip to content

Commit

Permalink
IOS: Removes a global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Bénony committed Jan 6, 2016
1 parent dad50ae commit dd950fd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
6 changes: 6 additions & 0 deletions backends/platform/ios7/iOS7AppDelegate.h
Expand Up @@ -4,6 +4,12 @@

#import <UIKit/UIKit.h>

@class iPhoneView;


@interface iOS7AppDelegate : NSObject<UIApplicationDelegate>

+ (iOS7AppDelegate *)iOS7AppDelegate;
+ (iPhoneView *)iPhoneView;

@end
10 changes: 10 additions & 0 deletions backends/platform/ios7/iOS7AppDelegate.mm
Expand Up @@ -76,6 +76,16 @@ - (void)didRotate:(NSNotification *)notification {
[_view deviceOrientationChanged:screenOrientation];
}

+ (iOS7AppDelegate *)iOS7AppDelegate {
UIApplication *app = [UIApplication sharedApplication];
return (iOS7AppDelegate *) app.delegate;
}

+ (iPhoneView *)iPhoneView {
iOS7AppDelegate *appDelegate = [self iOS7AppDelegate];
return appDelegate->_view;
}

@end

const char *iOS7_getDocumentsDir() {
Expand Down
23 changes: 12 additions & 11 deletions backends/platform/ios7/ios7_osys_video.mm
Expand Up @@ -27,9 +27,10 @@
#include "ios7_video.h"

#include "graphics/conversion.h"
#import "iOS7AppDelegate.h"

void OSystem_iOS7::initVideoContext() {
_videoContext = [g_iPhoneViewInstance getVideoContext];
_videoContext = [[iOS7AppDelegate iPhoneView] getVideoContext];
}

const OSystem::GraphicsMode *OSystem_iOS7::getSupportedGraphicsModes() const {
Expand Down Expand Up @@ -82,7 +83,7 @@
// Create the screen texture right here. We need to do this here, since
// when a game requests hi-color mode, we actually set the framebuffer
// to the texture buffer to avoid an additional copy step.
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(createScreenTexture) withObject:nil waitUntilDone: YES];
[[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(createScreenTexture) withObject:nil waitUntilDone: YES];

// In case the client code tries to set up a non supported mode, we will
// fall back to CLUT8 and set the transaction error accordingly.
Expand Down Expand Up @@ -119,13 +120,13 @@
OSystem::TransactionError OSystem_iOS7::endGFXTransaction() {
_screenChangeCount++;
updateOutputSurface();
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(setGraphicsMode) withObject:nil waitUntilDone: YES];
[[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(setGraphicsMode) withObject:nil waitUntilDone: YES];

return _gfxTransactionError;
}

void OSystem_iOS7::updateOutputSurface() {
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(initSurface) withObject:nil waitUntilDone: YES];
[[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(initSurface) withObject:nil waitUntilDone: YES];
}

int16 OSystem_iOS7::getHeight() {
Expand Down Expand Up @@ -285,7 +286,7 @@
void OSystem_iOS7::setShakePos(int shakeOffset) {
//printf("setShakePos(%i)\n", shakeOffset);
_videoContext->shakeOffsetY = shakeOffset;
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(setViewTransformation) withObject:nil waitUntilDone: YES];
[[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(setViewTransformation) withObject:nil waitUntilDone: YES];
// HACK: We use this to force a redraw.
_mouseDirty = true;
}
Expand All @@ -295,17 +296,17 @@
_videoContext->overlayVisible = true;
dirtyFullOverlayScreen();
updateScreen();
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursorScaling) withObject:nil waitUntilDone: YES];
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES];
[[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(updateMouseCursorScaling) withObject:nil waitUntilDone: YES];
[[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES];
}

void OSystem_iOS7::hideOverlay() {
//printf("hideOverlay()\n");
_videoContext->overlayVisible = false;
_dirtyOverlayRects.clear();
dirtyFullScreen();
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursorScaling) withObject:nil waitUntilDone: YES];
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES];
[[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(updateMouseCursorScaling) withObject:nil waitUntilDone: YES];
[[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES];
}

void OSystem_iOS7::clearOverlay() {
Expand Down Expand Up @@ -386,7 +387,7 @@
//printf("warpMouse(%d, %d)\n", x, y);
_videoContext->mouseX = x;
_videoContext->mouseY = y;
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(notifyMouseMove) withObject:nil waitUntilDone: YES];
[[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(notifyMouseMove) withObject:nil waitUntilDone: YES];
_mouseDirty = true;
}

Expand Down Expand Up @@ -499,5 +500,5 @@
}
}

[g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES];
[[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES];
}
2 changes: 0 additions & 2 deletions backends/platform/ios7/ios7_video.h
Expand Up @@ -104,6 +104,4 @@

@end

extern iPhoneView *g_iPhoneViewInstance;

#endif
8 changes: 3 additions & 5 deletions backends/platform/ios7/ios7_video.mm
Expand Up @@ -27,8 +27,8 @@

#include "graphics/colormasks.h"
#include "common/system.h"
#import "iOS7AppDelegate.h"

iPhoneView *g_iPhoneViewInstance = nil;
static int g_fullWidth;
static int g_fullHeight;

Expand Down Expand Up @@ -62,12 +62,12 @@ void iOS7_updateScreen() {
//printf("Mouse: (%i, %i)\n", mouseX, mouseY);
if (!g_needsScreenUpdate) {
g_needsScreenUpdate = 1;
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateSurface) withObject:nil waitUntilDone: NO];
[[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(updateSurface) withObject:nil waitUntilDone: NO];
}
}

bool iOS7_fetchEvent(InternalEvent *event) {
return [g_iPhoneViewInstance fetchEvent:event];
return [[iOS7AppDelegate iPhoneView] fetchEvent:event];
}

uint getSizeNextPOT(uint size) {
Expand Down Expand Up @@ -233,8 +233,6 @@ - (id)initWithFrame:(struct CGRect)frame {
_contentScaleFactor = [self optimalScale];
[self setContentScaleFactor:_contentScaleFactor];

g_iPhoneViewInstance = self;

_keyboardView = nil;
_screenTexture = 0;
_overlayTexture = 0;
Expand Down

0 comments on commit dd950fd

Please sign in to comment.