From 7cc73ca9b08ff57640a77018e9ce8268aeb4a68c Mon Sep 17 00:00:00 2001 From: nattthebear Date: Tue, 20 Jul 2021 16:47:10 -0400 Subject: [PATCH] Fix bug with delta state rewinder (#2871) --- .../rewind/ZeldaWinder.cs | 4 ++-- .../rewind/ZwinderBuffer.cs | 24 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/BizHawk.Client.Common/rewind/ZeldaWinder.cs b/src/BizHawk.Client.Common/rewind/ZeldaWinder.cs index 3e4dc401b4..56f194fdd7 100644 --- a/src/BizHawk.Client.Common/rewind/ZeldaWinder.cs +++ b/src/BizHawk.Client.Common/rewind/ZeldaWinder.cs @@ -106,7 +106,7 @@ namespace BizHawk.Client.Common _count++; return; } - if (!_buffer.WillCapture(_masterFrame)) + if (!_buffer.WouldCapture(frame - _masterFrame)) return; { @@ -189,7 +189,7 @@ namespace BizHawk.Client.Common _masterLength = (int)sss.Position; _masterFrame = frame; _count++; - }); + }, force: true); }); } } diff --git a/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs b/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs index 710e2cd2d2..e7780e13e3 100644 --- a/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs +++ b/src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs @@ -148,31 +148,35 @@ namespace BizHawk.Client.Common _backingStoreType == settings.BackingStore; } - private bool ShouldCapture(int frame) + private bool ShouldCaptureForFrameDiff(int frameDiff) { if (Count == 0) { return true; } - - var frameDiff = frame - _states[HeadStateIndex].Frame; if (frameDiff < 1) + { // non-linear time is from a combination of other state changing mechanisms and the rewinder // not much we can say here, so just take a state return true; + } + return frameDiff >= ComputeIdealRewindInterval(); + } - return frameDiff >= ComputeIdealRewindInterval(); + private bool ShouldCapture(int frame) + { + var frameDiff = frame - _states[HeadStateIndex].Frame; + return ShouldCaptureForFrameDiff(frameDiff); } /// - /// Predict whether Capture() will capture a state. Useful if expensive work needs to happen before - /// Capture() is called. + /// Predict whether Capture() would capture a state, assuming a particular frame delta. /// - /// The same frame number to be passed to capture - /// Whether capture will happen, assuming Capture() is passed the same frame and force = false - public bool WillCapture(int frame) + /// The assumed frame delta. Normally this will be equal to `nextStateFrame - GetState(Count - 1).Frame`. + /// Whether Capture(nextStateFrame) would actually capture, assuming the frameDelta matched. + public bool WouldCapture(int frameDelta) { - return ShouldCapture(frame); + return ShouldCaptureForFrameDiff(frameDelta); } ///