From b70d03a93f3e34e6830b580a11c05f5b1aacaac7 Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 4 Dec 2013 03:16:35 +0000 Subject: [PATCH] More simplifying Movie Loadstate code --- BizHawk.Client.Common/movie/IMovie.cs | 6 +----- BizHawk.Client.Common/movie/Movie.cs | 20 ++++++++++---------- BizHawk.Client.Common/movie/MovieSession.cs | 13 ++++++------- BizHawk.Client.Common/movie/TasMovie.cs | 4 ++-- 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/BizHawk.Client.Common/movie/IMovie.cs b/BizHawk.Client.Common/movie/IMovie.cs index da2cc0e00c..ef4fbcf59d 100644 --- a/BizHawk.Client.Common/movie/IMovie.cs +++ b/BizHawk.Client.Common/movie/IMovie.cs @@ -115,13 +115,9 @@ namespace BizHawk.Client.Common #region Dubious, should reconsider - LoadStateResult CheckTimeLines(TextReader reader, out string errorMessage); // No need to return a status, no reason to have hacky flags, no need to pass a textreader - + bool CheckTimeLines(TextReader reader, out string errorMessage); //Can we avoid passing a text reader? void ExtractInputLog(TextReader reader); //Is passing a textreader the only reasonable way to do this? #endregion } } - -// TODO: delete this and refactor code that uses it! -public enum LoadStateResult { Pass, TimeLineError, FutureEventError, NotInRecording, EmptyLog, MissingFrameNumber } \ No newline at end of file diff --git a/BizHawk.Client.Common/movie/Movie.cs b/BizHawk.Client.Common/movie/Movie.cs index e087e196aa..cb8c914ae1 100644 --- a/BizHawk.Client.Common/movie/Movie.cs +++ b/BizHawk.Client.Common/movie/Movie.cs @@ -556,7 +556,7 @@ namespace BizHawk.Client.Common } } - public LoadStateResult CheckTimeLines(TextReader reader, out string errorMessage) + public bool CheckTimeLines(TextReader reader, out string errorMessage) { // This function will compare the movie data to the savestate movie data to see if they match errorMessage = String.Empty; @@ -567,7 +567,7 @@ namespace BizHawk.Client.Common var line = reader.ReadLine(); if (line == null) { - return LoadStateResult.EmptyLog; + return false; } else if (line.Trim() == string.Empty) { @@ -583,7 +583,7 @@ namespace BizHawk.Client.Common catch { errorMessage = "Savestate Frame number failed to parse"; - return LoadStateResult.MissingFrameNumber; + return false; } } else if (line.Contains("Frame ")) @@ -596,7 +596,7 @@ namespace BizHawk.Client.Common catch { errorMessage = "Savestate Frame number failed to parse"; - return LoadStateResult.MissingFrameNumber; + return false; } } else if (line == "[Input]") @@ -622,7 +622,7 @@ namespace BizHawk.Client.Common { if (IsFinished) { - return LoadStateResult.Pass; + return true; } else { @@ -630,7 +630,7 @@ namespace BizHawk.Client.Common + log.Length + " which is greater than the current movie length of " + _log.Length; - return LoadStateResult.FutureEventError; + return false; } } @@ -641,7 +641,7 @@ namespace BizHawk.Client.Common errorMessage = "The savestate input does not match the movie input at frame " + (i + 1) + "."; - return LoadStateResult.TimeLineError; + return false; } } @@ -650,11 +650,11 @@ namespace BizHawk.Client.Common if (_mode == Moviemode.Play || _mode == Moviemode.Finished) { _mode = Moviemode.Finished; - return LoadStateResult.Pass; + return true; } else { - return LoadStateResult.NotInRecording; // TODO: For now throw an error if recording, ideally what should happen is that the state gets loaded, and the movie set to movie finished, the movie at its current state is preserved and the state is loaded just fine. This should probably also only happen if checktimelines passes + return false; } } else if (_mode == Moviemode.Finished) @@ -662,7 +662,7 @@ namespace BizHawk.Client.Common _mode = Moviemode.Play; } - return LoadStateResult.Pass; + return true; } #endregion diff --git a/BizHawk.Client.Common/movie/MovieSession.cs b/BizHawk.Client.Common/movie/MovieSession.cs index 712441b2bf..e25efbf12c 100644 --- a/BizHawk.Client.Common/movie/MovieSession.cs +++ b/BizHawk.Client.Common/movie/MovieSession.cs @@ -211,11 +211,10 @@ namespace BizHawk.Client.Common if (ReadOnly) { var result = Movie.CheckTimeLines(reader, out ErrorMSG); - if (result == LoadStateResult.Pass) + if (result) { Movie.Save(); Movie.SwitchToPlay(); - return true; } else @@ -227,7 +226,7 @@ namespace BizHawk.Client.Common else { var result = Movie.CheckTimeLines(reader, out ErrorMSG); - if (result == LoadStateResult.Pass) + if (result) { reader.BaseStream.Position = 0; reader.DiscardBufferedData(); @@ -246,7 +245,7 @@ namespace BizHawk.Client.Common if (ReadOnly) { var result = Movie.CheckTimeLines(reader, out ErrorMSG); - if (result == LoadStateResult.Pass) + if (result) { //Frame loop automatically handles the rewinding effect based on Global.Emulator.Frame so nothing else is needed here return true; @@ -259,7 +258,7 @@ namespace BizHawk.Client.Common else { var result = Movie.CheckTimeLines(reader, out ErrorMSG); - if (result == LoadStateResult.Pass) + if (result) { Movie.SwitchToRecord(); reader.BaseStream.Position = 0; @@ -279,7 +278,7 @@ namespace BizHawk.Client.Common if (ReadOnly) { var result = Movie.CheckTimeLines(reader, errorMessage: out ErrorMSG); - if (result != LoadStateResult.Pass) + if (!result) { Output(ErrorMSG); return false; @@ -296,7 +295,7 @@ namespace BizHawk.Client.Common else { var result = Movie.CheckTimeLines(reader, out ErrorMSG); - if (result == LoadStateResult.Pass) + if (result) { Global.Emulator.ClearSaveRam(); Movie.StartNewRecording(); diff --git a/BizHawk.Client.Common/movie/TasMovie.cs b/BizHawk.Client.Common/movie/TasMovie.cs index f5f5010164..993b21bc66 100644 --- a/BizHawk.Client.Common/movie/TasMovie.cs +++ b/BizHawk.Client.Common/movie/TasMovie.cs @@ -210,12 +210,12 @@ namespace BizHawk.Client.Common throw new NotImplementedException(); } - public LoadStateResult CheckTimeLines(System.IO.TextReader reader, out string errorMessage) + public bool CheckTimeLines(TextReader reader, out string errorMessage) { throw new NotImplementedException(); } - public void ExtractInputLog(System.IO.TextReader reader) + public void ExtractInputLog(TextReader reader) { throw new NotImplementedException(); }