mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-29 20:31:46 +00:00
Merge pull request #750 from TomHarte/CatchupCap
Avoids trying to paper over huge gaps in running time.
This commit is contained in:
commit
5f661adb7f
@ -767,10 +767,14 @@ struct ActivityObserver: public Activity::Observer {
|
|||||||
__block auto lastTime = Time::nanos_now();
|
__block auto lastTime = Time::nanos_now();
|
||||||
|
|
||||||
_timer = [[CSHighPrecisionTimer alloc] initWithTask:^{
|
_timer = [[CSHighPrecisionTimer alloc] initWithTask:^{
|
||||||
// Grab the time now and, therefore, the amount of time since the timer last fired.
|
// Grab the time now and, therefore, the amount of time since the timer last fired
|
||||||
|
// (capped at half a second).
|
||||||
const auto timeNow = Time::nanos_now();
|
const auto timeNow = Time::nanos_now();
|
||||||
const auto duration = timeNow - lastTime;
|
const auto duration = timeNow - lastTime;
|
||||||
|
if(duration > Time::Nanos(500'000'000)) {
|
||||||
|
lastTime = timeNow;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CGSize pixelSize;
|
CGSize pixelSize;
|
||||||
BOOL splitAndSync = NO;
|
BOOL splitAndSync = NO;
|
||||||
|
@ -51,6 +51,14 @@ struct MachineRunner {
|
|||||||
|
|
||||||
void stop() {
|
void stop() {
|
||||||
if(timer_) {
|
if(timer_) {
|
||||||
|
// SDL doesn't define whether SDL_RemoveTimer will block until any pending calls
|
||||||
|
// have been completed, or will return instantly. So: do an ordered shutdown,
|
||||||
|
// then remove the timer.
|
||||||
|
state_ = State::Stopping;
|
||||||
|
while(state_ == State::Stopping) {
|
||||||
|
frame_lock_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
SDL_RemoveTimer(timer_);
|
SDL_RemoveTimer(timer_);
|
||||||
timer_ = 0;
|
timer_ = 0;
|
||||||
}
|
}
|
||||||
@ -87,6 +95,13 @@ struct MachineRunner {
|
|||||||
std::atomic<Time::Nanos> vsync_time_;
|
std::atomic<Time::Nanos> vsync_time_;
|
||||||
std::atomic_flag frame_lock_;
|
std::atomic_flag frame_lock_;
|
||||||
|
|
||||||
|
enum class State {
|
||||||
|
Running,
|
||||||
|
Stopping,
|
||||||
|
Stopped
|
||||||
|
};
|
||||||
|
std::atomic<State> state_ = State::Running;
|
||||||
|
|
||||||
Time::ScanSynchroniser scan_synchroniser_;
|
Time::ScanSynchroniser scan_synchroniser_;
|
||||||
|
|
||||||
// A slightly clumsy means of trying to derive frame rate from calls to
|
// A slightly clumsy means of trying to derive frame rate from calls to
|
||||||
@ -105,7 +120,21 @@ struct MachineRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update() {
|
void update() {
|
||||||
|
// If a shutdown is in progress, signal stoppage and do nothing.
|
||||||
|
if(state_ != State::Running) {
|
||||||
|
state_ = State::Stopped;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get time now and determine how long it has been since the last time this
|
||||||
|
// function was called. If it's more than half a second then forego any activity
|
||||||
|
// now, as there's obviously been some sort of substantial time glitch.
|
||||||
const auto time_now = Time::nanos_now();
|
const auto time_now = Time::nanos_now();
|
||||||
|
if(time_now - last_time_ > Time::Nanos(500'000'000)) {
|
||||||
|
last_time_ = time_now;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto vsync_time = vsync_time_.load();
|
const auto vsync_time = vsync_time_.load();
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock_guard(*machine_mutex);
|
std::unique_lock<std::mutex> lock_guard(*machine_mutex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user