Unthread tastudio seek progress bar (#2774)
Co-authored-by: feos <feos-theos@yandex.ru>
This commit is contained in:
parent
681b564bce
commit
09ccf0dbe8
|
@ -154,7 +154,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
this.TasView = new BizHawk.Client.EmuHawk.InputRoll();
|
||||
this.TasStatusStrip = new StatusStripEx();
|
||||
this.MessageStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.SavingProgressBar = new System.Windows.Forms.ToolStripProgressBar();
|
||||
this.ProgressBar = new System.Windows.Forms.ToolStripProgressBar();
|
||||
this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.SplicerStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.TasPlaybackBox = new BizHawk.Client.EmuHawk.PlaybackBox();
|
||||
|
@ -925,7 +925,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
//
|
||||
this.TasStatusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.MessageStatusLabel,
|
||||
this.SavingProgressBar,
|
||||
this.ProgressBar,
|
||||
this.toolStripStatusLabel2,
|
||||
this.SplicerStatusLabel});
|
||||
this.TasStatusStrip.Location = new System.Drawing.Point(0, 554);
|
||||
|
@ -938,10 +938,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
this.MessageStatusLabel.Size = new System.Drawing.Size(95, 17);
|
||||
this.MessageStatusLabel.Text = "TAStudio engaged";
|
||||
//
|
||||
// SavingProgressBar
|
||||
// ProgressBar
|
||||
//
|
||||
this.SavingProgressBar.Name = "SavingProgressBar";
|
||||
this.SavingProgressBar.Size = new System.Drawing.Size(100, 16);
|
||||
this.ProgressBar.Name = "ProgressBar";
|
||||
this.ProgressBar.Size = new System.Drawing.Size(100, 16);
|
||||
//
|
||||
// toolStripStatusLabel2
|
||||
//
|
||||
|
@ -1310,7 +1310,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
private BizHawk.WinForms.Controls.ToolStripSeparatorEx StartFromNowSeparator;
|
||||
private BizHawk.WinForms.Controls.ToolStripMenuItemEx StartNewProjectFromNowMenuItem;
|
||||
private BizHawk.WinForms.Controls.ToolStripMenuItemEx RotateMenuItem;
|
||||
private System.Windows.Forms.ToolStripProgressBar SavingProgressBar;
|
||||
private System.Windows.Forms.ToolStripProgressBar ProgressBar;
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2;
|
||||
private BizHawk.WinForms.Controls.ToolStripMenuItemEx HideLagFramesSubMenu;
|
||||
private BizHawk.WinForms.Controls.ToolStripMenuItemEx HideLagFrames3;
|
||||
|
|
|
@ -24,6 +24,37 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private int _lastRefresh;
|
||||
|
||||
private void UpdateProgressBar()
|
||||
{
|
||||
if (MainForm.PauseOnFrame.HasValue)
|
||||
{
|
||||
int diff = Emulator.Frame - _seekStartFrame.Value;
|
||||
int unit = MainForm.PauseOnFrame.Value - _seekStartFrame.Value;
|
||||
double progress = 0;
|
||||
|
||||
if (diff != 0 && unit != 0)
|
||||
{
|
||||
progress = (double)100d / unit * diff;
|
||||
}
|
||||
|
||||
if (progress < 0)
|
||||
{
|
||||
progress = 0;
|
||||
}
|
||||
else if (progress > 100)
|
||||
{
|
||||
progress = 100;
|
||||
}
|
||||
|
||||
ProgressBar.Value = (int)progress;
|
||||
}
|
||||
else
|
||||
{
|
||||
ProgressBar.Visible = false;
|
||||
MessageStatusLabel.Text = "";
|
||||
}
|
||||
}
|
||||
|
||||
protected override void GeneralUpdate()
|
||||
{
|
||||
RefreshDialog();
|
||||
|
@ -61,6 +92,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
RefreshDialog(refreshNeeded, refreshBranches: false);
|
||||
UpdateProgressBar();
|
||||
}
|
||||
|
||||
protected override void FastUpdateAfter()
|
||||
{
|
||||
UpdateProgressBar();
|
||||
}
|
||||
|
||||
public override void Restart()
|
||||
|
|
|
@ -98,15 +98,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
TastudioPlayMode(); // suspend rec mode until seek ends, to allow mouse editing
|
||||
MainForm.UnpauseEmulator();
|
||||
|
||||
if (!_seekBackgroundWorker.IsBusy && diff > TasView.VisibleRows)
|
||||
if (diff > TasView.VisibleRows)
|
||||
{
|
||||
_seekBackgroundWorker.RunWorkerAsync();
|
||||
MessageStatusLabel.Text = "Seeking...";
|
||||
ProgressBar.Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void StopSeeking(bool skipRecModeCheck = false)
|
||||
{
|
||||
_seekBackgroundWorker.CancelAsync();
|
||||
if (WasRecording && !skipRecModeCheck)
|
||||
{
|
||||
TastudioRecordMode();
|
||||
|
|
|
@ -30,7 +30,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
private readonly List<TasClipboardEntry> _tasClipboard = new List<TasClipboardEntry>();
|
||||
private const string CursorColumnName = "CursorColumn";
|
||||
private const string FrameColumnName = "FrameColumn";
|
||||
private BackgroundWorker _seekBackgroundWorker;
|
||||
private MovieEndAction _originalEndAction; // The movie end behavior selected by the user (that is overridden by TAStudio)
|
||||
private UndoHistoryForm _undoForm;
|
||||
private Timer _autosaveTimer;
|
||||
|
@ -121,13 +120,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
ForumThreadMenuItem.Image = Resources.TAStudio;
|
||||
Icon = Resources.TAStudioIcon;
|
||||
|
||||
InitializeSeekWorker();
|
||||
|
||||
_defaultMainSplitDistance = MainVertialSplit.SplitterDistance;
|
||||
_defaultBranchMarkerSplitDistance = BranchesMarkersSplit.SplitterDistance;
|
||||
|
||||
// TODO: show this at all times or hide it when saving is done?
|
||||
SavingProgressBar.Visible = false;
|
||||
ProgressBar.Visible = false;
|
||||
|
||||
WantsToControlStopMovie = true;
|
||||
WantsToControlRestartMovie = true;
|
||||
|
@ -323,62 +320,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
private void InitializeSeekWorker()
|
||||
{
|
||||
_seekBackgroundWorker?.Dispose();
|
||||
_seekBackgroundWorker = new BackgroundWorker
|
||||
{
|
||||
WorkerReportsProgress = true,
|
||||
WorkerSupportsCancellation = true
|
||||
};
|
||||
|
||||
_seekBackgroundWorker.DoWork += (s, e) =>
|
||||
{
|
||||
this.Invoke(() => MessageStatusLabel.Text = "Seeking...");
|
||||
this.Invoke(() => SavingProgressBar.Visible = true);
|
||||
for (;;)
|
||||
{
|
||||
if (_seekBackgroundWorker.CancellationPending || !IsHandleCreated || !MainForm.PauseOnFrame.HasValue)
|
||||
{
|
||||
e.Cancel = true;
|
||||
break;
|
||||
}
|
||||
|
||||
int diff = Emulator.Frame - _seekStartFrame.Value;
|
||||
int unit = MainForm.PauseOnFrame.Value - _seekStartFrame.Value;
|
||||
double progress = 0;
|
||||
|
||||
if (diff != 0 && unit != 0)
|
||||
{
|
||||
progress = (double)100d / unit * diff;
|
||||
}
|
||||
|
||||
if (progress < 0)
|
||||
{
|
||||
progress = 0;
|
||||
}
|
||||
else if (progress > 100)
|
||||
{
|
||||
progress = 100;
|
||||
}
|
||||
|
||||
_seekBackgroundWorker.ReportProgress((int)progress);
|
||||
System.Threading.Thread.Sleep(1);
|
||||
}
|
||||
};
|
||||
|
||||
_seekBackgroundWorker.ProgressChanged += (s, e) =>
|
||||
{
|
||||
this.Invoke(() => SavingProgressBar.Value = e.ProgressPercentage);
|
||||
};
|
||||
|
||||
_seekBackgroundWorker.RunWorkerCompleted += (s, e) =>
|
||||
{
|
||||
this.Invoke(() => SavingProgressBar.Visible = false);
|
||||
this.Invoke(() => MessageStatusLabel.Text = "");
|
||||
};
|
||||
}
|
||||
|
||||
private void SetTasMovieCallbacks(ITasMovie movie)
|
||||
{
|
||||
movie.ClientSettingsForSave = () => TasView.UserSettingsSerialized();
|
||||
|
|
Loading…
Reference in New Issue