Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeFence: cleanup sync #297

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions src/cpuexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -963,31 +963,28 @@ static void cpu_timeslice(void)
// NOTE: if debugging stutter issues or the like, disable this mechanism in the core scripts, or directly here
if (options.time_fence != 0.0 && time_fence_is_supported())
{
static int running = 1;
const double now = timer_get_time();
if (now - options.time_fence - time_fence_global_offset >= 0.)
{
int waitForMasterClock = 1;
// We are ahead by a large amount: realign external clock
if (now - options.time_fence - time_fence_global_offset >= 1.0)
{
time_fence_global_offset = now - options.time_fence;
// Wait for a new time fence value to arrive OR when a screen update would be needed
// When emulation is known as running, we delay forced screen update quite a lot to gracefully handle stutters from master clock
else if (time_fence_wait(running ? 0.5 : (1.0 / 60.0)))
waitForMasterClock = 0;
}
// Wait for a new time fence that would unpause us to arrive
else if (time_fence_wait(1.0 / 120.0) && (now - options.time_fence - time_fence_global_offset < 0.))
{
running = 1; // We received a new time fence, so master clock is running
// exit if we are still ahead of the master clock
if (now - options.time_fence - time_fence_global_offset >= 0.)
return;
waitForMasterClock = 0;
}
else
if (waitForMasterClock)
{
// We waited, but no new time fence value arrived, so master clock seems to be paused: emulation must not be updated
// but we still need to process screen (normally, this would be called by CPU VBlank callback if the emulation was
// not stalled, the code here is derived from how pause is handled in usrintf.c / handle_user_interface())
running = 0;
draw_screen();
update_video_and_audio();
reset_partial_updates();
#if defined(VPINMAME) && (defined(_WIN32) || defined(_WIN64))
// COM component must always pump its message loop
extern void win_process_events_periodic(void);
win_process_events_periodic();
#endif
return;
}
}
Expand Down
Loading