Cocoa Port: Add the ability for the user to set a fixed frame skip value, just like in the Windows port. This is in addition to the existing automatic frame skip setting.

This commit is contained in:
rogerman 2021-08-31 13:56:07 -07:00
parent 67fa412144
commit 0df858f2e8
11 changed files with 89105 additions and 91318 deletions

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2017-2018 DeSmuME team
Copyright (C) 2017-2021 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -99,6 +99,7 @@ ClientExecutionControl::ClientExecutionControl()
_settingsPending.executionSpeed = SPEED_SCALAR_NORMAL;
_settingsPending.enableFrameSkip = true;
_settingsPending.framesToSkipSetting = 0; // A value of 0 is interpreted as 'automatic'.
_settingsPending.frameJumpRelativeTarget = 60;
_settingsPending.frameJumpTarget = 60;
@ -744,6 +745,29 @@ void ClientExecutionControl::ResetFramesToSkip()
pthread_mutex_unlock(&this->_mutexSettingsPendingOnNDSExec);
}
uint8_t ClientExecutionControl::GetFramesToSkipSetting()
{
pthread_mutex_lock(&this->_mutexSettingsPendingOnExecutionLoopStart);
const uint8_t framesToSkipSetting = this->_settingsPending.framesToSkipSetting;
pthread_mutex_unlock(&this->_mutexSettingsPendingOnExecutionLoopStart);
return framesToSkipSetting;
}
uint8_t ClientExecutionControl::GetFramesToSkipSettingApplied()
{
return this->_settingsApplied.framesToSkipSetting;
}
void ClientExecutionControl::SetFramesToSkipSetting(uint8_t numFrames)
{
pthread_mutex_lock(&this->_mutexSettingsPendingOnExecutionLoopStart);
this->_settingsPending.framesToSkipSetting = numFrames;
this->_newSettingsPendingOnExecutionLoopStart = true;
pthread_mutex_unlock(&this->_mutexSettingsPendingOnExecutionLoopStart);
}
uint64_t ClientExecutionControl::GetFrameJumpRelativeTarget()
{
pthread_mutex_lock(&this->_mutexSettingsPendingOnExecutionLoopStart);
@ -1068,6 +1092,7 @@ void ClientExecutionControl::ApplySettingsOnExecutionLoopStart()
const double speedScalar = (this->_settingsPending.executionSpeed > SPEED_SCALAR_MIN) ? this->_settingsPending.executionSpeed : SPEED_SCALAR_MIN;
this->_settingsApplied.enableExecutionSpeedLimiter = this->_settingsPending.enableExecutionSpeedLimiter;
this->_settingsApplied.executionSpeed = speedScalar;
this->_settingsApplied.framesToSkipSetting = this->_settingsPending.framesToSkipSetting;
this->_settingsApplied.jumpBehavior = this->_settingsPending.jumpBehavior;
this->_settingsApplied.frameJumpRelativeTarget = this->_settingsPending.frameJumpRelativeTarget;

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2017-2018 DeSmuME team
Copyright (C) 2017-2021 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -106,6 +106,7 @@ struct ClientExecutionControlSettings
double executionSpeed;
bool enableFrameSkip;
uint8_t framesToSkipSetting;
uint64_t frameJumpRelativeTarget;
uint64_t frameJumpTarget;
@ -337,6 +338,10 @@ public:
void SetFramesToSkip(uint8_t numFrames);
void ResetFramesToSkip();
uint8_t GetFramesToSkipSetting();
uint8_t GetFramesToSkipSettingApplied();
void SetFramesToSkipSetting(uint8_t numFrames);
uint64_t GetFrameJumpRelativeTarget();
void SetFrameJumpRelativeTarget(uint64_t newRelativeTarget);

View File

@ -6,6 +6,8 @@
<true/>
<key>CoreControl_EnableAutoFrameSkip</key>
<true/>
<key>CoreControl_FramesToSkipSetting</key>
<integer>0</integer>
<key>CoreControl_EnableCheats</key>
<true/>
<key>CoreControl_EnableSpeedLimit</key>

View File

@ -78,6 +78,7 @@ typedef struct
@property (assign) BOOL masterExecute;
@property (assign) BOOL isFrameSkipEnabled;
@property (assign) NSInteger framesToSkipSetting;
@property (assign) NSInteger coreState;
@property (assign) BOOL emulationPaused;

View File

@ -51,6 +51,7 @@ volatile bool execute = true;
@dynamic masterExecute;
@dynamic isFrameSkipEnabled;
@dynamic framesToSkipSetting;
@dynamic coreState;
@dynamic emulationPaused;
@dynamic isSpeedLimitEnabled;
@ -283,6 +284,25 @@ volatile bool execute = true;
return (enable) ? YES : NO;
}
- (void) setFramesToSkipSetting:(NSInteger)framesToSkip
{
if (framesToSkip < 0)
{
framesToSkip = 0; // Actual frame skip values can't be negative.
}
else if (framesToSkip > MAX_FIXED_FRAMESKIP_VALUE)
{
framesToSkip = MAX_FIXED_FRAMESKIP_VALUE;
}
execControl->SetFramesToSkipSetting((uint8_t)framesToSkip);
}
- (NSInteger) framesToSkipSetting
{
return (NSInteger)execControl->GetFramesToSkipSetting();
}
- (void) setSpeedScalar:(CGFloat)scalar
{
execControl->SetExecutionSpeed((float)scalar);
@ -1358,10 +1378,18 @@ static void* RunCoreThread(void *arg)
execControl->SetFramesToSkip(framesToSkip - 1);
}
else
{
const uint8_t framesToSkipSetting = execControl->GetFramesToSkipSettingApplied();
if (framesToSkipSetting == 0) // A value of 0 is interpreted as 'automatic'.
{
const double frameTimeBias = (lastExecutionSpeedDifference > 0.0) ? 1.0 - lastExecutionSpeedDifference : 1.0;
execControl->SetFramesToSkip( execControl->CalculateFrameSkip(startTime, frameTime * frameTimeBias) );
}
else
{
execControl->SetFramesToSkip(framesToSkipSetting);
}
}
}
break;
}

View File

@ -1,6 +1,6 @@
/*
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012-2018 DeSmuME Team
Copyright (C) 2012-2021 DeSmuME Team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -183,6 +183,8 @@
#define MAX_VOLUME 100.0f
#define MAX_BRIGHTNESS 100.0f
#define MAX_FIXED_FRAMESKIP_VALUE 255
#define CHEAT_DESCRIPTION_LENGTH 1024
#define WINDOW_STATUS_BAR_HEIGHT 24 // Height of an emulation window status bar in pixels.

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2018 DeSmuME Team
Copyright (C) 2013-2021 DeSmuME Team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -209,6 +209,7 @@ class AudioSampleBlockGenerator;
// Emulation Menu
- (IBAction) toggleSpeedLimiter:(id)sender;
- (IBAction) toggleAutoFrameSkip:(id)sender;
- (IBAction) framesToSkipSetting:(id)sender;
- (IBAction) toggleCheats:(id)sender;
- (IBAction) toggleExecutePause:(id)sender;
- (IBAction) coreExecute:(id)sender;

View File

@ -643,9 +643,9 @@
CocoaDSCore *cdsCore = (CocoaDSCore *)[cdsCoreController content];
NSURL *sramURL = [CocoaDSFile fileURLFromRomURL:[[self currentRom] fileURL] toKind:@"ROM Save"];
NSFileManager *fileManager = [[NSFileManager alloc] init];
const BOOL exists = [fileManager isReadableFileAtPath:[sramURL path]];
[fileManager release];
//NSFileManager *fileManager = [[NSFileManager alloc] init];
//const BOOL exists = [fileManager isReadableFileAtPath:[sramURL path]];
//[fileManager release];
const BOOL isMovieStarted = [cdsCore startReplayRecording:fileURL sramURL:sramURL];
[self setStatusText:(isMovieStarted) ? @"Replay recording started." : @"Replay creation failed!"];
@ -769,6 +769,12 @@
[inputManager dispatchCommandUsingIBAction:_cmd sender:sender];
}
- (IBAction) framesToSkipSetting:(id)sender
{
CocoaDSCore *cdsCore = (CocoaDSCore *)[cdsCoreController content];
[cdsCore setFramesToSkipSetting:[CocoaDSUtil getIBActionSenderTag:sender]];
}
- (IBAction) toggleGPUState:(id)sender
{
[inputManager dispatchCommandUsingIBAction:_cmd sender:sender];
@ -2896,6 +2902,13 @@
enable = NO;
}
}
else if (theAction == @selector(framesToSkipSetting:))
{
if ([(id)theItem isMemberOfClass:[NSMenuItem class]])
{
[(NSMenuItem*)theItem setState:([cdsCore framesToSkipSetting] == [theItem tag]) ? NSOnState : NSOffState];
}
}
else if (theAction == @selector(toggleCheats:))
{
if ([(id)theItem isMemberOfClass:[NSMenuItem class]])

View File

@ -395,6 +395,7 @@
[[NSUserDefaults standardUserDefaults] setDouble:[emuControl lastSetSpeedScalar] forKey:@"CoreControl_SpeedScalar"];
[[NSUserDefaults standardUserDefaults] setBool:[cdsCore isSpeedLimitEnabled] forKey:@"CoreControl_EnableSpeedLimit"];
[[NSUserDefaults standardUserDefaults] setBool:[cdsCore isFrameSkipEnabled] forKey:@"CoreControl_EnableAutoFrameSkip"];
[[NSUserDefaults standardUserDefaults] setInteger:[cdsCore framesToSkipSetting] forKey:@"CoreControl_FramesToSkipSetting"];
[[NSUserDefaults standardUserDefaults] setBool:[cdsCore isCheatingEnabled] forKey:@"CoreControl_EnableCheats"];
#ifdef GDB_STUB
@ -543,6 +544,7 @@
[emuControl changeCoreSpeedWithDouble:[[NSUserDefaults standardUserDefaults] doubleForKey:@"CoreControl_SpeedScalar"]];
[cdsCore setIsSpeedLimitEnabled:[[NSUserDefaults standardUserDefaults] boolForKey:@"CoreControl_EnableSpeedLimit"]];
[cdsCore setIsFrameSkipEnabled:[[NSUserDefaults standardUserDefaults] boolForKey:@"CoreControl_EnableAutoFrameSkip"]];
[cdsCore setFramesToSkipSetting:[[NSUserDefaults standardUserDefaults] integerForKey:@"CoreControl_FramesToSkipSetting"]];
[cdsCore setIsCheatingEnabled:[[NSUserDefaults standardUserDefaults] boolForKey:@"CoreControl_EnableCheats"]];
// Set up the firmware per user preferences.