Skip to content

Commit

Permalink
Fix conflicts between controller-triggered run modes and swipe-trigge…
Browse files Browse the repository at this point in the history
…red run-mode. Fixes #640
  • Loading branch information
LIJI32 committed Jun 28, 2024
1 parent 8db2490 commit 407e540
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions iOS/GBBackgroundView.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@

- (void)enterPreviewMode:(bool)showLabel;
- (void)reloadThemeImages;
- (void)fadeOverlayOut;
@end
1 change: 1 addition & 0 deletions iOS/GBViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ typedef enum {
GBRunModeTurbo,
GBRunModeRewind,
GBRunModePaused,
GBRunModeUnderclock,
} GBRunMode;

@interface GBViewController : UIViewController <UIApplicationDelegate,
Expand Down
38 changes: 30 additions & 8 deletions iOS/GBViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ @implementation GBViewController
__weak GCController *_lastController;

dispatch_queue_t _cameraQueue;

bool _runModeFromController;
}

static void loadBootROM(GB_gameboy_t *gb, GB_boot_rom_t type)
Expand Down Expand Up @@ -390,9 +392,14 @@ - (void)controller:(GCController *)controller buttonChanged:(GCControllerButtonI
if (button.isAnalog && [[NSUserDefaults standardUserDefaults] boolForKey:@"GBDynamicSpeed"]) {
GB_set_clock_multiplier(&_gb, (button.value - analogThreshold) / (1 - analogThreshold) * 3 + 1);
}
_runModeFromController = true;
[_backgroundView fadeOverlayOut];
}
else {
[self setRunMode:GBRunModeNormal];
if (self.runMode == GBRunModeTurbo && _runModeFromController) {
[self setRunMode:GBRunModeNormal];
_runModeFromController = false;
}
}
break;
case GBRewind:
Expand All @@ -401,22 +408,30 @@ - (void)controller:(GCController *)controller buttonChanged:(GCControllerButtonI
if (button.isAnalog && [[NSUserDefaults standardUserDefaults] boolForKey:@"GBDynamicSpeed"]) {
GB_set_clock_multiplier(&_gb, (button.value - analogThreshold) / (1 - analogThreshold) * 4);
}
_runModeFromController = true;
[_backgroundView fadeOverlayOut];
}
else {
[self setRunMode:GBRunModeNormal];
if (self.runMode == GBRunModeRewind && _runModeFromController) {
[self setRunMode:GBRunModeNormal];
_runModeFromController = false;
}
}
break;
case GBUnderclock:
if (button.value > analogThreshold) {
[self setRunMode:GBRunModeUnderclock ignoreDynamicSpeed:!button.isAnalog];
if (button.isAnalog && [[NSUserDefaults standardUserDefaults] boolForKey:@"GBDynamicSpeed"]) {
GB_set_clock_multiplier(&_gb, 1 - ((button.value - analogThreshold) / (1 - analogThreshold) * 0.75));
}
else {
GB_set_clock_multiplier(&_gb, 0.5);
}
_runModeFromController = true;
[_backgroundView fadeOverlayOut];
}
else {
GB_set_clock_multiplier(&_gb, 1.0);
if (self.runMode == GBRunModeUnderclock && _runModeFromController) {
[self setRunMode:GBRunModeNormal];
_runModeFromController = false;
}
}
break;
default: break;
Expand Down Expand Up @@ -1030,6 +1045,10 @@ - (void)stop
[_audioLock signal];
[_audioLock unlock];
}
dispatch_async(dispatch_get_main_queue(), ^{
self.runMode = GBRunModeNormal;
[_backgroundView fadeOverlayOut];
});
}


Expand Down Expand Up @@ -1161,16 +1180,19 @@ - (void)setRunMode:(GBRunMode)runMode ignoreDynamicSpeed:(bool)ignoreDynamicSpee
[_audioClient stop];
}

if (_runMode == GBRunModeNormal || _runMode == GBRunModeTurbo) {
if (_runMode == GBRunModeNormal || _runMode == GBRunModeTurbo || _runMode == GBRunModeUnderclock) {
_rewindOver = false;
}

if (_runMode == GBRunModeNormal || !([[NSUserDefaults standardUserDefaults] boolForKey:@"GBDynamicSpeed"] && !ignoreDynamicSpeed)) {
if (_runMode == GBRunModeNormal || _runMode == GBRunModeUnderclock || !([[NSUserDefaults standardUserDefaults] boolForKey:@"GBDynamicSpeed"] && !ignoreDynamicSpeed)) {
if (_runMode == GBRunModeTurbo) {
double multiplier = [[NSUserDefaults standardUserDefaults] doubleForKey:@"GBTurboSpeed"];
GB_set_turbo_mode(&_gb, multiplier == 1, false);
GB_set_clock_multiplier(&_gb, multiplier);
}
else if (_runMode == GBRunModeUnderclock) {
GB_set_clock_multiplier(&_gb, 0.5);
}
else {
GB_set_turbo_mode(&_gb, false, false);
GB_set_clock_multiplier(&_gb, 1.0);
Expand Down

0 comments on commit 407e540

Please sign in to comment.