tastudio: properly report saving progress.

also attempt to report seeking progress.
report occurs, but progressbar doesn't show up...
This commit is contained in:
feos 2015-12-10 01:38:06 +03:00
parent ea1368c819
commit 2a6a2a7a8a
7 changed files with 38 additions and 31 deletions

View File

@ -17,23 +17,8 @@ namespace BizHawk.Client.Common
public Func<string> ClientSettingsForSave { get; set; }
public Action<string> 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()));
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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<TAStudio>())
{
GlobalWin.Tools.TAStudio.ReportSeekingProgress();
}
}
}

View File

@ -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)

View File

@ -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;
}

View File

@ -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;