This commit is contained in:
hegyak 2015-12-09 17:01:18 -08:00
commit 84e3e02c1e
10 changed files with 63 additions and 34 deletions

View File

@ -17,23 +17,8 @@ namespace BizHawk.Client.Common
public Func<string> ClientSettingsForSave { get; set; } public Func<string> ClientSettingsForSave { get; set; }
public Action<string> GetClientSettingsOnLoad { 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) protected override void Write(string fn)
{ {
_totalProgress = 0;
var file = new FileInfo(fn); var file = new FileInfo(fn);
if (!file.Directory.Exists) if (!file.Directory.Exists)
{ {
@ -43,29 +28,21 @@ namespace BizHawk.Client.Common
using (var bs = new BinaryStateSaver(fn, false)) using (var bs = new BinaryStateSaver(fn, false))
{ {
bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString())); bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString()));
ReportProgress(PROGRESS_STEP);
bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString())); bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString()));
ReportProgress(PROGRESS_STEP);
bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString())); bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString()));
ReportProgress(PROGRESS_STEP);
bs.PutLump(BinaryStateLump.SyncSettings, tw => tw.WriteLine(SyncSettingsJson)); bs.PutLump(BinaryStateLump.SyncSettings, tw => tw.WriteLine(SyncSettingsJson));
ReportProgress(PROGRESS_STEP);
bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog())); bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog()));
ReportProgress(PROGRESS_STEP);
// TasProj extras // TasProj extras
bs.PutLump(BinaryStateLump.StateHistorySettings, tw => tw.WriteLine(StateManager.Settings.ToString())); bs.PutLump(BinaryStateLump.StateHistorySettings, tw => tw.WriteLine(StateManager.Settings.ToString()));
ReportProgress(PROGRESS_STEP);
if (StateManager.Settings.SaveStateHistory) if (StateManager.Settings.SaveStateHistory)
{ {
bs.PutLump(BinaryStateLump.StateHistory, (BinaryWriter bw) => StateManager.Save(bw)); bs.PutLump(BinaryStateLump.StateHistory, (BinaryWriter bw) => StateManager.Save(bw));
} }
ReportProgress(PROGRESS_STEP);
bs.PutLump(BinaryStateLump.LagLog, (BinaryWriter bw) => LagLog.Save(bw)); bs.PutLump(BinaryStateLump.LagLog, (BinaryWriter bw) => LagLog.Save(bw));
ReportProgress(PROGRESS_STEP);
bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString())); bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));
ReportProgress(PROGRESS_STEP);
if (StartsFromSavestate) if (StartsFromSavestate)
{ {
@ -82,14 +59,12 @@ namespace BizHawk.Client.Common
{ {
bs.PutLump(BinaryStateLump.MovieSaveRam, (BinaryWriter bw) => bw.Write(SaveRam)); bs.PutLump(BinaryStateLump.MovieSaveRam, (BinaryWriter bw) => bw.Write(SaveRam));
} }
ReportProgress(PROGRESS_STEP);
if (ClientSettingsForSave != null) if (ClientSettingsForSave != null)
{ {
var clientSettingsJson = ClientSettingsForSave(); var clientSettingsJson = ClientSettingsForSave();
bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson)); bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson));
} }
ReportProgress(PROGRESS_STEP);
if (VerificationLog.Any()) if (VerificationLog.Any())
{ {
@ -104,7 +79,6 @@ namespace BizHawk.Client.Common
bs.PutLump(BinaryStateLump.BranchStateHistory, (BinaryWriter bw) => StateManager.SaveBranchStates(bw)); bs.PutLump(BinaryStateLump.BranchStateHistory, (BinaryWriter bw) => StateManager.SaveBranchStates(bw));
} }
} }
ReportProgress(PROGRESS_STEP);
bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(Session.ToString())); 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 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(); public readonly TasBranchCollection Branches = new TasBranchCollection();
private BackgroundWorker _progressReportWorker = null; public BackgroundWorker _progressReportWorker = null;
public void NewBGWorker(BackgroundWorker newWorker) public void NewBGWorker(BackgroundWorker newWorker)
{ {
_progressReportWorker = 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 #region Events and Handlers
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;

View File

@ -565,6 +565,7 @@ namespace BizHawk.Client.Common
bw.Write(kvp.Key); bw.Write(kvp.Key);
bw.Write(kvp.Value.Length); bw.Write(kvp.Value.Length);
bw.Write(kvp.Value.State); bw.Write(kvp.Value.State);
_movie.ReportProgress((double)100d / States.Count * i);
} }
} }

View File

@ -38,7 +38,14 @@ namespace BizHawk.Client.Common
internal ByteWatch(MemoryDomain domain, long address, DisplayType type, bool bigEndian, string note, byte value, byte previous, int changeCount) internal ByteWatch(MemoryDomain domain, long address, DisplayType type, bool bigEndian, string note, byte value, byte previous, int changeCount)
: base(domain, address, WatchSize.Byte, type, bigEndian, note) : base(domain, address, WatchSize.Byte, type, bigEndian, note)
{ {
this._value = value; if (value == 0)
{
value = GetByte();
}
else
{
this._value = value;
}
this._previous = previous; this._previous = previous;
this._changecount = changeCount; this._changecount = changeCount;
} }

View File

@ -38,7 +38,14 @@ namespace BizHawk.Client.Common
internal DWordWatch(MemoryDomain domain, long address, DisplayType type, bool bigEndian, string note, uint value, uint previous, int changeCount) internal DWordWatch(MemoryDomain domain, long address, DisplayType type, bool bigEndian, string note, uint value, uint previous, int changeCount)
: base(domain, address, WatchSize.DWord, type, bigEndian, note) : base(domain, address, WatchSize.DWord, type, bigEndian, note)
{ {
this._value = value; if (value == 0)
{
value = GetDWord();
}
else
{
this._value = value;
}
this._previous = previous; this._previous = previous;
this._changecount = changeCount; this._changecount = changeCount;
} }

View File

@ -38,7 +38,14 @@ namespace BizHawk.Client.Common
internal WordWatch(MemoryDomain domain, long address, DisplayType type, bool bigEndian, string note, ushort value, ushort previous, int changeCount) internal WordWatch(MemoryDomain domain, long address, DisplayType type, bool bigEndian, string note, ushort value, ushort previous, int changeCount)
: base(domain, address, WatchSize.Word, type, bigEndian, note) : base(domain, address, WatchSize.Word, type, bigEndian, note)
{ {
this._value = value; if (value == 0)
{
value = GetWord();
}
else
{
this._value = value;
}
this._previous = previous; this._previous = previous;
this._changecount = changeCount; this._changecount = changeCount;
} }

View File

@ -2824,10 +2824,17 @@ namespace BizHawk.Client.EmuHawk
UpdateToolsAfter(); UpdateToolsAfter();
} }
if (IsSeeking && Global.Emulator.Frame == PauseOnFrame.Value) if (IsSeeking)
{ {
PauseEmulator(); if (Global.Emulator.Frame == PauseOnFrame.Value)
PauseOnFrame = null; {
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 bool _triggerAutoRestore; // If true, autorestore will be called on mouse up
private int? _autoRestoreFrame; // The frame auto-restore will restore to, if set private int? _autoRestoreFrame; // The frame auto-restore will restore to, if set
private bool? _autoRestorePaused = null; private bool? _autoRestorePaused = null;
private int? _seekStartFrame = null;
private void JumpToGreenzone() private void JumpToGreenzone()
{ {
if (Global.Emulator.Frame > CurrentTasMovie.LastValidFrame) if (Global.Emulator.Frame > CurrentTasMovie.LastValidFrame)

View File

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

View File

@ -444,6 +444,7 @@ namespace BizHawk.Client.EmuHawk
GoToFrame(0); GoToFrame(0);
else else
GoToFrame(CurrentTasMovie.Session.CurrentFrame); GoToFrame(CurrentTasMovie.Session.CurrentFrame);
CurrentTasMovie.PropertyChanged += new PropertyChangedEventHandler(this.TasMovie_OnPropertyChanged);
CurrentTasMovie.CurrentBranch = CurrentTasMovie.Session.CurrentBranch; CurrentTasMovie.CurrentBranch = CurrentTasMovie.Session.CurrentBranch;
// clear all selections // clear all selections
@ -640,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 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.PauseOnFrame = _autoRestoreFrame;
GlobalWin.MainForm.UnpauseEmulator(); GlobalWin.MainForm.UnpauseEmulator();
} }
@ -673,6 +675,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (GlobalWin.MainForm.EmulatorPaused || GlobalWin.MainForm.IsSeeking) // make seek frame keep up with emulation on fast scrolls 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.PauseOnFrame = frame;
GlobalWin.MainForm.UnpauseEmulator(); GlobalWin.MainForm.UnpauseEmulator();
} }
@ -704,6 +707,17 @@ namespace BizHawk.Client.EmuHawk
BookMarkControl.RemoveBranchExtrenal(); 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 private void UpdateOtherTools() // a hack probably, surely there is a better way to do this
{ {
_hackyDontUpdate = true; _hackyDontUpdate = true;