limit max speed to 4x, don't persist speed setting

This commit is contained in:
Jesús A. Álvarez 2016-05-14 14:04:18 +02:00
parent 8b31f58a9b
commit ac333642fd
4 changed files with 27 additions and 42 deletions

View File

@ -11,21 +11,10 @@
extern NSString * const MNVMDidInsertDiskNotification;
extern NSString * const MNVMDidEjectDiskNotification;
typedef enum : NSUInteger {
EmulationSpeedMax = -1,
EmulationSpeed1x = 0,
EmulationSpeed2x,
EmulationSpeed4x,
EmulationSpeed8x,
EmulationSpeed16x,
EmulationSpeed32x
} EmulationSpeed;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (assign, nonatomic, getter=isEmulatorRunning) BOOL emulatorRunning;
@property (nonatomic, assign) EmulationSpeed emulationSpeed;
@property (nonatomic, readonly) NSString *documentsPath;
@property (nonatomic, readonly) NSArray<NSString*> *diskImageExtensions;

View File

@ -40,7 +40,12 @@ NSString * const MNVMDidEjectDiskNotification = @"MNVMDidEjectDisk";
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
sharedAppDelegate = self;
[self initDefaults];
[self performSelector:@selector(runEmulator) withObject:nil afterDelay:0.1];
return YES;
}
- (void)initDefaults {
// default settings
NSString *defaultKeyboardLayout = @"US.nfkeyboardlayout";
NSLocale *locale = [NSLocale currentLocale];
@ -49,15 +54,22 @@ NSString * const MNVMDidEjectDiskNotification = @"MNVMDidEjectDisk";
} else if ([[locale objectForKey:NSLocaleLanguageCode] isEqualToString:@"es"]) {
defaultKeyboardLayout = @"Spanish.nfkeyboardlayout";
}
NSDictionary *defaults = @{@"speedValue": @(WantInitSpeedValue),
@"trackpad": @([UIDevice currentDevice].userInterfaceIdiom != UIUserInterfaceIdiomPad),
@"frameskip": @(0),
@"keyboardLayout": defaultKeyboardLayout
};
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
[self performSelector:@selector(runEmulator) withObject:nil afterDelay:0.1];
return YES;
NSDictionary *defaultValues = @{@"trackpad": @([UIDevice currentDevice].userInterfaceIdiom != UIUserInterfaceIdiomPad),
@"frameskip": @(0),
@"keyboardLayout": defaultKeyboardLayout
};
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults registerDefaults:defaultValues];
[defaults setValue:@(WantInitSpeedValue) forKey:@"speedValue"];
[defaults addObserver:self forKeyPath:@"speedValue" options:0 context:NULL];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
if (object == [NSUserDefaults standardUserDefaults]) {
if ([keyPath isEqualToString:@"speedValue"]) {
SpeedValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"speedValue"];
}
}
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
@ -181,6 +193,9 @@ NSString * const MNVMDidEjectDiskNotification = @"MNVMDidEjectDisk";
- (void)runEmulator {
SpeedValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"speedValue"];
if (SpeedValue > 3) {
SpeedValue = 3;
}
RunEmulator();
}
@ -192,15 +207,6 @@ NSString * const MNVMDidEjectDiskNotification = @"MNVMDidEjectDisk";
SetSpeedStopped(emulatorRunning);
}
- (EmulationSpeed)emulationSpeed {
return SpeedValue;
}
- (void)setEmulationSpeed:(EmulationSpeed)emulationSpeed {
SpeedValue = emulationSpeed;
[[NSUserDefaults standardUserDefaults] setInteger:emulationSpeed forKey:@"speedValue"];
}
#pragma mark - Mouse
- (void)setMouseX:(NSInteger)x Y:(NSInteger)y {

View File

@ -64,8 +64,6 @@
<segment title="2x"/>
<segment title="4x"/>
<segment title="8x"/>
<segment title="16x"/>
<segment title="Max"/>
</segments>
<connections>
<action selector="changeSpeed:" destination="WUA-f8-k8g" eventType="valueChanged" id="FDr-uw-7bN"/>

View File

@ -33,14 +33,7 @@
- (IBAction)changeSpeed:(UISegmentedControl*)sender {
if ([sender isKindOfClass:[UISegmentedControl class]]) {
EmulationSpeed speedValues[] = {
EmulationSpeed1x,
EmulationSpeed2x,
EmulationSpeed4x,
EmulationSpeed8x,
EmulationSpeed16x,
EmulationSpeedMax};
[AppDelegate sharedInstance].emulationSpeed = speedValues[sender.selectedSegmentIndex];
[[NSUserDefaults standardUserDefaults] setInteger:sender.selectedSegmentIndex forKey:@"speedValue"];
}
}
@ -81,8 +74,7 @@
if (section == 0) {
cell = [tableView dequeueReusableCellWithIdentifier:@"speed" forIndexPath:indexPath];
UISegmentedControl *speedControl = (UISegmentedControl*)[cell viewWithTag:128];
EmulationSpeed speed = [AppDelegate sharedInstance].emulationSpeed;
speedControl.selectedSegmentIndex = speed == EmulationSpeedMax ? 5 : speed;
speedControl.selectedSegmentIndex = [defaults integerForKey:@"speedValue"];
} else if (section == 1) {
cell = [tableView dequeueReusableCellWithIdentifier:@"mouse" forIndexPath:indexPath];
UISegmentedControl *mouseControl = (UISegmentedControl*)[cell viewWithTag:128];