From cc9c1af99a109fb1ce6a64b0bf2b99ef68e5b61b Mon Sep 17 00:00:00 2001 From: Eric Buchmann Date: Tue, 8 Oct 2019 17:26:06 -0700 Subject: [PATCH] add game speed controls --- OpenEmuBase/OEGameCore.m | 26 ++++++++++++++ OpenEmuBase/OESystemResponderClient.h | 2 ++ OpenEmuSystem/OEKeyBindingDescription.h | 2 ++ OpenEmuSystem/OEKeyBindingDescription.m | 8 +++++ OpenEmuSystem/OESystemBindings.h | 2 ++ OpenEmuSystem/OESystemBindings.m | 46 +++++++++++++------------ OpenEmuSystem/OESystemController.m | 4 +++ OpenEmuSystem/OESystemResponder.h | 2 ++ OpenEmuSystem/OESystemResponder.mm | 12 +++++++ 9 files changed, 82 insertions(+), 22 deletions(-) diff --git a/OpenEmuBase/OEGameCore.m b/OpenEmuBase/OEGameCore.m index 3293a0c..bdb8361 100644 --- a/OpenEmuBase/OEGameCore.m +++ b/OpenEmuBase/OEGameCore.m @@ -573,6 +573,32 @@ - (BOOL)isEmulationPaused return self.rate == 0; } +- (void)increaseGameSpeed +{ + float nextSpeed = self.rate + 0.25; + + if (nextSpeed >= 5) nextSpeed = 5.0; + + if (self.isEmulationPaused) { + lastRate = nextSpeed; + } else { + self.rate = nextSpeed; + } +} + +- (void)decreaseGameSpeed +{ + float nextSpeed = self.rate - 0.25; + + if (nextSpeed <= 0) nextSpeed = 0.25; + + if (self.isEmulationPaused) { + lastRate = nextSpeed; + } else { + self.rate = nextSpeed; + } +} + - (void)fastForwardAtSpeed:(CGFloat)fastForwardSpeed; { // FIXME: Need implementation. diff --git a/OpenEmuBase/OESystemResponderClient.h b/OpenEmuBase/OESystemResponderClient.h index 0704013..d5bdbfd 100644 --- a/OpenEmuBase/OESystemResponderClient.h +++ b/OpenEmuBase/OESystemResponderClient.h @@ -34,6 +34,8 @@ - (void)fastForward:(BOOL)flag; - (void)fastForwardAtSpeed:(CGFloat)fastForwardSpeed; +- (void)increaseGameSpeed; +- (void)decreaseGameSpeed; - (void)rewind:(BOOL)flag; - (void)rewindAtSpeed:(CGFloat)rewindSpeed; - (void)slowMotionAtSpeed:(CGFloat)slowMotionSpeed; diff --git a/OpenEmuSystem/OEKeyBindingDescription.h b/OpenEmuSystem/OEKeyBindingDescription.h index 3092fc3..2c60e20 100644 --- a/OpenEmuSystem/OEKeyBindingDescription.h +++ b/OpenEmuSystem/OEKeyBindingDescription.h @@ -50,6 +50,8 @@ typedef NS_ENUM(NSUInteger, OEGlobalButtonIdentifier) { OEGlobalButtonIdentifierPause, OEGlobalButtonIdentifierRewind, OEGlobalButtonIdentifierFastForward, + OEGlobalButtonIdentifierIncreaseGameSpeed, + OEGlobalButtonIdentifierDecreaseGameSpeed, OEGlobalButtonIdentifierSlowMotion, OEGlobalButtonIdentifierStepFrameBackward, OEGlobalButtonIdentifierStepFrameForward, diff --git a/OpenEmuSystem/OEKeyBindingDescription.m b/OpenEmuSystem/OEKeyBindingDescription.m index 50781df..a2eefb9 100644 --- a/OpenEmuSystem/OEKeyBindingDescription.m +++ b/OpenEmuSystem/OEKeyBindingDescription.m @@ -70,6 +70,10 @@ return @"OEGlobalButtonIdentifierRewind"; case OEGlobalButtonIdentifierFastForward : return @"OEGlobalButtonIdentifierFastForward"; + case OEGlobalButtonIdentifierIncreaseGameSpeed : + return @"OEGlobalButtonIdentifierIncreaseGameSpeed"; + case OEGlobalButtonIdentifierDecreaseGameSpeed : + return @"OEGlobalButtonIdentifierDecreaseGameSpeed"; case OEGlobalButtonIdentifierSlowMotion : return @"OEGlobalButtonIdentifierSlowMotion"; case OEGlobalButtonIdentifierStepFrameBackward : @@ -127,6 +131,10 @@ return OEGlobalButtonRewind; case OEGlobalButtonIdentifierFastForward : return OEGlobalButtonFastForward; + case OEGlobalButtonIdentifierIncreaseGameSpeed : + return OEGlobalButtonIncreaseGameSpeed; + case OEGlobalButtonIdentifierDecreaseGameSpeed : + return OEGlobalButtonDecreaseGameSpeed; case OEGlobalButtonIdentifierSlowMotion : return OEGlobalButtonSlowMotion; case OEGlobalButtonIdentifierStepFrameBackward : diff --git a/OpenEmuSystem/OESystemBindings.h b/OpenEmuSystem/OESystemBindings.h index f6295e3..c2b6c1a 100644 --- a/OpenEmuSystem/OESystemBindings.h +++ b/OpenEmuSystem/OESystemBindings.h @@ -53,6 +53,8 @@ extern NSString *const OEGlobalButtonReset; extern NSString *const OEGlobalButtonPause; extern NSString *const OEGlobalButtonRewind; extern NSString *const OEGlobalButtonFastForward; +extern NSString *const OEGlobalButtonIncreaseGameSpeed; +extern NSString *const OEGlobalButtonDecreaseGameSpeed; extern NSString *const OEGlobalButtonSlowMotion; extern NSString *const OEGlobalButtonStepFrameBackward; extern NSString *const OEGlobalButtonStepFrameForward; diff --git a/OpenEmuSystem/OESystemBindings.m b/OpenEmuSystem/OESystemBindings.m index 7ca128c..fa970fa 100644 --- a/OpenEmuSystem/OESystemBindings.m +++ b/OpenEmuSystem/OESystemBindings.m @@ -42,28 +42,30 @@ static NSString *const _OEKeyboardPlayerBindingRepresentationsKey = @"keyboardPlayerBindings"; static NSString *const _OEControllerBindingRepresentationsKey = @"controllerBindings"; -NSString *const OEGlobalButtonSaveState = @"OEGlobalButtonSaveState"; -NSString *const OEGlobalButtonLoadState = @"OEGlobalButtonLoadState"; -NSString *const OEGlobalButtonQuickSave = @"OEGlobalButtonQuickSave"; -NSString *const OEGlobalButtonQuickLoad = @"OEGlobalButtonQuickLoad"; -NSString *const OEGlobalButtonFullScreen = @"OEGlobalButtonFullScreen"; -NSString *const OEGlobalButtonMute = @"OEGlobalButtonMute"; -NSString *const OEGlobalButtonVolumeDown = @"OEGlobalButtonVolumeDown"; -NSString *const OEGlobalButtonVolumeUp = @"OEGlobalButtonVolumeUp"; -NSString *const OEGlobalButtonStop = @"OEGlobalButtonStop"; -NSString *const OEGlobalButtonReset = @"OEGlobalButtonReset"; -NSString *const OEGlobalButtonPause = @"OEGlobalButtonPause"; -NSString *const OEGlobalButtonRewind = @"OEGlobalButtonRewind"; -NSString *const OEGlobalButtonFastForward = @"OEGlobalButtonFastForward"; -NSString *const OEGlobalButtonSlowMotion = @"OEGlobalButtonSlowMotion"; -NSString *const OEGlobalButtonStepFrameBackward = @"OEGlobalButtonStepFrameBackward"; -NSString *const OEGlobalButtonStepFrameForward = @"OEGlobalButtonStepFrameForward"; -NSString *const OEGlobalButtonNextDisplayMode = @"OEGlobalButtonNextDisplayMode"; -NSString *const OEGlobalButtonLastDisplayMode = @"OEGlobalButtonLastDisplayMode"; -NSString *const OEGlobalButtonScreenshot = @"OEGlobalButtonScreenshot"; -NSString *const OEGlobalButtonRapidFireToggle = @"OEGlobalButtonRapidFireToggle"; -NSString *const OEGlobalButtonRapidFireClear = @"OEGlobalButtonRapidFireClear"; -NSString *const OEGlobalButtonRapidFireReset = @"OEGlobalButtonRapidFireReset"; +NSString *const OEGlobalButtonSaveState = @"OEGlobalButtonSaveState"; +NSString *const OEGlobalButtonLoadState = @"OEGlobalButtonLoadState"; +NSString *const OEGlobalButtonQuickSave = @"OEGlobalButtonQuickSave"; +NSString *const OEGlobalButtonQuickLoad = @"OEGlobalButtonQuickLoad"; +NSString *const OEGlobalButtonFullScreen = @"OEGlobalButtonFullScreen"; +NSString *const OEGlobalButtonMute = @"OEGlobalButtonMute"; +NSString *const OEGlobalButtonVolumeDown = @"OEGlobalButtonVolumeDown"; +NSString *const OEGlobalButtonVolumeUp = @"OEGlobalButtonVolumeUp"; +NSString *const OEGlobalButtonStop = @"OEGlobalButtonStop"; +NSString *const OEGlobalButtonReset = @"OEGlobalButtonReset"; +NSString *const OEGlobalButtonPause = @"OEGlobalButtonPause"; +NSString *const OEGlobalButtonRewind = @"OEGlobalButtonRewind"; +NSString *const OEGlobalButtonFastForward = @"OEGlobalButtonFastForward"; +NSString *const OEGlobalButtonIncreaseGameSpeed = @"OEGlobalButtonIncreaseGameSpeed"; +NSString *const OEGlobalButtonDecreaseGameSpeed = @"OEGlobalButtonDecreaseGameSpeed"; +NSString *const OEGlobalButtonSlowMotion = @"OEGlobalButtonSlowMotion"; +NSString *const OEGlobalButtonStepFrameBackward = @"OEGlobalButtonStepFrameBackward"; +NSString *const OEGlobalButtonStepFrameForward = @"OEGlobalButtonStepFrameForward"; +NSString *const OEGlobalButtonNextDisplayMode = @"OEGlobalButtonNextDisplayMode"; +NSString *const OEGlobalButtonLastDisplayMode = @"OEGlobalButtonLastDisplayMode"; +NSString *const OEGlobalButtonScreenshot = @"OEGlobalButtonScreenshot"; +NSString *const OEGlobalButtonRapidFireToggle = @"OEGlobalButtonRapidFireToggle"; +NSString *const OEGlobalButtonRapidFireClear = @"OEGlobalButtonRapidFireClear"; +NSString *const OEGlobalButtonRapidFireReset = @"OEGlobalButtonRapidFireReset"; @interface OEHIDEvent () - (OEHIDEvent *)OE_eventWithDeviceHandler:(OEDeviceHandler *)aDeviceHandler; diff --git a/OpenEmuSystem/OESystemController.m b/OpenEmuSystem/OESystemController.m index 6c6dc03..f4cf6c6 100644 --- a/OpenEmuSystem/OESystemController.m +++ b/OpenEmuSystem/OESystemController.m @@ -223,6 +223,8 @@ - (NSString *)serialLookupForFile:(__kindof OEFile *)file Button(@"Pause", @"Name of the global button to pause the emulation", OEGlobalButtonPause), Button(@"Rewind", @"Name of the global button to rewind the emulation", OEGlobalButtonRewind), Button(@"Fast Forward", @"Name of the global button to fast foward the emulation", OEGlobalButtonFastForward), + Button(@"Increase Game Speed", @"Name of the global button to increase the emulation speed", OEGlobalButtonIncreaseGameSpeed), + Button(@"Decrease Game Speed", @"Name of the global button to decrease the emulation speed", OEGlobalButtonDecreaseGameSpeed), //Button(@"Slow Motion", @"Name of the global button to run the emulation in slow motion", OEGlobalButtonSlowMotion), Button(@"Step Backward", @"Name of the global button to step the emulation backward by one frame", OEGlobalButtonStepFrameBackward), Button(@"Step Forward", @"Name of the global button to step the emulation forward by one frame", OEGlobalButtonStepFrameForward), @@ -239,6 +241,8 @@ - (NSString *)serialLookupForFile:(__kindof OEFile *)file Button(@"Pause", @"Name of the global button to pause the emulation", OEGlobalButtonPause), Button(@"Rewind", @"Name of the global button to rewind the emulation", OEGlobalButtonRewind), Button(@"Fast Forward", @"Name of the global button to fast foward the emulation", OEGlobalButtonFastForward), + Button(@"Increase Game Speed", @"Name of the global button to increase the emulation speed", OEGlobalButtonIncreaseGameSpeed), + Button(@"Decrease Game Speed", @"Name of the global button to decrease the emulation speeed", OEGlobalButtonDecreaseGameSpeed), Button(@"Step Backward", @"Name of the global button to step the emulation backward by one frame", OEGlobalButtonStepFrameBackward), Button(@"Step Forward", @"Name of the global button to step the emulation forward by one frame", OEGlobalButtonStepFrameForward), Button(@"Next Display Mode", @"Name of the global button to switch to the next display mode", OEGlobalButtonNextDisplayMode), diff --git a/OpenEmuSystem/OESystemResponder.h b/OpenEmuSystem/OESystemResponder.h index db61f76..51f2540 100644 --- a/OpenEmuSystem/OESystemResponder.h +++ b/OpenEmuSystem/OESystemResponder.h @@ -85,6 +85,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)toggleEmulationPaused:(id)sender; - (void)takeScreenshot:(id)sender; - (void)fastForwardGameplay:(BOOL)enable; +- (void)increaseGameSpeed:(id)sender; +- (void)decreaseGameSpeed:(id)sender; - (void)rewindGameplay:(BOOL)enable; - (void)stepGameplayFrameForward:(id)sender; - (void)stepGameplayFrameBackward:(id)sender; diff --git a/OpenEmuSystem/OESystemResponder.mm b/OpenEmuSystem/OESystemResponder.mm index b15db8a..f3e9f85 100644 --- a/OpenEmuSystem/OESystemResponder.mm +++ b/OpenEmuSystem/OESystemResponder.mm @@ -481,6 +481,12 @@ - (void)pressGlobalButtonWithIdentifier:(OEGlobalButtonIdentifier)identifier pla SEND_ACTION2(fastForwardGameplay:, YES); [[self client] fastForward:YES]; return; + case OEGlobalButtonIdentifierIncreaseGameSpeed : + [[self client] increaseGameSpeed]; + return; + case OEGlobalButtonIdentifierDecreaseGameSpeed : + [[self client] decreaseGameSpeed]; + return; case OEGlobalButtonIdentifierRewind : SEND_ACTION2(rewindGameplay:, YES); [[self client] rewind:YES]; @@ -550,6 +556,10 @@ - (void)releaseGlobalButtonWithIdentifier:(OEGlobalButtonIdentifier)identifier p SEND_ACTION2(fastForwardGameplay:, NO); [[self client] fastForward:NO]; return; + case OEGlobalButtonIdentifierIncreaseGameSpeed : + return; + case OEGlobalButtonIdentifierDecreaseGameSpeed : + return; case OEGlobalButtonIdentifierRewind : SEND_ACTION2(rewindGameplay:, NO); [[self client] rewind:NO]; @@ -599,6 +609,8 @@ - (void)changeAnalogGlobalButtonIdentifier:(OEGlobalButtonIdentifier)identifier return; case OEGlobalButtonIdentifierFastForward : + case OEGlobalButtonIdentifierIncreaseGameSpeed : + case OEGlobalButtonIdentifierDecreaseGameSpeed : case OEGlobalButtonIdentifierRewind : case OEGlobalButtonIdentifierSaveState : case OEGlobalButtonIdentifierLoadState :