diff --git a/BizHawk.Client.Common/movie/Movie.cs b/BizHawk.Client.Common/movie/Movie.cs index 6fe3b80f13..ade21a5e8b 100644 --- a/BizHawk.Client.Common/movie/Movie.cs +++ b/BizHawk.Client.Common/movie/Movie.cs @@ -68,17 +68,7 @@ namespace BizHawk.Client.Common public int RawFrames { - get - { - if (Loaded) - { - return _log.Length; - } - else - { - return _preload_framecount; - } - } + get { return Loaded ? _log.Length : _preload_framecount; } } public int? Frames @@ -141,7 +131,6 @@ namespace BizHawk.Client.Common { _log.ClearStates(); } - } } @@ -252,26 +241,6 @@ namespace BizHawk.Client.Common #region Public File Handling - public void WriteMovie(Stream stream) - { - if (!Loaded) - { - return; - } - - var directory_info = new FileInfo(Filename).Directory; - if (directory_info != null) Directory.CreateDirectory(directory_info.FullName); - - if (IsText) - { - WriteText(stream); - } - else - { - WriteBinary(stream); - } - } - public void WriteMovie(string path) { if (!Loaded) @@ -293,11 +262,7 @@ namespace BizHawk.Client.Common public void WriteMovie() { - if (!Loaded) - { - return; - } - else if (Filename == "") + if (!Loaded || String.IsNullOrWhiteSpace(Filename)) { return; } @@ -308,11 +273,7 @@ namespace BizHawk.Client.Common public void WriteBackup() { - if (!Loaded) - { - return; - } - else if (Filename == "") + if (!Loaded || String.IsNullOrWhiteSpace(Filename)) { return; } @@ -356,7 +317,7 @@ namespace BizHawk.Client.Common string str; while ((str = sr.ReadLine()) != null) { - if (str == "" || Header.AddHeaderFromLine(str)) + if (String.IsNullOrWhiteSpace(str) || Header.AddHeaderFromLine(str)) { continue; } @@ -426,14 +387,7 @@ namespace BizHawk.Client.Common getframe = frame; } - if (getframe < _log.Length) - { - return _log.GetFrame(getframe); - } - else - { - return ""; - } + return _log[getframe]; } public void ModifyFrame(string record, int frame) @@ -485,10 +439,7 @@ namespace BizHawk.Client.Common public MovieLog LogDump { - get - { - return _log; - } + get { return _log; } } public bool FrameLagged(int frame) @@ -500,8 +451,7 @@ namespace BizHawk.Client.Common { if (StateCapturing) { - byte[] state = Global.Emulator.SaveStateBinary(); - _log.AddState(state); + _log.AddState(Global.Emulator.SaveStateBinary()); GC.Collect(); } } @@ -534,12 +484,13 @@ namespace BizHawk.Client.Common public void DumpLogIntoSavestateText(TextWriter writer) { writer.WriteLine("[Input]"); - string s = MovieHeader.GUID + " " + Header.GetHeaderLine(MovieHeader.GUID); - writer.WriteLine(s); + writer.WriteLine(MovieHeader.GUID + " " + Header.GetHeaderLine(MovieHeader.GUID)); + for (int x = 0; x < _log.Length; x++) { - writer.WriteLine(_log.GetFrame(x)); + writer.WriteLine(_log[x]); } + writer.WriteLine("[/Input]"); } @@ -648,7 +599,7 @@ namespace BizHawk.Client.Common public string GetTime(bool preLoad) { - string time = ""; + string time = String.Empty; double seconds; if (preLoad) @@ -763,9 +714,7 @@ namespace BizHawk.Client.Common } for (int i = 0; i < stateFrame; i++) { - string xs = _log.GetFrame(i); - string ys = log.GetFrame(i); //TODO: huh?? - if (xs != ys) + if (_log[i] != log[i]) { ErrorMessage = "The savestate input does not match the movie input at frame " + (i + 1).ToString() diff --git a/BizHawk.Client.Common/movie/MovieLog.cs b/BizHawk.Client.Common/movie/MovieLog.cs index ed3e25e254..1d1796a4e7 100644 --- a/BizHawk.Client.Common/movie/MovieLog.cs +++ b/BizHawk.Client.Common/movie/MovieLog.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; +using System.Linq; namespace BizHawk.Client.Common { @@ -50,14 +51,7 @@ namespace BizHawk.Client.Common { get { - if (_state_records.Count > 0) - { - return StateCount * _state_records[0].State.Length; - } - else - { - return 0; - } + return _state_records.Any() ? StateCount * _state_records[0].State.Length : 0; } } @@ -105,7 +99,7 @@ namespace BizHawk.Client.Common public void SetFrameAt(int frameNum, string frame) { - if (frameNum < StateLastIndex && (frameNum < StateFirstIndex || frame != GetFrame(frameNum))) + if (frameNum < StateLastIndex && (frameNum < StateFirstIndex || frame != _movie_records[frameNum])) { TruncateStates(frameNum+1); } @@ -175,23 +169,19 @@ namespace BizHawk.Client.Common } } - public string GetFrame(int frame) + public string this[int frame] { - if (frame >= 0 && frame < _movie_records.Count) + get { return _movie_records[frame]; } - else - { - return ""; //TODO: throw an exception? - } } public void WriteText(StreamWriter sw) { - for (int i = 0; i < _movie_records.Count; i++) + foreach (var record in _movie_records) { - sw.WriteLine(GetFrame(i)); + sw.WriteLine(record); } } @@ -236,9 +226,9 @@ namespace BizHawk.Client.Common Lagged = Global.Emulator.IsLagFrame; } - public readonly int Index; - public readonly byte[] State; - public readonly bool Lagged; + public int Index { get; private set; } + public byte[] State { get; private set; } + public bool Lagged { get; private set; } } private readonly List _movie_records = new List(); diff --git a/BizHawk.MultiClient/movie/PlayMovie.cs b/BizHawk.MultiClient/movie/PlayMovie.cs index f0e803c054..0185165b96 100644 --- a/BizHawk.MultiClient/movie/PlayMovie.cs +++ b/BizHawk.MultiClient/movie/PlayMovie.cs @@ -488,7 +488,7 @@ namespace BizHawk.MultiClient .OrderByDescending(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) .ThenBy(x => x.GameName) - .ThenBy(x => x.Frames ?? int.MaxValue) + .ThenBy(x => x.RawFrames) .ToList(); } else @@ -497,7 +497,7 @@ namespace BizHawk.MultiClient .OrderBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) .ThenBy(x => x.GameName) - .ThenBy(x => x.Frames ?? int.MaxValue) + .ThenBy(x => x.RawFrames) .ToList(); } break; @@ -508,7 +508,7 @@ namespace BizHawk.MultiClient .OrderByDescending(x => x.SysID) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.GameName) - .ThenBy(x => x.Frames ?? int.MaxValue) + .ThenBy(x => x.RawFrames) .ToList(); } else @@ -517,7 +517,7 @@ namespace BizHawk.MultiClient .OrderBy(x => x.SysID) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.GameName) - .ThenBy(x => x.Frames ?? int.MaxValue) + .ThenBy(x => x.RawFrames) .ToList(); } break; @@ -528,7 +528,7 @@ namespace BizHawk.MultiClient .OrderByDescending(x => x.GameName) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) - .ThenBy(x => x.Frames ?? int.MaxValue) + .ThenBy(x => x.RawFrames) .ToList(); } else @@ -537,7 +537,7 @@ namespace BizHawk.MultiClient .OrderBy(x => x.GameName) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) - .ThenBy(x => x.Frames ?? int.MaxValue) + .ThenBy(x => x.RawFrames) .ToList(); } break; @@ -545,7 +545,7 @@ namespace BizHawk.MultiClient if (sortReverse) { MovieList = MovieList - .OrderByDescending(x => x.Frames ?? int.MaxValue) + .OrderByDescending(x => x.RawFrames) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) .ThenBy(x => x.GameName) @@ -554,7 +554,7 @@ namespace BizHawk.MultiClient else { MovieList = MovieList - .OrderBy(x => x.Frames ?? int.MaxValue) + .OrderBy(x => x.RawFrames) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) .ThenBy(x => x.GameName) diff --git a/BizHawk.MultiClient/tools/StateVisualizer.cs b/BizHawk.MultiClient/tools/StateVisualizer.cs index 07694371fe..e8abc64d53 100644 --- a/BizHawk.MultiClient/tools/StateVisualizer.cs +++ b/BizHawk.MultiClient/tools/StateVisualizer.cs @@ -137,7 +137,7 @@ namespace BizHawk.MultiClient { for (int i = 0; i < log.Length; i++) { - if (log.GetFrame(i) != timeline.Log.GetFrame(i)) + if (log[i] != timeline.Log[i]) { isdifferent = true; } @@ -158,7 +158,7 @@ namespace BizHawk.MultiClient { for (int i = 0; i < timeline.Log.Length; i++) { - if (log.GetFrame(i) != timeline.Log.GetFrame(i)) + if (log[i] != timeline.Log[i]) { isdifferent = true; }