Skip to content

Commit 7c5432c

Browse files
committed
Make consecutive recorded frames while unpaused be a single undo action.
1 parent 08aede3 commit 7c5432c

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

src/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public interface IMovieChangeLog
2828
/// If not already recording a batch, does nothing.
2929
/// </summary>
3030
void EndBatch();
31+
32+
/// <summary>
33+
/// Combine the last two undo actions, making them part of one batch action.
34+
/// </summary>
35+
void MergeLastActions();
36+
3137
/// <summary>
3238
/// Undoes the most recent action batch, if any exist.
3339
/// </summary>
@@ -178,6 +184,17 @@ public void EndBatch()
178184
}
179185
}
180186

187+
public void MergeLastActions()
188+
{
189+
Debug.Assert(UndoIndex + 1 == _history.Count, "Don't merge the last actions if they aren't the last actions.");
190+
Debug.Assert(_history.Count > 1, "Don't merge when there aren't actions to merge.");
191+
192+
_history[_history.Count - 2].AddRange(_history[_history.Count - 1]);
193+
_history.RemoveAt(_history.Count - 1);
194+
Names.RemoveAt(Names.Count - 1);
195+
UndoIndex--;
196+
}
197+
181198
public void Undo()
182199
{
183200
if (UndoIndex == -1)

src/BizHawk.Client.EmuHawk/MainForm.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ private set
10451045
InitializeFpsData();
10461046
}
10471047

1048+
if (value != _emulatorPaused) Tools.OnPauseToggle(value);
10481049
_emulatorPaused = value;
10491050
}
10501051
}

src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public partial class TAStudio : IToolForm
2121

2222
private int _lastRefresh;
2323
private bool _doPause;
24+
private bool _extended;
25+
private bool _extendNeedsMerge;
2426

2527
private void UpdateProgressBar()
2628
{
@@ -55,7 +57,8 @@ private void UpdateProgressBar()
5557

5658
protected override void UpdateBefore()
5759
{
58-
if (CurrentTasMovie.IsAtEnd() && !CurrentTasMovie.IsRecording())
60+
_extended = CurrentTasMovie.IsAtEnd() && !CurrentTasMovie.IsRecording();
61+
if (_extended)
5962
{
6063
CurrentTasMovie.RecordFrame(CurrentTasMovie.Emulator.Frame, MovieSession.StickySource);
6164
}
@@ -108,6 +111,18 @@ protected override void UpdateAfter()
108111

109112
protected override void FastUpdateAfter()
110113
{
114+
// Recording multiple frames, or auto-extending the movie, while unpaused should count as a single undo action.
115+
// And do this before stopping the seek, which could puase.
116+
if (!MainForm.EmulatorPaused && (CurrentTasMovie.IsRecording() || _extended))
117+
{
118+
if (_extendNeedsMerge) CurrentTasMovie.ChangeLog.MergeLastActions();
119+
_extendNeedsMerge = true;
120+
}
121+
else
122+
{
123+
_extendNeedsMerge = false;
124+
}
125+
111126
if (_seekingTo != -1 && Emulator.Frame >= _seekingTo)
112127
{
113128
StopSeeking();

src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,13 @@ public void TogglePause()
890890
MainForm.TogglePause();
891891
}
892892

893+
public override void OnPauseToggle(bool newPauseState)
894+
{
895+
// Consecutively recorded frames are merged into one undo action, until we pause.
896+
// Then a new undo action should be used.
897+
if (newPauseState) _extendNeedsMerge = false;
898+
}
899+
893900
private void SetSplicer()
894901
{
895902
// TODO: columns selected?

src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,7 @@ protected override void OnLoad(EventArgs e)
136136
}
137137

138138
public virtual void HandleHotkeyUpdate() { }
139+
140+
public virtual void OnPauseToggle(bool newPauseState) { }
139141
}
140142
}

src/BizHawk.Client.EmuHawk/tools/ToolManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,17 @@ public void HandleHotkeyUpdate()
804804
}
805805
}
806806

807+
public void OnPauseToggle(bool newPauseState)
808+
{
809+
foreach (var tool in _tools)
810+
{
811+
if (tool.IsActive && tool is ToolFormBase toolForm)
812+
{
813+
toolForm.OnPauseToggle(newPauseState);
814+
}
815+
}
816+
}
817+
807818
private static readonly IList<string> PossibleToolTypeNames = EmuHawk.ReflectionCache.Types.Select(t => t.AssemblyQualifiedName).ToList();
808819

809820
public bool IsAvailable(Type tool)

0 commit comments

Comments
 (0)