More bk2 progress

This commit is contained in:
adelikat 2014-06-15 14:44:26 +00:00
parent c807e27496
commit 6b73891a91
11 changed files with 149 additions and 28 deletions

View File

@ -133,6 +133,7 @@
<Compile Include="lua\LuaLibraryBase.cs" />
<Compile Include="lua\LuaMemoryBase.cs" />
<Compile Include="lua\NamedLuaFunction.cs" />
<Compile Include="movie\bk2\Bk2ControllerAdapter.cs" />
<Compile Include="movie\bk2\Bk2Header.cs" />
<Compile Include="movie\bk2\Bk2LogEntryGenerator.cs" />
<Compile Include="movie\bk2\Bk2Movie.cs" />
@ -153,6 +154,7 @@
<Compile Include="movie\InputAdapters.cs" />
<Compile Include="movie\interfaces\ILogEntryGenerator.cs" />
<Compile Include="movie\interfaces\IMovie.cs" />
<Compile Include="movie\interfaces\IMovieController.cs" />
<Compile Include="movie\MovieImport.cs" />
<Compile Include="movie\MovieService.cs" />
<Compile Include="movie\MovieSession.cs" />

View File

@ -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));
}
}

View File

@ -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;

View File

@ -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);
}
/// <summary>
@ -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);
}
}

View File

@ -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; }
/// <summary>
/// latches one player from the source
/// </summary>
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;
}
}
/// <summary>
/// latches all buttons from the provided source
/// </summary>
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);
}
}
/// <summary>
/// latches all buttons from the supplied mnemonic string
/// </summary>
public void SetControllersAsMnemonic(string mnemonic)
{
// TODO
}
#endregion
private readonly WorkingDictionary<string, bool> MyBoolButtons = new WorkingDictionary<string, bool>();
private readonly WorkingDictionary<string, float> MyFloatControls = new WorkingDictionary<string, float>();
}
}

View File

@ -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();
}
}
}
}

View File

@ -240,6 +240,14 @@ namespace BizHawk.Client.Common
}
}
public IMovieController MovieControllerAdapter
{
get
{
return new BkmControllerAdapter();
}
}
#region Privates
private bool IsBasePressed(string name)

View File

@ -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

View File

@ -32,6 +32,9 @@ namespace BizHawk.Client.Common
/// </summary>
string EmptyEntry { get; }
/// <summary>
/// Returns a movie controller adapter in the same state
/// </summary>
IMovieController MovieControllerAdapter { get; }
}
}

View File

@ -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));

View File

@ -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);