diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs index 09168d82d5..6bb3be3ca3 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs @@ -71,16 +71,9 @@ namespace BizHawk.Client.Common return Global.MovieSession.Movie.IsActive; } - public static int movie_length() + public static double movie_length() { - if (Global.MovieSession.Movie.Frames.HasValue) - { - return Global.MovieSession.Movie.Frames.Value; - } - else - { - return -1; - } + return Global.MovieSession.Movie.FrameCount; } public static string movie_mode() diff --git a/BizHawk.Client.Common/movie/IMovie.cs b/BizHawk.Client.Common/movie/IMovie.cs index 20a1969e66..ae29626bed 100644 --- a/BizHawk.Client.Common/movie/IMovie.cs +++ b/BizHawk.Client.Common/movie/IMovie.cs @@ -21,7 +21,15 @@ namespace BizHawk.Client.Common #region Properties + double FrameCount { get; } + + /// + /// Actual length of the input log, should only be used by code that iterates or needs a real length + /// + int InputLogLength { get; } + ulong Rerecords { get; set; } + IMovieHeader Header { get; } #endregion @@ -90,8 +98,6 @@ namespace BizHawk.Client.Common 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 string GetTime(bool preLoad); // Rename to simply: Time, and make it a Timespan void GetInputLog(TextReader reader, bool isMultitracking); // how about the movie know if it is multi-tracking rather than having to pass it in - int? Frames { get; } // Nullable is a hack, also why does calling code need to know the number of frames, can that be minimized? - int RawFrames { get; } // Hacky to need two different frame properties string GetInput(int frame); // Should be a property of a Record object diff --git a/BizHawk.Client.Common/movie/Movie.cs b/BizHawk.Client.Common/movie/Movie.cs index 2d99376d2d..06a8bab0c3 100644 --- a/BizHawk.Client.Common/movie/Movie.cs +++ b/BizHawk.Client.Common/movie/Movie.cs @@ -61,25 +61,23 @@ namespace BizHawk.Client.Common get { return Header[HeaderKeys.GAMENAME]; } } - public int RawFrames + public int InputLogLength { get { return Loaded ? _log.Length : _preloadFramecount; } } - public int? Frames + public double FrameCount { get { - if (Loaded) + if (_loopOffset.HasValue) { - if (_loopOffset.HasValue) - { - return null; - } - else - { - return _log.Length; - } + return double.PositiveInfinity; + } + else if (Loaded) + { + + return _log.Length; } else { @@ -281,12 +279,22 @@ namespace BizHawk.Client.Common string line; while ((line = sr.ReadLine()) != null) { - if (String.IsNullOrWhiteSpace(line) || Header.ParseLineFromFile(line)) + if (line.Contains("LoopOffset")) + { + try + { + _loopOffset = int.Parse(line.Split(new[] { ' ' }, 2)[1]); + } + catch (Exception) + { + continue; + } + } + else if (String.IsNullOrWhiteSpace(line) || Header.ParseLineFromFile(line)) { continue; } - - if (line.StartsWith("|")) + else if (line.StartsWith("|")) { var frames = sr.ReadToEnd(); var length = line.Length; diff --git a/BizHawk.Client.Common/movie/MovieImport.cs b/BizHawk.Client.Common/movie/MovieImport.cs index fd29ae449a..9eee8f5d37 100644 --- a/BizHawk.Client.Common/movie/MovieImport.cs +++ b/BizHawk.Client.Common/movie/MovieImport.cs @@ -168,7 +168,7 @@ namespace BizHawk.Client.Common case '1': break; case '2': - if (m.Frames != 0) + if (m.FrameCount != 0) { warningMsg = "hard reset"; } diff --git a/BizHawk.Client.Common/movie/MovieSession.cs b/BizHawk.Client.Common/movie/MovieSession.cs index 53b26b9253..3ef63bc207 100644 --- a/BizHawk.Client.Common/movie/MovieSession.cs +++ b/BizHawk.Client.Common/movie/MovieSession.cs @@ -128,7 +128,7 @@ namespace BizHawk.Client.Common else if (Movie.IsFinished) { - if (Global.Emulator.Frame < Movie.Frames) //This scenario can happen from rewinding (suddenly we are back in the movie, so hook back up to the movie + if (Global.Emulator.Frame < Movie.FrameCount) //This scenario can happen from rewinding (suddenly we are back in the movie, so hook back up to the movie { Movie.SwitchToPlay(); LatchInputFromLog(); diff --git a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs index df9cd698a7..4ba39ac418 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs @@ -347,34 +347,23 @@ namespace BizHawk.Client.EmuHawk { if (Global.MovieSession.Movie.IsFinished) { - StringBuilder s = new StringBuilder(); - s.Append(Global.Emulator.Frame); - s.Append('/'); - if (Global.MovieSession.Movie.Frames.HasValue) - { - s.Append(Global.MovieSession.Movie.Frames); - } - else - { - s.Append("infinity"); - } - s.Append(" (Finished)"); - return s.ToString(); + var sb = new StringBuilder(); + sb + .Append(Global.Emulator.Frame) + .Append('/') + .Append(Global.MovieSession.Movie.FrameCount) + .Append(" (Finished)"); + return sb.ToString(); } else if (Global.MovieSession.Movie.IsPlaying) { - StringBuilder s = new StringBuilder(); - s.Append(Global.Emulator.Frame); - s.Append('/'); - if (Global.MovieSession.Movie.Frames.HasValue) - { - s.Append(Global.MovieSession.Movie.Frames); - } - else - { - s.Append("infinity"); - } - return s.ToString(); + var sb = new StringBuilder(); + sb + .Append(Global.Emulator.Frame) + .Append('/') + .Append(Global.MovieSession.Movie.FrameCount); + + return sb.ToString(); } else if (Global.MovieSession.Movie.IsRecording) { diff --git a/BizHawk.Client.EmuHawk/MainForm.Rewind.cs b/BizHawk.Client.EmuHawk/MainForm.Rewind.cs index 7236146829..a7cf08ccd3 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Rewind.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Rewind.cs @@ -603,7 +603,7 @@ namespace BizHawk.Client.EmuHawk { for (int i = 0; i < frames; i++) { - if (RewindBuf.Count == 0 || (Global.MovieSession.Movie.Loaded && Global.MovieSession.Movie.Frames == 0)) + if (RewindBuf.Count == 0 || (Global.MovieSession.Movie.Loaded && Global.MovieSession.Movie.FrameCount == 0)) return; if (LastState.Length < 0x10000) diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index fc5d3668f8..b2802927bc 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -213,7 +213,7 @@ namespace BizHawk.Client.EmuHawk // if user is dumping and didnt supply dump length, make it as long as the loaded movie if (_autoDumpLength == 0) { - _autoDumpLength = movie.RawFrames; + _autoDumpLength = movie.InputLogLength; } StartNewMovie(movie, false); Global.Config.RecentMovies.Add(cmdMovie); diff --git a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs index 4f7c532280..1eaa1ec4b9 100644 --- a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs +++ b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs @@ -88,7 +88,7 @@ namespace BizHawk.Client.EmuHawk { var movie = new Movie(file.FullName); movie.Load(); //State files will have to load everything unfortunately - if (movie.Frames == 0) + if (movie.FrameCount == 0) { MessageBox.Show("No input log detected in this savestate, aborting", "Can not load file", MessageBoxButtons.OK, MessageBoxIcon.Hand); @@ -117,7 +117,7 @@ namespace BizHawk.Client.EmuHawk { var movie = new Movie(file.CanonicalFullPath); movie.Load(); //State files will have to load everything unfortunately - if (movie.Frames > 0) + if (movie.FrameCount > 0) { _movieList.Add(movie); _sortReverse = false; @@ -376,7 +376,7 @@ namespace BizHawk.Client.EmuHawk DetailsView.Items.Add(FpsItem); var FramesItem = new ListViewItem("Frames"); - FramesItem.SubItems.Add(_movieList[firstIndex].RawFrames.ToString()); + FramesItem.SubItems.Add(_movieList[firstIndex].FrameCount.ToString()); DetailsView.Items.Add(FramesItem); CommentsBtn.Enabled = _movieList[firstIndex].Header.Comments.Any(); @@ -448,7 +448,7 @@ namespace BizHawk.Client.EmuHawk .OrderByDescending(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) .ThenBy(x => x.GameName) - .ThenBy(x => x.RawFrames) + .ThenBy(x => x.FrameCount) .ToList(); } else @@ -457,7 +457,7 @@ namespace BizHawk.Client.EmuHawk .OrderBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) .ThenBy(x => x.GameName) - .ThenBy(x => x.RawFrames) + .ThenBy(x => x.FrameCount) .ToList(); } break; @@ -468,7 +468,7 @@ namespace BizHawk.Client.EmuHawk .OrderByDescending(x => x.SysID) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.GameName) - .ThenBy(x => x.RawFrames) + .ThenBy(x => x.FrameCount) .ToList(); } else @@ -477,7 +477,7 @@ namespace BizHawk.Client.EmuHawk .OrderBy(x => x.SysID) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.GameName) - .ThenBy(x => x.RawFrames) + .ThenBy(x => x.FrameCount) .ToList(); } break; @@ -488,7 +488,7 @@ namespace BizHawk.Client.EmuHawk .OrderByDescending(x => x.GameName) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) - .ThenBy(x => x.RawFrames) + .ThenBy(x => x.FrameCount) .ToList(); } else @@ -497,7 +497,7 @@ namespace BizHawk.Client.EmuHawk .OrderBy(x => x.GameName) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) - .ThenBy(x => x.RawFrames) + .ThenBy(x => x.FrameCount) .ToList(); } break; @@ -505,16 +505,16 @@ namespace BizHawk.Client.EmuHawk if (_sortReverse) { _movieList = _movieList - .OrderByDescending(x => x.RawFrames) + .OrderByDescending(x => x.FrameCount) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) - .ThenBy(x => x.GameName) + .ThenBy(x => x.FrameCount) .ToList(); } else { _movieList = _movieList - .OrderBy(x => x.RawFrames) + .OrderBy(x => x.FrameCount) .ThenBy(x => Path.GetFileName(x.Filename)) .ThenBy(x => x.SysID) .ThenBy(x => x.GameName) diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio.cs index cfaf12c92d..e81e9ae265 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio.cs @@ -125,7 +125,7 @@ namespace BizHawk.Client.EmuHawk text = ""; //If this is just for an actual frame and not just the list view cursor at the end - if (Global.MovieSession.Movie.Frames != index) + if (Global.MovieSession.Movie.FrameCount != index) { if (column == 0) text = String.Format("{0:#,##0}", index); @@ -136,7 +136,7 @@ namespace BizHawk.Client.EmuHawk private void DisplayList() { - TASView.ItemCount = Global.MovieSession.Movie.RawFrames; + TASView.ItemCount = Global.MovieSession.Movie.InputLogLength; //if (Global.MovieSession.Movie.Frames == Global.Emulator.Frame && Global.MovieSession.Movie.StateLastIndex == Global.Emulator.Frame - 1) //{ // //If we're at the end of the movie add one to show the cursor as a blank frame @@ -253,7 +253,7 @@ namespace BizHawk.Client.EmuHawk if (Global.MovieSession.Movie.IsFinished || !Global.MovieSession.Movie.IsActive) { GlobalWin.MainForm.Rewind(1); - if (Global.Emulator.Frame <= Global.MovieSession.Movie.Frames) + if (Global.Emulator.Frame <= Global.MovieSession.Movie.FrameCount) { Global.MovieSession.Movie.SwitchToPlay(); }