1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00

Softens swings in emulated machine speed.

This commit is contained in:
Thomas Harte 2020-02-09 16:34:13 -05:00
parent b5d6126a2d
commit 2ea1e059a8

View File

@ -158,6 +158,7 @@ struct ActivityObserver: public Activity::Observer {
int64_t _timeDiff; int64_t _timeDiff;
double _refreshPeriod; double _refreshPeriod;
BOOL _isSyncLocking; BOOL _isSyncLocking;
double _speedMultiplier;
NSTimer *_joystickTimer; NSTimer *_joystickTimer;
@ -168,6 +169,7 @@ struct ActivityObserver: public Activity::Observer {
self = [super init]; self = [super init];
if(self) { if(self) {
_analyser = result; _analyser = result;
_speedMultiplier = 1.0;
Machine::Error error; Machine::Error error;
std::vector<ROMMachine::ROM> missing_roms; std::vector<ROMMachine::ROM> missing_roms;
@ -802,11 +804,12 @@ struct ActivityObserver: public Activity::Observer {
// So the set speed multiplier may be adjusted slightly to aim for that. // So the set speed multiplier may be adjusted slightly to aim for that.
double speed_multiplier = 1.0 / ratio; double speed_multiplier = 1.0 / ratio;
if(scan_status.current_position > 0.0) { if(scan_status.current_position > 0.0) {
constexpr double adjustmentRatio = 1.01; constexpr double adjustmentRatio = 1.005;
if(scan_status.current_position < 0.5) speed_multiplier /= adjustmentRatio; if(scan_status.current_position < 0.5) speed_multiplier /= adjustmentRatio;
else speed_multiplier *= adjustmentRatio; else speed_multiplier *= adjustmentRatio;
} }
self->_machine->crt_machine()->set_speed_multiplier(speed_multiplier); self->_speedMultiplier = (self->_speedMultiplier * 0.95) + (speed_multiplier * 0.05);
self->_machine->crt_machine()->set_speed_multiplier(self->_speedMultiplier);
self->_machine->crt_machine()->run_for((double)(timeNow - self->_syncTime) / 1e9); self->_machine->crt_machine()->run_for((double)(timeNow - self->_syncTime) / 1e9);
} }
} }