diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj index db5c0c6745..d3a5931c11 100644 --- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj +++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj @@ -133,6 +133,7 @@ + @@ -153,6 +154,7 @@ + diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Joypad.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Joypad.cs index ed8797ab0c..f3f7396f59 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Joypad.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Joypad.cs @@ -73,17 +73,18 @@ namespace BizHawk.Client.Common )] public void SetFromMnemonicStr(string inputLogEntry) { - var m = new BkmControllerAdapter { Type = Global.MovieSession.MovieControllerAdapter.Type }; - m.SetControllersAsMnemonic(inputLogEntry); + var lg = Global.MovieSession.Movie.LogGeneratorInstance().MovieControllerAdapter; + lg.Type = Global.MovieSession.MovieControllerAdapter.Type; + lg.SetControllersAsMnemonic(inputLogEntry); - foreach (var button in m.Type.BoolButtons) + foreach (var button in lg.Type.BoolButtons) { - Global.LuaAndAdaptor.SetButton(button, m.IsPressed(button)); + Global.LuaAndAdaptor.SetButton(button, lg.IsPressed(button)); } - foreach (var floatButton in m.Type.FloatControls) + foreach (var floatButton in lg.Type.FloatControls) { - Global.LuaAndAdaptor.SetFloat(floatButton, m.GetFloat(floatButton)); + Global.LuaAndAdaptor.SetFloat(floatButton, lg.GetFloat(floatButton)); } } diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs index bd347a85e4..688778055e 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs @@ -31,13 +31,13 @@ namespace BizHawk.Client.Common { var input = Lua.NewTable(); - var m = new BkmControllerAdapter { Type = Global.MovieSession.MovieControllerAdapter.Type }; - m.SetControllersAsMnemonic( - Global.MovieSession.Movie.GetInput(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 m.Type.BoolButtons) + foreach (var button in lg.Type.BoolButtons) { - input[button] = m[button]; + input[button] = lg[button]; } return input; diff --git a/BizHawk.Client.Common/movie/MovieSession.cs b/BizHawk.Client.Common/movie/MovieSession.cs index 0b146797ca..d1c030bf23 100644 --- a/BizHawk.Client.Common/movie/MovieSession.cs +++ b/BizHawk.Client.Common/movie/MovieSession.cs @@ -10,15 +10,23 @@ namespace BizHawk.Client.Common public class MovieSession { private readonly MultitrackRecording _multiTrack = new MultitrackRecording(); - private readonly BkmControllerAdapter _movieControllerAdapter = new BkmControllerAdapter(); public MovieSession() { ReadOnly = true; + // Movies 2.0 TODO: Put this logic somewhere else, movie service? + if (VersionInfo.DeveloperBuild) + { + MovieControllerAdapter = new Bk2ControllerAdapter(); + } + else + { + MovieControllerAdapter = new BkmControllerAdapter(); + } } public MultitrackRecording MultiTrack { get { return _multiTrack; } } - public BkmControllerAdapter MovieControllerAdapter { get { return _movieControllerAdapter; } } + public IMovieController MovieControllerAdapter { get; private set; } public IMovie Movie { get; set; } public bool ReadOnly { get; set; } @@ -49,12 +57,12 @@ namespace BizHawk.Client.Common rewiredSource.PlayerSource = -1; } - _movieControllerAdapter.LatchPlayerFromSource(rewiredSource, _multiTrack.CurrentPlayer); + MovieControllerAdapter.LatchPlayerFromSource(rewiredSource, _multiTrack.CurrentPlayer); } public void LatchInputFromPlayer(IController source) { - _movieControllerAdapter.LatchFromSource(source); + MovieControllerAdapter.LatchFromSource(source); } /// @@ -67,7 +75,7 @@ namespace BizHawk.Client.Common // Attempting to get a frame past the end of a movie changes the mode to finished if (!Movie.IsFinished) { - _movieControllerAdapter.SetControllersAsMnemonic(input); + MovieControllerAdapter.SetControllersAsMnemonic(input); } } diff --git a/BizHawk.Client.Common/movie/bk2/Bk2ControllerAdapter.cs b/BizHawk.Client.Common/movie/bk2/Bk2ControllerAdapter.cs new file mode 100644 index 0000000000..f8842b4530 --- /dev/null +++ b/BizHawk.Client.Common/movie/bk2/Bk2ControllerAdapter.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using BizHawk.Common; +using BizHawk.Emulation.Common; + +namespace BizHawk.Client.Common +{ + public class Bk2ControllerAdapter : IMovieController + { + #region IController Implementation + + public bool this[string button] + { + get { return MyBoolButtons[button]; } + } + + public bool IsPressed(string button) + { + return MyBoolButtons[button]; + } + + public float GetFloat(string name) + { + return MyFloatControls[name]; + } + + #endregion + + #region IMovieController Implementation + + public ControllerDefinition Type { get; set; } + + /// + /// latches one player from the source + /// + public void LatchPlayerFromSource(IController playerSource, int playerNum) + { + foreach (string button in playerSource.Type.BoolButtons) + { + var bnp = ButtonNameParser.Parse(button); + if (bnp == null) + { + continue; + } + + if (bnp.PlayerNum != playerNum) + { + continue; + } + + bool val = playerSource[button]; + MyBoolButtons[button] = val; + } + } + + /// + /// latches all buttons from the provided source + /// + public void LatchFromSource(IController source) + { + foreach (string button in Type.BoolButtons) + { + MyBoolButtons[button] = source[button]; + } + + foreach (string name in Type.FloatControls) + { + MyFloatControls[name] = source.GetFloat(name); + } + } + + /// + /// latches all buttons from the supplied mnemonic string + /// + public void SetControllersAsMnemonic(string mnemonic) + { + // TODO + } + + #endregion + + private readonly WorkingDictionary MyBoolButtons = new WorkingDictionary(); + private readonly WorkingDictionary MyFloatControls = new WorkingDictionary(); + } +} diff --git a/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs b/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs index 3b6303c2bf..95b27e457f 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs @@ -59,7 +59,8 @@ namespace BizHawk.Client.Common public string GenerateLogEntry() { - var sb = new StringBuilder('|'); + var sb = new StringBuilder(); + sb.Append('|'); foreach (var button in _source.Type.BoolButtons) { sb.Append(_source.IsPressed(button) ? '1' : '.'); @@ -79,5 +80,13 @@ namespace BizHawk.Client.Common sb.Append('|'); return sb.ToString(); } + + public IMovieController MovieControllerAdapter + { + get + { + return new Bk2ControllerAdapter(); + } + } } } diff --git a/BizHawk.Client.Common/movie/bkm/BkmLogEntryGenerator.cs b/BizHawk.Client.Common/movie/bkm/BkmLogEntryGenerator.cs index 65662aa437..ba3f3de1be 100644 --- a/BizHawk.Client.Common/movie/bkm/BkmLogEntryGenerator.cs +++ b/BizHawk.Client.Common/movie/bkm/BkmLogEntryGenerator.cs @@ -240,6 +240,14 @@ namespace BizHawk.Client.Common } } + public IMovieController MovieControllerAdapter + { + get + { + return new BkmControllerAdapter(); + } + } + #region Privates private bool IsBasePressed(string name) diff --git a/BizHawk.Client.Common/movie/bkm/BkmMnemonicConstants.cs b/BizHawk.Client.Common/movie/bkm/BkmMnemonicConstants.cs index 938407c5da..ac26bc9691 100644 --- a/BizHawk.Client.Common/movie/bkm/BkmMnemonicConstants.cs +++ b/BizHawk.Client.Common/movie/bkm/BkmMnemonicConstants.cs @@ -5,8 +5,6 @@ using System.Text; using BizHawk.Common; using BizHawk.Emulation.Common; -// TODO: this entire file is scheduled to be obsolete - namespace BizHawk.Client.Common { public static class BkmMnemonicConstants diff --git a/BizHawk.Client.Common/movie/interfaces/ILogEntryGenerator.cs b/BizHawk.Client.Common/movie/interfaces/ILogEntryGenerator.cs index c397fdb980..a934c5a075 100644 --- a/BizHawk.Client.Common/movie/interfaces/ILogEntryGenerator.cs +++ b/BizHawk.Client.Common/movie/interfaces/ILogEntryGenerator.cs @@ -32,6 +32,9 @@ namespace BizHawk.Client.Common /// string EmptyEntry { get; } - + /// + /// Returns a movie controller adapter in the same state + /// + IMovieController MovieControllerAdapter { get; } } } diff --git a/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs b/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs index 765a12f215..e35e11d18d 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs @@ -250,7 +250,9 @@ namespace BizHawk.Client.EmuHawk public string InputStrOrAll() { - var m = new BkmControllerAdapter { Type = Global.MovieSession.MovieControllerAdapter.Type }; + //var m = new BkmControllerAdapter { Type = Global.MovieSession.MovieControllerAdapter.Type }; + var m = Global.MovieSession.Movie.LogGeneratorInstance().MovieControllerAdapter; + m.Type = Global.MovieSession.MovieControllerAdapter.Type; if (Global.MovieSession.Movie.IsActive) { @@ -286,7 +288,8 @@ namespace BizHawk.Client.EmuHawk { if (Global.MovieSession.Movie.IsActive) { - var m = new BkmControllerAdapter { Type = Global.MovieSession.MovieControllerAdapter.Type }; + var m = Global.MovieSession.Movie.LogGeneratorInstance().MovieControllerAdapter; + m.Type = Global.MovieSession.MovieControllerAdapter.Type; m.SetControllersAsMnemonic( Global.MovieSession.Movie.GetInput(Global.Emulator.Frame - 1)); diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/AnalogControlPanel.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/AnalogControlPanel.cs index 4b67dd9499..3cdfcacb98 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/AnalogControlPanel.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/AnalogControlPanel.cs @@ -86,14 +86,15 @@ namespace BizHawk.Client.EmuHawk e.Graphics.DrawLine(_black_pen, 64, 0, 64, 127); e.Graphics.DrawLine(_black_pen, 0, 63, 127, 63); - if (Global.MovieSession.Movie.IsActive && !Global.MovieSession.Movie.IsFinished) + if (Global.MovieSession.Movie.IsPlaying && !Global.MovieSession.Movie.IsFinished) { - var mnemonicStr = Global.MovieSession.Movie.GetInput(Global.Emulator.Frame - 1); - var m = new BkmControllerAdapter { Type = Global.MovieSession.MovieControllerAdapter.Type }; - m.SetControllersAsMnemonic(mnemonicStr); + var logEntry = Global.MovieSession.Movie.GetInput(Global.Emulator.Frame - 1); + var lg = Global.MovieSession.Movie.LogGeneratorInstance().MovieControllerAdapter; + lg.Type = Global.MovieSession.MovieControllerAdapter.Type; + lg.SetControllersAsMnemonic(logEntry); - var x = m.GetFloat(Controller + " X Axis"); - var y = m.GetFloat(Controller + " Y Axis"); + var x = lg.GetFloat(Controller + " X Axis"); + var y = lg.GetFloat(Controller + " Y Axis"); var xx = RealToGFX((int)x); var yy = RealToGFX((int)y);