(iOS) Change handling of iterate loop
This commit is contained in:
parent
f0774266a1
commit
d39f5280f9
|
@ -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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
RARCH_LOG("Iterate Ended\n");
|
||||||
|
_isIterating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)startTimer
|
- (void)schedule
|
||||||
{
|
{
|
||||||
if (!_gameTimer)
|
_isScheduled = true;
|
||||||
_gameTimer = [NSTimer scheduledTimerWithTimeInterval:0.001f target:self selector:@selector(iterate) userInfo:nil repeats:YES];
|
[self performSelector:@selector(iterate) withObject:self afterDelay:.01f];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stopTimer
|
- (void)lapse
|
||||||
{
|
{
|
||||||
if (_gameTimer)
|
_isScheduled = false;
|
||||||
[_gameTimer invalidate];
|
|
||||||
|
|
||||||
_gameTimer = nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#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
|
||||||
|
|
Loading…
Reference in New Issue