aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/iphone/iphone_video.mm
diff options
context:
space:
mode:
Diffstat (limited to 'backends/platform/iphone/iphone_video.mm')
-rw-r--r--backends/platform/iphone/iphone_video.mm150
1 files changed, 30 insertions, 120 deletions
diff --git a/backends/platform/iphone/iphone_video.mm b/backends/platform/iphone/iphone_video.mm
index 5b78237ff7..7877bc6430 100644
--- a/backends/platform/iphone/iphone_video.mm
+++ b/backends/platform/iphone/iphone_video.mm
@@ -65,23 +65,8 @@ void iPhone_updateScreen() {
}
}
-bool iPhone_fetchEvent(int *outEvent, int *outX, int *outY) {
- id event = [g_iPhoneViewInstance getEvent];
- if (event == nil) {
- return false;
- }
-
- id type = [event objectForKey:@"type"];
-
- if (type == nil) {
- printf("fetchEvent says: No type!\n");
- return false;
- }
-
- *outEvent = [type intValue];
- *outX = [[event objectForKey:@"x"] intValue];
- *outY = [[event objectForKey:@"y"] intValue];
- return true;
+bool iPhone_fetchEvent(InternalEvent *event) {
+ return [g_iPhoneViewInstance fetchEvent:event];
}
uint getSizeNextPOT(uint size) {
@@ -197,6 +182,8 @@ const char *iPhone_getDocumentsDir() {
_firstTouch = NULL;
_secondTouch = NULL;
+ _eventLock = [[NSLock alloc] init];
+
_gameScreenVertCoords[0] = _gameScreenVertCoords[1] =
_gameScreenVertCoords[2] = _gameScreenVertCoords[3] =
_gameScreenVertCoords[4] = _gameScreenVertCoords[5] =
@@ -242,6 +229,7 @@ const char *iPhone_getDocumentsDir() {
_videoContext.overlayTexture.free();
_videoContext.mouseTexture.free();
+ [_eventLock dealloc];
[super dealloc];
}
@@ -575,23 +563,23 @@ const char *iPhone_getDocumentsDir() {
}
}
-- (id)getEvent {
- if (_events == nil || [_events count] == 0) {
- return nil;
- }
-
- id event = [_events objectAtIndex: 0];
-
- [_events removeObjectAtIndex: 0];
-
- return event;
+- (void)addEvent:(InternalEvent)event {
+ [_eventLock lock];
+ _events.push_back(event);
+ [_eventLock unlock];
}
-- (void)addEvent:(NSDictionary *)event {
- if (_events == nil)
- _events = [[NSMutableArray alloc] init];
+- (bool)fetchEvent:(InternalEvent *)event {
+ [_eventLock lock];
+ if (_events.empty()) {
+ [_eventLock unlock];
+ return false;
+ }
- [_events addObject: event];
+ *event = *_events.begin();
+ _events.pop_front();
+ [_eventLock unlock];
+ return true;
}
/**
@@ -664,14 +652,7 @@ const char *iPhone_getDocumentsDir() {
return;
}
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputOrientationChanged], @"type",
- [NSNumber numberWithInt:orientation], @"x",
- [NSNumber numberWithInt:0], @"y",
- nil
- ]
- ];
+ [self addEvent:InternalEvent(kInputOrientationChanged, orientation, 0)];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
@@ -686,14 +667,7 @@ const char *iPhone_getDocumentsDir() {
return;
_firstTouch = touch;
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputMouseDown], @"type",
- [NSNumber numberWithInt:x], @"x",
- [NSNumber numberWithInt:y], @"y",
- nil
- ]
- ];
+ [self addEvent:InternalEvent(kInputMouseDown, x, y)];
break;
}
@@ -704,14 +678,7 @@ const char *iPhone_getDocumentsDir() {
return;
_secondTouch = touch;
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputMouseSecondDown], @"type",
- [NSNumber numberWithInt:x], @"x",
- [NSNumber numberWithInt:y], @"y",
- nil
- ]
- ];
+ [self addEvent:InternalEvent(kInputMouseSecondDown, x, y)];
break;
}
}
@@ -727,27 +694,13 @@ const char *iPhone_getDocumentsDir() {
if (![self getMouseCoords:point eventX:&x eventY:&y])
return;
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputMouseDragged], @"type",
- [NSNumber numberWithInt:x], @"x",
- [NSNumber numberWithInt:y], @"y",
- nil
- ]
- ];
+ [self addEvent:InternalEvent(kInputMouseDragged, x, y)];
} else if (touch == _secondTouch) {
CGPoint point = [touch locationInView:self];
if (![self getMouseCoords:point eventX:&x eventY:&y])
return;
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputMouseSecondDragged], @"type",
- [NSNumber numberWithInt:x], @"x",
- [NSNumber numberWithInt:y], @"y",
- nil
- ]
- ];
+ [self addEvent:InternalEvent(kInputMouseSecondDragged, x, y)];
}
}
}
@@ -763,14 +716,7 @@ const char *iPhone_getDocumentsDir() {
if (![self getMouseCoords:point eventX:&x eventY:&y])
return;
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputMouseUp], @"type",
- [NSNumber numberWithInt:x], @"x",
- [NSNumber numberWithInt:y], @"y",
- nil
- ]
- ];
+ [self addEvent:InternalEvent(kInputMouseUp, x, y)];
break;
}
@@ -780,14 +726,7 @@ const char *iPhone_getDocumentsDir() {
if (![self getMouseCoords:point eventX:&x eventY:&y])
return;
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputMouseSecondUp], @"type",
- [NSNumber numberWithInt:x], @"x",
- [NSNumber numberWithInt:y], @"y",
- nil
- ]
- ];
+ [self addEvent:InternalEvent(kInputMouseSecondUp, x, y)];
break;
}
}
@@ -797,14 +736,7 @@ const char *iPhone_getDocumentsDir() {
}
- (void)handleKeyPress:(unichar)c {
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputKeyPressed], @"type",
- [NSNumber numberWithInt:c], @"x",
- [NSNumber numberWithInt:0], @"y",
- nil
- ]
- ];
+ [self addEvent:InternalEvent(kInputKeyPressed, c, 0)];
}
- (BOOL)canHandleSwipes {
@@ -814,38 +746,16 @@ const char *iPhone_getDocumentsDir() {
- (int)swipe:(int)num withEvent:(struct __GSEvent *)event {
//printf("swipe: %i\n", num);
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputSwipe], @"type",
- [NSNumber numberWithInt:num], @"x",
- [NSNumber numberWithInt:0], @"y",
- nil
- ]
- ];
-
+ [self addEvent:InternalEvent(kInputSwipe, num, 0)];
return 0;
}
- (void)applicationSuspend {
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputApplicationSuspended], @"type",
- [NSNumber numberWithInt:0], @"x",
- [NSNumber numberWithInt:0], @"y",
- nil
- ]
- ];
+ [self addEvent:InternalEvent(kInputApplicationSuspended, 0, 0)];
}
- (void)applicationResume {
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputApplicationResumed], @"type",
- [NSNumber numberWithInt:0], @"x",
- [NSNumber numberWithInt:0], @"y",
- nil
- ]
- ];
+ [self addEvent:InternalEvent(kInputApplicationResumed, 0, 0)];
}
@end