tastudio: actually implement seeking progressbar.

This commit is contained in:
feos 2015-12-12 23:59:55 +03:00
parent c1e70077c8
commit 2535207a40
4 changed files with 78 additions and 32 deletions

View File

@ -2839,16 +2839,13 @@ namespace BizHawk.Client.EmuHawk
UpdateToolsAfter();
}
if (IsSeeking)
if (IsSeeking && Global.Emulator.Frame == PauseOnFrame.Value)
{
if (Global.Emulator.Frame == PauseOnFrame.Value)
PauseEmulator();
PauseOnFrame = null;
if (GlobalWin.Tools.IsLoaded<TAStudio>())
{
PauseEmulator();
PauseOnFrame = null;
}
else if (GlobalWin.Tools.IsLoaded<TAStudio>())
{
GlobalWin.Tools.TAStudio.ReportSeekingProgress();
GlobalWin.Tools.TAStudio.StopSeeking();
}
}
}

View File

@ -46,6 +46,7 @@ namespace BizHawk.Client.EmuHawk
private int? _autoRestoreFrame; // The frame auto-restore will restore to, if set
private bool? _autoRestorePaused = null;
private int? _seekStartFrame = null;
private void JumpToGreenzone()
{
if (Global.Emulator.Frame > CurrentTasMovie.LastValidFrame)
@ -58,11 +59,32 @@ namespace BizHawk.Client.EmuHawk
}
GoToLastEmulatedFrameIfNecessary(CurrentTasMovie.LastValidFrame);
GlobalWin.MainForm.PauseOnFrame = _autoRestoreFrame;
GlobalWin.MainForm.PauseEmulator();
StartSeeking(_autoRestoreFrame, true);
}
}
private void StartSeeking(int? frame, bool pause = false)
{
if (!frame.HasValue)
return;
_seekStartFrame = Emulator.Frame;
GlobalWin.MainForm.PauseOnFrame = frame.Value;
if (pause)
GlobalWin.MainForm.PauseEmulator();
else
GlobalWin.MainForm.UnpauseEmulator();
if (!_seekBackgroundWorker.IsBusy)
_seekBackgroundWorker.RunWorkerAsync();
}
public void StopSeeking()
{
_seekBackgroundWorker.CancelAsync();
}
// public static Color CurrentFrame_FrameCol = Color.FromArgb(0xCFEDFC); Why?
public static Color CurrentFrame_InputLog = Color.FromArgb(0xB5E7F7);

View File

@ -58,9 +58,7 @@ namespace BizHawk.Client.EmuHawk
if (lastState > Emulator.Frame)
LoadState(CurrentTasMovie.TasStateManager[lastState]); // STATE ACCESS
_seekStartFrame = Emulator.Frame;
GlobalWin.MainForm.UnpauseEmulator();
GlobalWin.MainForm.PauseOnFrame = frame;
StartSeeking(frame);
}
}

View File

@ -26,6 +26,7 @@ namespace BizHawk.Client.EmuHawk
private readonly List<TasClipboardEntry> _tasClipboard = new List<TasClipboardEntry>();
private BackgroundWorker _saveBackgroundWorker;
private BackgroundWorker _seekBackgroundWorker;
private MovieEndAction _originalEndAction; // The movie end behavior selected by the user (that is overridden by TAStudio)
private Dictionary<string, string> GenerateColumnNames()
@ -127,6 +128,7 @@ namespace BizHawk.Client.EmuHawk
this.SavingProgressBar.Visible = false;
InitializeSaveWorker();
InitializeSeekWorker();
WantsToControlStopMovie = true;
TasPlaybackBox.Tastudio = this;
@ -178,6 +180,50 @@ namespace BizHawk.Client.EmuHawk
CurrentTasMovie.NewBGWorker(_saveBackgroundWorker);
}
private void InitializeSeekWorker()
{
if (_seekBackgroundWorker != null)
{
_seekBackgroundWorker.Dispose();
_seekBackgroundWorker = null; // Idk if this line is even useful.
}
_seekBackgroundWorker = new BackgroundWorker();
_seekBackgroundWorker.WorkerReportsProgress = true;
_seekBackgroundWorker.WorkerSupportsCancellation = true;
_seekBackgroundWorker.DoWork += (s, e) =>
{
this.Invoke(() => this.MessageStatusLabel.Text = "Seeking...");
this.Invoke(() => this.SavingProgressBar.Visible = true);
for ( ; ; )
{
if (_seekBackgroundWorker.CancellationPending)
{
e.Cancel = true;
break;
}
double progress = (double)100d /
(GlobalWin.MainForm.PauseOnFrame.Value - _seekStartFrame.Value) *
(Global.Emulator.Frame - _seekStartFrame.Value);
_seekBackgroundWorker.ReportProgress((int)progress);
System.Threading.Thread.Sleep(1);
}
};
_seekBackgroundWorker.ProgressChanged += (s, e) =>
{
SavingProgressBar.Value = e.ProgressPercentage;
};
_seekBackgroundWorker.RunWorkerCompleted += (s, e) =>
{
this.Invoke(() => this.SavingProgressBar.Visible = false);
this.Invoke(() => this.MessageStatusLabel.Text = "");
InitializeSeekWorker(); // Required, or it will error when trying to report progress again.
};
}
private bool _initialized = false;
private void Tastudio_Load(object sender, EventArgs e)
{
@ -641,9 +687,7 @@ namespace BizHawk.Client.EmuHawk
{
if (_autoRestoreFrame > Emulator.Frame) // Don't unpause if we are already on the desired frame, else runaway seek
{
_seekStartFrame = Emulator.Frame;
GlobalWin.MainForm.PauseOnFrame = _autoRestoreFrame;
GlobalWin.MainForm.UnpauseEmulator();
StartSeeking(_autoRestoreFrame);
}
}
else
@ -653,8 +697,6 @@ namespace BizHawk.Client.EmuHawk
_autoRestorePaused = null;
GlobalWin.MainForm.PauseOnFrame = null; // Cancel seek to autorestore point
}
_autoRestoreFrame = null;
}
@ -675,9 +717,7 @@ namespace BizHawk.Client.EmuHawk
{
if (GlobalWin.MainForm.EmulatorPaused || GlobalWin.MainForm.IsSeeking) // make seek frame keep up with emulation on fast scrolls
{
_seekStartFrame = Emulator.Frame;
GlobalWin.MainForm.PauseOnFrame = frame;
GlobalWin.MainForm.UnpauseEmulator();
StartSeeking(frame);
}
}
}
@ -707,17 +747,6 @@ namespace BizHawk.Client.EmuHawk
BookMarkControl.RemoveBranchExtrenal();
}
public void ReportSeekingProgress()
{
if (_seekStartFrame.HasValue)
{
CurrentTasMovie.ReportProgress((double)100d /
(GlobalWin.MainForm.PauseOnFrame.Value - _seekStartFrame.Value) *
(Global.Emulator.Frame - _seekStartFrame.Value));
RefreshDialog();
}
}
private void UpdateOtherTools() // a hack probably, surely there is a better way to do this
{
_hackyDontUpdate = true;