Clamp `SpectatorPlayerClock`'s elapsed calculation to avoid player clocks getting too far ahead

This commit is contained in:
Dean Herbert 2022-08-25 21:33:33 +09:00
parent a8c699610a
commit a546aa2673
1 changed files with 2 additions and 1 deletions

View File

@ -80,7 +80,8 @@ public void ProcessFrame()
// When in catch-up mode, the source is usually not running.
// In such a case, its elapsed time may be zero, which would cause catch-up to get stuck.
// To avoid this, use a constant 16ms elapsed time for now. Probably not too correct, but this whole logic isn't too correct anyway.
double elapsedSource = masterClock.ElapsedFrameTime != 0 ? masterClock.ElapsedFrameTime : 16;
// Clamping is required to ensure that player clocks don't get too far ahead if ProcessFrame is run multiple times.
double elapsedSource = masterClock.ElapsedFrameTime != 0 ? masterClock.ElapsedFrameTime : Math.Clamp(masterClock.CurrentTime - CurrentTime, 0, 16);
double elapsed = elapsedSource * Rate;
CurrentTime += elapsed;