Skip to content

Commit

Permalink
Prevent the rewind buffer from being reset unexpectedly on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
LIJI32 committed Nov 23, 2024
1 parent a0c5b6f commit 117da60
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion iOS/GBViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ @implementation GBViewController
UIButton *_printerButton;
UIActivityIndicatorView *_printerSpinner;
NSMutableData *_currentPrinterImageData;

NSString *_lastSavedROM;
NSDate *_saveDate;
}

static void loadBootROM(GB_gameboy_t *gb, GB_boot_rom_t type)
Expand Down Expand Up @@ -697,7 +700,17 @@ - (void)loadROM
}
}
}
GB_rewind_reset(&_gb);

NSDate *date = nil;
[[NSURL fileURLWithPath:[GBROMManager sharedManager].autosaveStateFile] getResourceValue:&date
forKey:NSURLContentModificationDateKey
error:nil];

// Reset the rewind buffer only if we switched ROMs or had the save state change externally
if (![_lastSavedROM isEqual:[GBROMManager sharedManager].currentROM] ||
![_saveDate isEqual:date]) {
GB_rewind_reset(&_gb);
}
}
}
else {
Expand Down Expand Up @@ -1155,6 +1168,14 @@ - (void)postRun
if (!_swappingROM) {
GB_save_battery(&_gb, [GBROMManager sharedManager].batterySaveFile.fileSystemRepresentation);
[self saveStateToFile:[GBROMManager sharedManager].autosaveStateFile];

NSDate *date;
[[NSURL fileURLWithPath:[GBROMManager sharedManager].autosaveStateFile] getResourceValue:&date
forKey:NSURLContentModificationDateKey
error:nil];
_saveDate = date;
_lastSavedROM = [GBROMManager sharedManager].currentROM;

}
[[GBHapticManager sharedManager] setRumbleStrength:0];
if (@available(iOS 14.0, *)) {
Expand Down

0 comments on commit 117da60

Please sign in to comment.