(iOS) Change handling of iterate loop

This commit is contained in:
meancoot 2013-03-21 16:36:48 -04:00
parent f0774266a1
commit d39f5280f9
1 changed files with 42 additions and 25 deletions

View File

@ -27,8 +27,9 @@
@implementation RetroArch_iOS @implementation RetroArch_iOS
{ {
UIWindow* _window; UIWindow* _window;
NSTimer* _gameTimer;
bool _isIterating;
bool _isScheduled;
bool _isGameTop; bool _isGameTop;
bool _isPaused; bool _isPaused;
bool _isRunning; bool _isRunning;
@ -66,14 +67,15 @@
- (void)applicationDidBecomeActive:(UIApplication*)application - (void)applicationDidBecomeActive:(UIApplication*)application
{ {
[self startTimer]; [self schedule];
} }
- (void)applicationWillResignActive:(UIApplication*)application - (void)applicationWillResignActive:(UIApplication*)application
{ {
[self stopTimer]; [self lapse];
} }
- (void)applicationWillEnterForeground:(UIApplication *)application - (void)applicationWillEnterForeground:(UIApplication *)application
{ {
if (_isRunning) if (_isRunning)
@ -94,7 +96,7 @@
self.navigationBarHidden = _isGameTop; self.navigationBarHidden = _isGameTop;
if (_isGameTop) if (_isGameTop)
[self startTimer]; [self schedule];
self.topViewController.navigationItem.rightBarButtonItem = [self createBluetoothButton]; self.topViewController.navigationItem.rightBarButtonItem = [self createBluetoothButton];
} }
@ -179,24 +181,43 @@
- (void)iterate - (void)iterate
{ {
if (_isPaused || !_isRunning || !_isGameTop) RARCH_LOG("Iterate Began\n");
[self stopTimer];
else if (_isRunning && !rarch_main_iterate()) if (_isIterating)
{
RARCH_LOG("Recursive Iterate");
return;
}
_isIterating = true;
SInt32 runLoopResult = kCFRunLoopRunTimedOut;
while (!_isPaused && _isRunning && _isGameTop && _isScheduled && runLoopResult == kCFRunLoopRunTimedOut)
{
if (!rarch_main_iterate())
[self closeGame]; [self closeGame];
// Here's a construct you don't see every day
for (
runLoopResult = kCFRunLoopRunHandledSource;
runLoopResult == kCFRunLoopRunHandledSource;
runLoopResult = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true)
);
} }
- (void)startTimer RARCH_LOG("Iterate Ended\n");
{ _isIterating = false;
if (!_gameTimer)
_gameTimer = [NSTimer scheduledTimerWithTimeInterval:0.001f target:self selector:@selector(iterate) userInfo:nil repeats:YES];
} }
- (void)stopTimer - (void)schedule
{ {
if (_gameTimer) _isScheduled = true;
[_gameTimer invalidate]; [self performSelector:@selector(iterate) withObject:self afterDelay:.01f];
}
_gameTimer = nil; - (void)lapse
{
_isScheduled = false;
} }
#pragma mark PAUSE MENU #pragma mark PAUSE MENU
@ -235,12 +256,8 @@
- (IBAction)closePauseMenu:(id)sender - (IBAction)closePauseMenu:(id)sender
{ {
[[RAGameView get] closePauseMenu]; [[RAGameView get] closePauseMenu];
if (_isPaused)
{
_isPaused = false; _isPaused = false;
[self startTimer]; [self schedule];
}
} }
- (IBAction)closeGamePressed:(id)sender - (IBAction)closeGamePressed:(id)sender