don't expose Bk2Controller, clients need to depend on an interface and rely on the Movie (well, MovieSession currently) to generate an IMovieController instance, since different implementations of IMovie need to be able to create their own controller implementations

This commit is contained in:
adelikat 2020-04-14 21:35:44 -05:00
parent f2e52988c1
commit c0fde42a0c
6 changed files with 23 additions and 20 deletions

View File

@ -65,7 +65,7 @@ namespace BizHawk.Client.Common
MovieInputSourceAdapter.Source = MultitrackRewiringAdapter;
ControllerOutput.Source = MovieOutputHardpoint;
Global.MovieSession.CreateMovieController(MovieInputSourceAdapter.Definition);
Global.MovieSession.RecreateMovieController(MovieInputSourceAdapter.Definition);
// connect the movie session before MovieOutputHardpoint if it is doing anything
// otherwise connect the MovieInputSourceAdapter to it, effectively bypassing the movie session

View File

@ -47,15 +47,15 @@ namespace BizHawk.Client.Common
/// </summary>
public Action ModeChangedCallback { get; set; }
public void CreateMovieController(ControllerDefinition definition)
public void RecreateMovieController(ControllerDefinition definition)
{
MovieController = new Bk2Controller(definition);
}
public IMovieController GenerateMovieController()
public IMovieController GenerateMovieController(ControllerDefinition definition = null)
{
// TODO: expose Movie.LogKey and pass in here
return new Bk2Controller("", MovieController.Definition);
return new Bk2Controller("", definition ?? MovieController.Definition);
}
// Convenience property that gets the controller state from the movie for the most recent frame

View File

@ -7,7 +7,7 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
public class Bk2Controller : IMovieController
internal class Bk2Controller : IMovieController
{
private readonly WorkingDictionary<string, bool> _myBoolButtons = new WorkingDictionary<string, bool>();
private readonly WorkingDictionary<string, float> _myAxisControls = new WorkingDictionary<string, float>();

View File

@ -15,14 +15,17 @@ namespace BizHawk.Client.Common
/// <summary>
/// Recreates MovieController with the given controller definition
/// with an empty controller state
/// </summary>
void CreateMovieController(ControllerDefinition definition);
void RecreateMovieController(ControllerDefinition definition);
/// <summary>
/// Creates a <see cref="IMovieController" /> instance based on the
/// given button definition if provided else the
/// current <see cref="MovieController" /> button definition
/// will be used
/// </summary>
IMovieController GenerateMovieController();
IMovieController GenerateMovieController(ControllerDefinition definition = null);
bool ReadOnly { get; set; }
bool MovieIsQueued { get; }

View File

@ -375,17 +375,17 @@ namespace BizHawk.Client.EmuHawk
var branch = Tastudio.CurrentTasMovie.Branches.FirstOrDefault(b => b.UniqueIdentifier.ToString() == branchId);
if (branch != null && frame < branch.InputLog.Count)
{
var adapter = new Bk2Controller(Global.MovieSession.MovieController.Definition);
adapter.SetFromMnemonic(branch.InputLog[frame]);
var controller = Global.MovieSession.GenerateMovieController();
controller.SetFromMnemonic(branch.InputLog[frame]);
foreach (var button in adapter.Definition.BoolButtons)
foreach (var button in controller.Definition.BoolButtons)
{
table[button] = adapter.IsPressed(button);
table[button] = controller.IsPressed(button);
}
foreach (var button in adapter.Definition.AxisControls)
foreach (var button in controller.Definition.AxisControls)
{
table[button] = adapter.AxisValue(button);
table[button] = controller.AxisValue(button);
}
}
}

View File

@ -12,16 +12,16 @@ namespace BizHawk.Client.EmuHawk
private readonly IEmulator _emulator;
private readonly ToolManager _tools;
private readonly string[] _log;
private readonly Bk2Controller _targetController;
private readonly IMovieController _targetController;
private string _inputKey;
private Bk2Controller _controller;
private IMovieController _controller;
public MovieZone(IMovie movie, IEmulator emulator, ToolManager tools, int start, int length, string key = "")
{
_emulator = emulator;
_tools = tools;
var lg = movie.LogGeneratorInstance(Global.MovieSession.MovieController);
_targetController = new Bk2Controller(_emulator.ControllerDefinition);
_targetController = Global.MovieSession.GenerateMovieController();
_targetController.SetFrom(_targetController); // Reference and create all buttons
if (key == "")
@ -53,7 +53,7 @@ namespace BizHawk.Client.EmuHawk
}
}
_controller = new Bk2Controller(d);
_controller = Global.MovieSession.GenerateMovieController(d);
var logGenerator = Global.MovieSession.Movie.LogGeneratorInstance(_controller);
logGenerator.GenerateLogEntry(); // Reference and create all buttons.
@ -106,7 +106,7 @@ namespace BizHawk.Client.EmuHawk
}
}
var newController = new Bk2Controller(d);
var newController = Global.MovieSession.GenerateMovieController(d);
var logGenerator = Global.MovieSession.Movie.LogGeneratorInstance(newController);
logGenerator.GenerateLogEntry(); // Reference and create all buttons.
@ -252,7 +252,7 @@ namespace BizHawk.Client.EmuHawk
Name = Path.GetFileNameWithoutExtension(fileName);
// Adapters
_targetController = new Bk2Controller(_emulator.ControllerDefinition);
_targetController = Global.MovieSession.GenerateMovieController();
_targetController.SetFrom(_targetController); // Reference and create all buttons
string[] keys = _inputKey.Split('|');
var d = new ControllerDefinition(_emulator.ControllerDefinition);
@ -268,7 +268,7 @@ namespace BizHawk.Client.EmuHawk
}
}
_controller = new Bk2Controller(d);
_controller = Global.MovieSession.GenerateMovieController(d);
}
#region Custom Latch