Make the number of frames per TAStudio rewind configurable (squashed PR #4319)

* allow a TAStudio rewind to go back a configurable number of frames.

* rename FramesPerRewind to RewindStep.

* make whitespace consistent.

Use tabs for regular lines, but use spaces in argument lists that are formatted as one argument per line.

* remove tiny designer resizes.

* refactor isFastForwarding variables in main form.

* refactor isFastForwarding variables in main form, v2.

Copy IsFastForwarding into a local variable to minimize recalculations.

* add doc string to MainForm.IsFastForwarding.

* refactor if statement shape in TAStudio.MenuItems.cs .
This commit is contained in:
Daniel Peter Rutschmann 2025-06-09 23:45:27 -04:00 committed by GitHub
parent 95a01894de
commit 3ab4a96404
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 88 additions and 4 deletions

View File

@ -35,6 +35,9 @@ namespace BizHawk.Client.EmuHawk
/// <remarks>only referenced from <see cref="LuaConsole"/></remarks> /// <remarks>only referenced from <see cref="LuaConsole"/></remarks>
bool IsTurboing { get; } bool IsTurboing { get; }
/// <remarks>only referenced from <see cref="TAStudio"/></remarks>
bool IsFastForwarding { get; }
int? PauseOnFrame { get; set; } int? PauseOnFrame { get; set; }
/// <remarks>only referenced from <see cref="PlaybackBox"/></remarks> /// <remarks>only referenced from <see cref="PlaybackBox"/></remarks>

View File

@ -1101,6 +1101,7 @@ namespace BizHawk.Client.EmuHawk
public bool IsSeeking => PauseOnFrame.HasValue; public bool IsSeeking => PauseOnFrame.HasValue;
private bool IsTurboSeeking => PauseOnFrame.HasValue && Config.TurboSeek; private bool IsTurboSeeking => PauseOnFrame.HasValue && Config.TurboSeek;
public bool IsTurboing => InputManager.ClientControls["Turbo"] || IsTurboSeeking; public bool IsTurboing => InputManager.ClientControls["Turbo"] || IsTurboSeeking;
public bool IsFastForwarding => InputManager.ClientControls["Fast Forward"] || IsTurboing || InvisibleEmulation;
/// <summary> /// <summary>
/// Used to disable secondary throttling (e.g. vsync, audio) for unthrottled modes or when the primary (clock) throttle is taking over (e.g. during fast forward/rewind). /// Used to disable secondary throttling (e.g. vsync, audio) for unthrottled modes or when the primary (clock) throttle is taking over (e.g. during fast forward/rewind).
@ -3118,7 +3119,7 @@ namespace BizHawk.Client.EmuHawk
// BlockFrameAdvance (true when input it being editted in TAStudio) supercedes all other frame advance conditions // BlockFrameAdvance (true when input it being editted in TAStudio) supercedes all other frame advance conditions
if ((runFrame || force) && !BlockFrameAdvance) if ((runFrame || force) && !BlockFrameAdvance)
{ {
var isFastForwarding = InputManager.ClientControls["Fast Forward"] || IsTurboing || InvisibleEmulation; var isFastForwarding = IsFastForwarding;
var isFastForwardingOrRewinding = isFastForwarding || isRewinding || Config.Unthrottled; var isFastForwardingOrRewinding = isFastForwarding || isRewinding || Config.Unthrottled;
if (isFastForwardingOrRewinding != _lastFastForwardingOrRewinding) if (isFastForwardingOrRewinding != _lastFastForwardingOrRewinding)

View File

@ -81,6 +81,7 @@ namespace BizHawk.Client.EmuHawk
this.StateHistoryIntegrityCheckMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.StateHistoryIntegrityCheckMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.ConfigSubMenu = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.ConfigSubMenu = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.SetMaxUndoLevelsMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.SetMaxUndoLevelsMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.SetRewindStepFastMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.CopyIncludesFrameNoMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.CopyIncludesFrameNoMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.toolStripSeparator26 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx(); this.toolStripSeparator26 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx();
this.autosaveToolStripMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.autosaveToolStripMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
@ -190,6 +191,7 @@ namespace BizHawk.Client.EmuHawk
this.BranchesMarkersSplit = new System.Windows.Forms.SplitContainer(); this.BranchesMarkersSplit = new System.Windows.Forms.SplitContainer();
this.MainVertialSplit = new System.Windows.Forms.SplitContainer(); this.MainVertialSplit = new System.Windows.Forms.SplitContainer();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.SetRewindStepMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.TASMenu.SuspendLayout(); this.TASMenu.SuspendLayout();
this.TasStatusStrip.SuspendLayout(); this.TasStatusStrip.SuspendLayout();
this.RightClickMenu.SuspendLayout(); this.RightClickMenu.SuspendLayout();
@ -476,6 +478,8 @@ namespace BizHawk.Client.EmuHawk
// //
this.ConfigSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ConfigSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SetMaxUndoLevelsMenuItem, this.SetMaxUndoLevelsMenuItem,
this.SetRewindStepMenuItem,
this.SetRewindStepFastMenuItem,
this.CopyIncludesFrameNoMenuItem, this.CopyIncludesFrameNoMenuItem,
this.toolStripSeparator26, this.toolStripSeparator26,
this.autosaveToolStripMenuItem, this.autosaveToolStripMenuItem,
@ -503,6 +507,11 @@ namespace BizHawk.Client.EmuHawk
this.SetMaxUndoLevelsMenuItem.Text = "Set max Undo Levels"; this.SetMaxUndoLevelsMenuItem.Text = "Set max Undo Levels";
this.SetMaxUndoLevelsMenuItem.Click += new System.EventHandler(this.SetMaxUndoLevelsMenuItem_Click); this.SetMaxUndoLevelsMenuItem.Click += new System.EventHandler(this.SetMaxUndoLevelsMenuItem_Click);
// //
// SetRewindStepFastMenuItem
//
this.SetRewindStepFastMenuItem.Text = "Set Fast-Forward Rewind Step";
this.SetRewindStepFastMenuItem.Click += new System.EventHandler(this.SetRewindStepFastMenuItem_Click);
//
// CopyIncludesFrameNoMenuItem // CopyIncludesFrameNoMenuItem
// //
this.CopyIncludesFrameNoMenuItem.Text = "Include Frame # When Copying Input"; this.CopyIncludesFrameNoMenuItem.Text = "Include Frame # When Copying Input";
@ -1152,6 +1161,11 @@ namespace BizHawk.Client.EmuHawk
this.MainVertialSplit.TabIndex = 10; this.MainVertialSplit.TabIndex = 10;
this.MainVertialSplit.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.MainVerticalSplit_SplitterMoved); this.MainVertialSplit.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.MainVerticalSplit_SplitterMoved);
// //
// SetRewindStepMenuItem
//
this.SetRewindStepMenuItem.Text = "Set Rewind Step";
this.SetRewindStepMenuItem.Click += new System.EventHandler(this.SetRewindStepMenuItem_Click);
//
// TAStudio // TAStudio
// //
this.AllowDrop = true; this.AllowDrop = true;
@ -1349,5 +1363,7 @@ namespace BizHawk.Client.EmuHawk
private BizHawk.WinForms.Controls.ToolStripMenuItemEx SetFontMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx SetFontMenuItem;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx CopyIncludesFrameNoMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx CopyIncludesFrameNoMenuItem;
private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.ToolTip toolTip1;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx SetRewindStepFastMenuItem;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx SetRewindStepMenuItem;
} }
} }

View File

@ -77,17 +77,18 @@
public bool Rewind() public bool Rewind()
{ {
int rewindStep = MainForm.IsFastForwarding ? Settings.RewindStepFast : Settings.RewindStep;
// copy pasted from TasView_MouseWheel(), just without notch logic // copy pasted from TasView_MouseWheel(), just without notch logic
if (MainForm.IsSeeking && !MainForm.EmulatorPaused) if (MainForm.IsSeeking && !MainForm.EmulatorPaused)
{ {
MainForm.PauseOnFrame--; MainForm.PauseOnFrame -= rewindStep;
// that's a weird condition here, but for whatever reason it works best // that's a weird condition here, but for whatever reason it works best
if (Emulator.Frame >= MainForm.PauseOnFrame) if (Emulator.Frame >= MainForm.PauseOnFrame)
{ {
MainForm.PauseEmulator(); MainForm.PauseEmulator();
StopSeeking(); StopSeeking();
GoToPreviousFrame(); GoToFrame(Math.Max(0, Emulator.Frame - rewindStep));
} }
RefreshDialog(); RefreshDialog();
@ -95,7 +96,7 @@
else else
{ {
StopSeeking(); // late breaking memo: don't know whether this is needed StopSeeking(); // late breaking memo: don't know whether this is needed
GoToPreviousFrame(); GoToFrame(Math.Max(0, Emulator.Frame - rewindStep));
} }
return true; return true;

View File

@ -788,6 +788,67 @@ namespace BizHawk.Client.EmuHawk
} }
} }
} }
private void SetRewindStepFastMenuItem_Click(object sender, EventArgs e)
{
using var prompt = new InputPrompt
{
TextInputType = InputPrompt.InputType.Unsigned,
Message = "Number of frames to go back\nwhen pressing the rewind key\nwhile fast-forwarding:",
InitialValue = Settings.RewindStepFast.ToString(),
};
var result = MainForm.DoWithTempMute(() => prompt.ShowDialogOnScreen());
if (!result.IsOk())
{
return;
}
int val = 0;
try
{
val = int.Parse(prompt.PromptText);
}
catch
{
DialogController.ShowMessageBox("Invalid Entry.", "Input Error", EMsgBoxIcon.Error);
}
if (val > 0)
{
Settings.RewindStepFast = val;
}
}
private void SetRewindStepMenuItem_Click(object sender, EventArgs e)
{
using var prompt = new InputPrompt
{
TextInputType = InputPrompt.InputType.Unsigned,
Message = "Number of frames to go back\nwhen pressing the rewind key:",
InitialValue = Settings.RewindStep.ToString(),
};
var result = MainForm.DoWithTempMute(() => prompt.ShowDialogOnScreen());
if (!result.IsOk())
{
return;
}
int val = 0;
try
{
val = int.Parse(prompt.PromptText);
}
catch
{
DialogController.ShowMessageBox("Invalid Entry.", "Input Error", EMsgBoxIcon.Error);
}
if (val > 0)
{
Settings.RewindStep = val;
}
}
private void CopyIncludesFrameNoMenuItem_Click(object sender, EventArgs e) private void CopyIncludesFrameNoMenuItem_Click(object sender, EventArgs e)
=> Settings.CopyIncludesFrameNo = !Settings.CopyIncludesFrameNo; => Settings.CopyIncludesFrameNo = !Settings.CopyIncludesFrameNo;

View File

@ -114,6 +114,8 @@ namespace BizHawk.Client.EmuHawk
public bool AutoadjustInput { get; set; } public bool AutoadjustInput { get; set; }
public TAStudioPalette Palette { get; set; } public TAStudioPalette Palette { get; set; }
public int MaxUndoSteps { get; set; } = 1000; public int MaxUndoSteps { get; set; } = 1000;
public int RewindStep { get; set; } = 1;
public int RewindStepFast { get; set; } = 4;
} }
public TAStudio() public TAStudio()