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

View File

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

View File

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

View File

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