From ba8656e3457a0ecbabdb06ecd4b3a0be00036f28 Mon Sep 17 00:00:00 2001
From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com>
Date: Thu, 3 Aug 2023 21:02:52 -0700
Subject: [PATCH] slight tastudio tweaks wrt
12830bab4e0b20a37f1d3d42fb63e3cf36c676ad
---
.../movie/tasproj/TasMovie.cs | 2 +-
.../movie/tasproj/ZwinderStateManager.cs | 12 ++---
.../tools/TAStudio/BookmarksBranchesBox.cs | 51 +++++++++----------
3 files changed, 31 insertions(+), 34 deletions(-)
diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs
index 6f1be955dc..8f591884ed 100644
--- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs
+++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs
@@ -196,7 +196,7 @@ namespace BizHawk.Client.Common
LagLog[Emulator.Frame] = _inputPollable.IsLagFrame;
// We will forbibly capture a state for the last edited frame (requested by #916 for case of "platforms with analog stick")
- TasStateManager.Capture(Emulator.Frame, Emulator.AsStatable(), !Emulator.AsStatable().AvoidRewind && Emulator.Frame == LastEditedFrame - 1);
+ TasStateManager.Capture(Emulator.Frame, Emulator.AsStatable(), Emulator.Frame == LastEditedFrame - 1);
}
diff --git a/src/BizHawk.Client.Common/movie/tasproj/ZwinderStateManager.cs b/src/BizHawk.Client.Common/movie/tasproj/ZwinderStateManager.cs
index 66d954a49c..9baa2b97b2 100644
--- a/src/BizHawk.Client.Common/movie/tasproj/ZwinderStateManager.cs
+++ b/src/BizHawk.Client.Common/movie/tasproj/ZwinderStateManager.cs
@@ -327,6 +327,12 @@ namespace BizHawk.Client.Common
return;
}
+ // avoid capturing in this case
+ if (source.AvoidRewind)
+ {
+ return;
+ }
+
// We use the gap buffer for forced capture to avoid crowding the "current" buffer and thus reducing it's actual span of covered frames.
if (NeedsGap(frame) || force)
{
@@ -334,12 +340,6 @@ namespace BizHawk.Client.Common
return;
}
- // avoid capturing in this case
- if (source.AvoidRewind)
- {
- return;
- }
-
_current.Capture(frame,
s =>
{
diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs
index 68d055931f..7c44d6bc6d 100644
--- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs
@@ -152,6 +152,24 @@ namespace BizHawk.Client.EmuHawk
}
}
+ // used to capture a reserved state immediately on branch creation
+ // while also not doing a double state
+ private class BufferedStatable : IStatable
+ {
+ private readonly byte[] _bufferedState;
+
+ public BufferedStatable(byte[] state)
+ => _bufferedState = state;
+
+ public bool AvoidRewind => true;
+
+ public void SaveStateBinary(BinaryWriter writer)
+ => writer.Write(_bufferedState);
+
+ public void LoadStateBinary(BinaryReader reader)
+ => throw new NotImplementedException();
+ }
+
///
/// Add a new branch.
///
@@ -163,6 +181,7 @@ namespace BizHawk.Client.EmuHawk
BranchView.RowCount = Branches.Count;
Branches.Current = Branches.Count - 1;
Movie.TasSession.UpdateValues(Tastudio.Emulator.Frame, Branches.Current);
+ Movie.TasStateManager.Capture(Tastudio.Emulator.Frame, new BufferedStatable(branch.CoreData));
BranchView.ScrollToIndex(Branches.Current);
BranchView.DeselectAll();
Select(Branches.Current, true);
@@ -174,36 +193,12 @@ namespace BizHawk.Client.EmuHawk
public TasBranch SelectedBranch
=> BranchView.AnyRowsSelected ? Branches[BranchView.FirstSelectedRowIndex] : null;
- // to avoid a double (potentially slow) state
- private class BufferedStatable : IStatable
- {
- private readonly Lazy _bufferedState;
- public byte[] BufferedState => _bufferedState.Value;
-
- public BufferedStatable(IStatable statable)
- {
- _bufferedState = new(statable.CloneSavestate);
- AvoidRewind = statable.AvoidRewind;
- }
-
- public bool AvoidRewind { get; }
-
- public void SaveStateBinary(BinaryWriter writer)
- => writer.Write(BufferedState);
-
- public void LoadStateBinary(BinaryReader reader)
- => throw new NotImplementedException();
- }
-
private TasBranch CreateBranch()
{
- var bufferedStatable = new BufferedStatable(Tastudio.Emulator.AsStatable());
- Movie.TasStateManager.Capture(Tastudio.Emulator.Frame, bufferedStatable, bufferedStatable.AvoidRewind);
-
return new()
{
Frame = Tastudio.Emulator.Frame,
- CoreData = bufferedStatable.BufferedState,
+ CoreData = Tastudio.Emulator.AsStatable().CloneSavestate(),
InputLog = Movie.GetLogEntries().Clone(),
CoreFrameBuffer = MainForm.MakeScreenshotImage(),
OSDFrameBuffer = MainForm.CaptureOSD(),
@@ -224,7 +219,7 @@ namespace BizHawk.Client.EmuHawk
Movie.LoadBranch(branch);
Tastudio.LoadState(new(branch.Frame, new MemoryStream(branch.CoreData, false)));
- Movie.TasStateManager.Capture(Tastudio.Emulator.Frame, Tastudio.Emulator.AsStatable(), Tastudio.Emulator.AsStatable().AvoidRewind);
+ Movie.TasStateManager.Capture(Tastudio.Emulator.Frame, Tastudio.Emulator.AsStatable());
Tastudio.MainForm.QuickBmpFile.Copy(new BitmapBufferVideoProvider(branch.CoreFrameBuffer), Tastudio.VideoProvider);
if (Tastudio.Settings.OldControlSchemeForBranches && Tastudio.TasPlaybackBox.RecordingMode)
@@ -312,7 +307,9 @@ namespace BizHawk.Client.EmuHawk
_branchUndo = BranchUndo.Update;
BranchView.ScrollToIndex(Branches.Current);
- Branches.Replace(SelectedBranch, CreateBranch());
+ var branch = CreateBranch();
+ Branches.Replace(SelectedBranch, branch);
+ Movie.TasStateManager.Capture(Tastudio.Emulator.Frame, new BufferedStatable(branch.CoreData));
Tastudio.RefreshDialog();
SavedCallback?.Invoke(Branches.Current);
Tastudio.MainForm.AddOnScreenMessage($"Saved branch {Branches.Current + 1}");