slight tastudio tweaks wrt 12830bab4e

This commit is contained in:
CasualPokePlayer 2023-08-03 21:02:52 -07:00
parent 1ebc006873
commit ba8656e345
3 changed files with 31 additions and 34 deletions

View File

@ -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);
}

View File

@ -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 =>
{

View File

@ -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();
}
/// <summary>
/// Add a new branch.
/// </summary>
@ -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<byte[]> _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}");