From 6133164a7f3ef54e6e3c3418983cea9e6a4d8bfc Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 18 Jun 2014 02:26:22 +0000 Subject: [PATCH] Add GetInputState() to IMovie that returns an IController representing a frame of input and replace a lua method to use this instead of getting the inputlog as a string and processing it, still todo: obsolete the GetInput() method --- .../lua/EmuLuaLibrary.Movie.cs | 14 ++++---- .../movie/bk2/Bk2LogEntryGenerator.cs | 5 ++- BizHawk.Client.Common/movie/bk2/Bk2Movie.cs | 33 +++++++++++++++++++ BizHawk.Client.Common/movie/bkm/BkmMovie.cs | 33 +++++++++++++++++++ .../movie/interfaces/IMovie.cs | 9 ++++- 5 files changed, 86 insertions(+), 8 deletions(-) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs index 688778055e..1849d9f923 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs @@ -30,14 +30,16 @@ namespace BizHawk.Client.Common public LuaTable GetInput(int frame) { var input = Lua.NewTable(); + var adapter = Global.MovieSession.Movie.GetInputState(frame); - var lg = Global.MovieSession.Movie.LogGeneratorInstance().MovieControllerAdapter; - lg.Type = Global.MovieSession.MovieControllerAdapter.Type; - lg.SetControllersAsMnemonic(Global.MovieSession.Movie.GetInput(frame)); - - foreach (var button in lg.Type.BoolButtons) + foreach (var button in adapter.Type.BoolButtons) { - input[button] = lg[button]; + input[button] = adapter[button]; + } + + foreach (var button in adapter.Type.FloatControls) + { + input[button] = adapter[button]; } return input; diff --git a/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs b/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs index b6b2ecfdb6..ba13dec846 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs @@ -14,7 +14,10 @@ namespace BizHawk.Client.Common public IMovieController MovieControllerAdapter { - get { return new Bk2ControllerAdapter(); } + get + { + return new Bk2ControllerAdapter(); + } } #region ILogEntryGenerator Implementation diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs index ed48a2c4ac..be5f15ddb6 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs @@ -157,6 +157,39 @@ namespace BizHawk.Client.Common return string.Empty; } + public IController GetInputState(int frame) + { + if (frame < FrameCount && frame >= 0) + { + + int getframe; + + if (LoopOffset.HasValue) + { + if (frame < _log.Count) + { + getframe = frame; + } + else + { + getframe = ((frame - LoopOffset.Value) % (_log.Count - LoopOffset.Value)) + LoopOffset.Value; + } + } + else + { + getframe = frame; + } + + var adapter = new Bk2ControllerAdapter(); + adapter.Type = Global.MovieSession.MovieControllerAdapter.Type; + adapter.SetControllersAsMnemonic(_log[getframe]); + return adapter; + } + + Finish(); + return null; + } + public void PokeFrame(int frame, IController source) { throw new NotImplementedException(); diff --git a/BizHawk.Client.Common/movie/bkm/BkmMovie.cs b/BizHawk.Client.Common/movie/bkm/BkmMovie.cs index 9797534e84..c736f3f5a3 100644 --- a/BizHawk.Client.Common/movie/bkm/BkmMovie.cs +++ b/BizHawk.Client.Common/movie/bkm/BkmMovie.cs @@ -133,6 +133,39 @@ namespace BizHawk.Client.Common return string.Empty; } + public IController GetInputState(int frame) + { + if (frame < FrameCount && frame >= 0) + { + + int getframe; + + if (_loopOffset.HasValue) + { + if (frame < _log.Count) + { + getframe = frame; + } + else + { + getframe = ((frame - _loopOffset.Value) % (_log.Count - _loopOffset.Value)) + _loopOffset.Value; + } + } + else + { + getframe = frame; + } + + var adapter = new BkmControllerAdapter(); + adapter.Type = Global.MovieSession.MovieControllerAdapter.Type; + adapter.SetControllersAsMnemonic(_log[getframe]); + return adapter; + } + + Finish(); + return null; ; + } + public void ClearFrame(int frame) { var lg = LogGeneratorInstance(); diff --git a/BizHawk.Client.Common/movie/interfaces/IMovie.cs b/BizHawk.Client.Common/movie/interfaces/IMovie.cs index a8890b0f42..7d74ce9789 100644 --- a/BizHawk.Client.Common/movie/interfaces/IMovie.cs +++ b/BizHawk.Client.Common/movie/interfaces/IMovie.cs @@ -209,9 +209,16 @@ namespace BizHawk.Client.Common /// The input will be in the same format as represented in the input log when saved as a file /// /// The frame of input to be retrieved - /// + /// a string representation of a log entry from the input log file itself string GetInput(int frame); + /// + /// Gets a single frame of input via a controller state + /// + /// The frame of input to be retrieved + /// A controller state representing the specified frame of input, if frame is out of range, will return null + IController GetInputState(int frame); + #endregion } }