diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs index 51f979c27f..ddf0861d33 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs @@ -17,23 +17,8 @@ namespace BizHawk.Client.Common public Func ClientSettingsForSave { get; set; } public Action GetClientSettingsOnLoad { get; set; } - private const double PROGRESS_STEP = 100 / 12; // TODO hardcoded for now, there might be a better way of doing this - - private double _totalProgress = 0; - - private void ReportProgress(double percent) - { - if (_progressReportWorker != null) - { - _totalProgress += percent; - _progressReportWorker.ReportProgress((int)_totalProgress); - } - } - protected override void Write(string fn) { - _totalProgress = 0; - var file = new FileInfo(fn); if (!file.Directory.Exists) { @@ -43,29 +28,21 @@ namespace BizHawk.Client.Common using (var bs = new BinaryStateSaver(fn, false)) { bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString())); - ReportProgress(PROGRESS_STEP); bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString())); - ReportProgress(PROGRESS_STEP); bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString())); - ReportProgress(PROGRESS_STEP); bs.PutLump(BinaryStateLump.SyncSettings, tw => tw.WriteLine(SyncSettingsJson)); - ReportProgress(PROGRESS_STEP); bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog())); - ReportProgress(PROGRESS_STEP); // TasProj extras bs.PutLump(BinaryStateLump.StateHistorySettings, tw => tw.WriteLine(StateManager.Settings.ToString())); - ReportProgress(PROGRESS_STEP); + if (StateManager.Settings.SaveStateHistory) { bs.PutLump(BinaryStateLump.StateHistory, (BinaryWriter bw) => StateManager.Save(bw)); } - ReportProgress(PROGRESS_STEP); bs.PutLump(BinaryStateLump.LagLog, (BinaryWriter bw) => LagLog.Save(bw)); - ReportProgress(PROGRESS_STEP); bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString())); - ReportProgress(PROGRESS_STEP); if (StartsFromSavestate) { @@ -82,14 +59,12 @@ namespace BizHawk.Client.Common { bs.PutLump(BinaryStateLump.MovieSaveRam, (BinaryWriter bw) => bw.Write(SaveRam)); } - ReportProgress(PROGRESS_STEP); if (ClientSettingsForSave != null) { var clientSettingsJson = ClientSettingsForSave(); bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson)); } - ReportProgress(PROGRESS_STEP); if (VerificationLog.Any()) { @@ -104,7 +79,6 @@ namespace BizHawk.Client.Common bs.PutLump(BinaryStateLump.BranchStateHistory, (BinaryWriter bw) => StateManager.SaveBranchStates(bw)); } } - ReportProgress(PROGRESS_STEP); bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(Session.ToString())); } diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index f8ef6337b0..e2e64d8e2c 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -24,7 +24,7 @@ namespace BizHawk.Client.Common public readonly IStringLog VerificationLog = StringLogUtil.MakeStringLog(); // For movies that do not begin with power-on, this is the input required to get into the initial state public readonly TasBranchCollection Branches = new TasBranchCollection(); - private BackgroundWorker _progressReportWorker = null; + public BackgroundWorker _progressReportWorker = null; public void NewBGWorker(BackgroundWorker newWorker) { _progressReportWorker = newWorker; @@ -149,6 +149,16 @@ namespace BizHawk.Client.Common } } + public void ReportProgress(double percent) + { + if (percent > 100d) + return; + if (_progressReportWorker != null) + { + _progressReportWorker.ReportProgress((int)percent); + } + } + #region Events and Handlers public event PropertyChangedEventHandler PropertyChanged; diff --git a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs index 5d1d317eca..566c5d866d 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs @@ -565,6 +565,7 @@ namespace BizHawk.Client.Common bw.Write(kvp.Key); bw.Write(kvp.Value.Length); bw.Write(kvp.Value.State); + _movie.ReportProgress((double)100d / States.Count * i); } } diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index fa90b636e8..f8a5d5b6bd 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -2824,10 +2824,17 @@ namespace BizHawk.Client.EmuHawk UpdateToolsAfter(); } - if (IsSeeking && Global.Emulator.Frame == PauseOnFrame.Value) + if (IsSeeking) { - PauseEmulator(); - PauseOnFrame = null; + if (Global.Emulator.Frame == PauseOnFrame.Value) + { + PauseEmulator(); + PauseOnFrame = null; + } + else if (GlobalWin.Tools.IsLoaded()) + { + GlobalWin.Tools.TAStudio.ReportSeekingProgress(); + } } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index b15ad1a9d0..dae45074f8 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -45,6 +45,7 @@ namespace BizHawk.Client.EmuHawk private bool _triggerAutoRestore; // If true, autorestore will be called on mouse up 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) diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs index ddeb65f5ce..1a51108ae8 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs @@ -58,6 +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; } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 3eae69c78a..e4d5ebbed5 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -641,6 +641,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(); } @@ -674,6 +675,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(); } @@ -705,6 +707,17 @@ 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;