diff --git a/BizHawk.Client.Common/movie/IMovie.cs b/BizHawk.Client.Common/movie/IMovie.cs index 534b650700..1dcd1babdc 100644 --- a/BizHawk.Client.Common/movie/IMovie.cs +++ b/BizHawk.Client.Common/movie/IMovie.cs @@ -18,6 +18,7 @@ namespace BizHawk.Client.Common bool Loaded { get; } ulong Rerecords { get; set; } + IMovieHeader Header { get; } #endregion @@ -78,6 +79,7 @@ namespace BizHawk.Client.Common #endregion #region Dubious, should reconsider + void CommitFrame(int frameNum, IController source); // Why pass in frameNum? Calling api void PokeFrame(int frameNum, string input); // Why does this exist as something different than Commit Frame? LoadStateResult CheckTimeLines(TextReader reader, bool onlyGuid, bool ignoreGuidMismatch, out string errorMessage); // No need to return a status, no reason to have hacky flags, no need to pass a textreader @@ -89,9 +91,6 @@ namespace BizHawk.Client.Common string GetInput(int frame); // Should be a property of a Record object - IMovieHeader Header { get; } // Expose IMovieHEader instead - MovieLog LogDump { get; } // Don't expose this!!! - #endregion } } diff --git a/BizHawk.Client.Common/movie/Movie.cs b/BizHawk.Client.Common/movie/Movie.cs index 2b0e7184a2..aab1af4672 100644 --- a/BizHawk.Client.Common/movie/Movie.cs +++ b/BizHawk.Client.Common/movie/Movie.cs @@ -414,11 +414,6 @@ namespace BizHawk.Client.Common #region Public Misc Methods - public MovieLog LogDump - { - get { return _log; } - } - public void PokeFrame(int frameNum, string input) { _changes = true; diff --git a/BizHawk.Client.Common/movie/MovieLog.cs b/BizHawk.Client.Common/movie/MovieLog.cs index 08f4a03eda..e094ea6a19 100644 --- a/BizHawk.Client.Common/movie/MovieLog.cs +++ b/BizHawk.Client.Common/movie/MovieLog.cs @@ -81,11 +81,13 @@ namespace BizHawk.Client.Common { InitState = state; } + if (Global.Emulator.Frame < StateFirstIndex) { _state_records.Clear(); _state_records.Add(new StateRecord(Global.Emulator.Frame, state)); } + if (Global.Emulator.Frame > StateLastIndex) { if (StateSizeInBytes + state.Length > MAXSTATERECORDSIZE) @@ -93,6 +95,7 @@ namespace BizHawk.Client.Common // Discard the oldest state to save space. _state_records.RemoveAt(0); } + _state_records.Add(new StateRecord(Global.Emulator.Frame,state)); } } @@ -101,7 +104,7 @@ namespace BizHawk.Client.Common { if (frameNum < StateLastIndex && (frameNum < StateFirstIndex || frame != _movie_records[frameNum])) { - TruncateStates(frameNum+1); + TruncateStates(frameNum + 1); } if (_movie_records.Count > frameNum) @@ -123,12 +126,10 @@ namespace BizHawk.Client.Common if (frame <= StateFirstIndex) { _state_records.Clear(); - //Global.MovieSession.Movie.RewindToFrame(0); //TODO: unbreak this, also don't do it this way } else { _state_records.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1); - //Global.MovieSession.Movie.RewindToFrame(frame); //TODO: unbreak this, also don't do it this way } } } @@ -209,7 +210,7 @@ namespace BizHawk.Client.Common #region private fields - private class StateRecord + private sealed class StateRecord { public StateRecord(int index, byte[] state) { @@ -226,8 +227,8 @@ namespace BizHawk.Client.Common private readonly List _movie_records = new List(); private readonly List _state_records = new List(); - //TODO: Make this size limit configurable by the user - private const int MAXSTATERECORDSIZE = 512*1024*1024; //To limit memory usage. + // TODO: Make this size limit configurable by the user + private const int MAXSTATERECORDSIZE = 512 * 1024 * 1024; //To limit memory usage. #endregion } diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index 1b33ddaaca..fefc37b30a 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -590,7 +590,6 @@ Component - Form diff --git a/BizHawk.Client.EmuHawk/tools/StateVisualizer.cs b/BizHawk.Client.EmuHawk/tools/StateVisualizer.cs deleted file mode 100644 index 16669e47c0..0000000000 --- a/BizHawk.Client.EmuHawk/tools/StateVisualizer.cs +++ /dev/null @@ -1,187 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.IO; - -using BizHawk.Client.Common; - -namespace BizHawk.Client.EmuHawk -{ - class StateVisualizer - { - public StateVisualizer() - { - TimeLine movietimeline = new TimeLine(Global.MovieSession.Movie.LogDump); - - Timelines = new List {movietimeline}; - - //Load all 10 saveslots and process - for (int i = 0; i < 10; i++) - { - string name = "QuickSave" + i.ToString(); - string path = PathManager.SaveStatePrefix(Global.Game) + "." + name + ".State"; - if (File.Exists(path)) - { - Movie movie = new Movie(); - LoadLogFromSavestateText(movie, path); - AddLog(movie.LogDump, i); - } - } - } - - private void LoadLogFromSavestateText(Movie movie, string path) - { - using (var reader = new StreamReader(path)) - { - movie.LoadLogFromSavestateText(reader, Global.MovieSession.MultiTrack.IsActive); - } - } - - public int TimeLineCount - { - get - { - return Timelines.Count; - } - } - - private void AddLog(MovieLog log, int? slot) - { - sort(); - - bool added = false; - foreach (TimeLine timeline in Timelines) - { - if (timeline.TryAddToTimeline(log, slot)) - { - added = true; - } - } - - if (!added) - { - TimeLine t = new TimeLine(log); - Timelines.Add(t); - } - } - - private void sort() - { - Timelines = Timelines.OrderByDescending(x => x.Length).ToList(); - } - - List Timelines; //MovieLogs of all savestates and the loaded movie - - //Represents a single timeline that consists of at least 1 slot - private class TimeLine - { - public TimeLine(MovieLog log, int? slot_number = null) - { - timeline = new Event(log, slot_number); - subevents = new List(); - } - - private Event timeline; - private List subevents; - - private class Event - { - public int? Slot; - public MovieLog Log; - - public Event(MovieLog log, int? slot) - { - Slot = slot; - Log = log; - } - - public Event() - { - Slot = null; - Log = new MovieLog(); - } - } - - public int Points - { - get - { - return subevents.Count + 1; - } - } - - public int Length - { - get - { - return timeline.Log.Length; - } - } - - public int? GetPoint(int position) - { - sort(); - if (position < subevents.Count) - { - return subevents[position].Log.Length; - } - else - { - return null; - } - } - - public bool TryAddToTimeline(MovieLog log, int? slot) - { - bool isdifferent = false; - if (log.Length < timeline.Log.Length) - { - for (int i = 0; i < log.Length; i++) - { - if (log[i] != timeline.Log[i]) - { - isdifferent = true; - } - } - - if (isdifferent) - { - return false; - } - else - { - subevents.Add(new Event(log, slot)); - sort(); - return true; - } - } - else - { - for (int i = 0; i < timeline.Log.Length; i++) - { - if (log[i] != timeline.Log[i]) - { - isdifferent = true; - } - } - - if (isdifferent) - { - return false; - } - else - { - subevents.Add(timeline); - timeline = new Event(log, slot); - sort(); - return true; - } - } - } - - private void sort() - { - subevents = subevents.OrderByDescending(x => x.Log.Length).ToList(); - } - } - } -}