From b80f5a07eab1f7d43c511eb6a734697444857bd3 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 3 Dec 2013 02:10:17 +0000 Subject: [PATCH] Communicate with IMovie via MnemonicsGenerator objects --- BizHawk.Client.Common/movie/IMovie.cs | 4 +-- BizHawk.Client.Common/movie/IMovieRecord.cs | 2 +- BizHawk.Client.Common/movie/Movie.cs | 8 +++--- BizHawk.Client.Common/movie/MovieImport.cs | 28 ++++++++++----------- BizHawk.Client.Common/movie/MovieRecord.cs | 2 +- BizHawk.Client.Common/movie/MovieSession.cs | 4 ++- BizHawk.Client.Common/movie/TasMovie.cs | 9 ++++--- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/BizHawk.Client.Common/movie/IMovie.cs b/BizHawk.Client.Common/movie/IMovie.cs index b4177f5263..10a3c1ffc1 100644 --- a/BizHawk.Client.Common/movie/IMovie.cs +++ b/BizHawk.Client.Common/movie/IMovie.cs @@ -84,14 +84,14 @@ namespace BizHawk.Client.Common #region Editing API void ClearFrame(int frame); - void AppendFrame(string record); + void AppendFrame(MnemonicsGenerator mg); void Truncate(int frame); #endregion #region Dubious, should reconsider - void CommitFrame(int frameNum, IController source); // Why pass in frameNum? Calling api + void CommitFrame(int frameNum, MnemonicsGenerator mg); // 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 diff --git a/BizHawk.Client.Common/movie/IMovieRecord.cs b/BizHawk.Client.Common/movie/IMovieRecord.cs index c59e4272ec..526d7d393f 100644 --- a/BizHawk.Client.Common/movie/IMovieRecord.cs +++ b/BizHawk.Client.Common/movie/IMovieRecord.cs @@ -13,7 +13,7 @@ namespace BizHawk.Client.Common /// /// String representation of the controller input as a series of mnemonics /// - string Input { get; } + string Input { get; set; } /// /// Whether or not this was a lag frame, diff --git a/BizHawk.Client.Common/movie/Movie.cs b/BizHawk.Client.Common/movie/Movie.cs index bb7763feb3..94e8c76ef0 100644 --- a/BizHawk.Client.Common/movie/Movie.cs +++ b/BizHawk.Client.Common/movie/Movie.cs @@ -349,9 +349,9 @@ namespace BizHawk.Client.Common _changes = true; } - public void AppendFrame(string record) + public void AppendFrame(MnemonicsGenerator mg) { - _log.AppendFrame(record); + _log.AppendFrame(mg.GetControllersAsMnemonic()); _changes = true; } @@ -372,7 +372,7 @@ namespace BizHawk.Client.Common _log.SetFrameAt(frameNum, input); } - public void CommitFrame(int frameNum, IController source) + public void CommitFrame(int frameNum, MnemonicsGenerator mg) { // Note: Truncation here instead of loadstate will make VBA style loadstates // (Where an entire movie is loaded then truncated on the next frame @@ -386,8 +386,6 @@ namespace BizHawk.Client.Common } _changes = true; - var mg = new MnemonicsGenerator(); - mg.SetSource(source); _log.SetFrameAt(frameNum, mg.GetControllersAsMnemonic()); } diff --git a/BizHawk.Client.Common/movie/MovieImport.cs b/BizHawk.Client.Common/movie/MovieImport.cs index 864983e610..843c4f36b6 100644 --- a/BizHawk.Client.Common/movie/MovieImport.cs +++ b/BizHawk.Client.Common/movie/MovieImport.cs @@ -250,7 +250,7 @@ namespace BizHawk.Client.Common } // Convert the data for the controllers to a mnemonic and add it as a frame. mg.SetSource(controllers); - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); return m; } @@ -576,7 +576,6 @@ namespace BizHawk.Client.Common while (frame <= frameCount) { mg.SetSource(controllers); - string mnemonic = mg.GetControllersAsMnemonic(); byte update = r.ReadByte(); // aa: Number of delta bytes to follow int delta = (update >> 5) & 0x3; @@ -597,11 +596,10 @@ namespace BizHawk.Client.Common frame += frames; while (frames > 0) { - m.AppendFrame(mnemonic); + m.AppendFrame(mg); if (controllers["Reset"]) { controllers["Reset"] = false; - mnemonic = mg.GetControllersAsMnemonic(); } frames--; } @@ -856,7 +854,7 @@ namespace BizHawk.Client.Common } } mg.SetSource(controllers); - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); } r.Close(); fs.Close(); @@ -983,7 +981,7 @@ namespace BizHawk.Client.Common } } mg.SetSource(controllers); - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); } return m; } @@ -1330,7 +1328,7 @@ namespace BizHawk.Client.Common warningMsg = "Control commands are not properly supported."; } mg.SetSource(controllers); - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); } r.Close(); fs.Close(); @@ -1452,7 +1450,7 @@ namespace BizHawk.Client.Common } } mg.SetSource(controllers); - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); } r.Close(); fs.Close(); @@ -1682,7 +1680,7 @@ namespace BizHawk.Client.Common } } mg.SetSource(controllers); - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); } r.Close(); fs.Close(); @@ -1954,7 +1952,7 @@ namespace BizHawk.Client.Common continue; } mg.SetSource(controllers); - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); } r.Close(); fs.Close(); @@ -2226,7 +2224,7 @@ namespace BizHawk.Client.Common } } mg.SetSource(controllers); - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); } r.Close(); fs.Close(); @@ -2446,7 +2444,7 @@ namespace BizHawk.Client.Common } } mg.SetSource(controllers); - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); } r.Close(); fs.Close(); @@ -2614,7 +2612,7 @@ namespace BizHawk.Client.Common { controllers["Reset"] = true; mg.SetSource(controllers); - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); controllers["Reset"] = false; } // TODO: Other commands. @@ -2630,7 +2628,7 @@ namespace BizHawk.Client.Common mg.SetSource(controllers); for (; frames <= frame; frames++) { - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); } } else if (((flag >> 2) & 0x1) != 0) @@ -2743,7 +2741,7 @@ namespace BizHawk.Client.Common } } mg.SetSource(controllers); - m.AppendFrame(mg.GetControllersAsMnemonic()); + m.AppendFrame(mg); frames++; } } diff --git a/BizHawk.Client.Common/movie/MovieRecord.cs b/BizHawk.Client.Common/movie/MovieRecord.cs index 673f7cdeda..2c38ffb60b 100644 --- a/BizHawk.Client.Common/movie/MovieRecord.cs +++ b/BizHawk.Client.Common/movie/MovieRecord.cs @@ -9,7 +9,7 @@ namespace BizHawk.Client.Common { private List _state = new List(); - public string Input { get; private set; } + public string Input { get; set; } public bool Lagged { get; private set; } public IEnumerable State { diff --git a/BizHawk.Client.Common/movie/MovieSession.cs b/BizHawk.Client.Common/movie/MovieSession.cs index 14f6234f24..2b5d254c6a 100644 --- a/BizHawk.Client.Common/movie/MovieSession.cs +++ b/BizHawk.Client.Common/movie/MovieSession.cs @@ -182,7 +182,9 @@ namespace BizHawk.Client.Common } //the movie session makes sure that the correct input has been read and merged to its MovieControllerAdapter; //this has been wired to Global.MovieOutputHardpoint in RewireInputChain - Movie.CommitFrame(Global.Emulator.Frame, Global.MovieOutputHardpoint); + var mg = new MnemonicsGenerator(); + mg.SetSource(Global.MovieOutputHardpoint); + Movie.CommitFrame(Global.Emulator.Frame, mg); } } diff --git a/BizHawk.Client.Common/movie/TasMovie.cs b/BizHawk.Client.Common/movie/TasMovie.cs index 4d982ef103..a48a5b1aab 100644 --- a/BizHawk.Client.Common/movie/TasMovie.cs +++ b/BizHawk.Client.Common/movie/TasMovie.cs @@ -172,12 +172,15 @@ namespace BizHawk.Client.Common throw new NotImplementedException(); } - public void AppendFrame(string record) + public void AppendFrame(MnemonicsGenerator mg) { - throw new NotImplementedException(); + _records.Add(new MovieRecord() + { + Input = mg.GetControllersAsMnemonic(), + }); } - public void CommitFrame(int frameNum, Emulation.Common.IController source) + public void CommitFrame(int frameNum, MnemonicsGenerator mg) { throw new NotImplementedException(); }