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

This commit is contained in:
adelikat 2014-06-18 02:26:22 +00:00
parent 083ea4cd02
commit 6133164a7f
5 changed files with 86 additions and 8 deletions

View File

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

View File

@ -14,7 +14,10 @@ namespace BizHawk.Client.Common
public IMovieController MovieControllerAdapter
{
get { return new Bk2ControllerAdapter(); }
get
{
return new Bk2ControllerAdapter();
}
}
#region ILogEntryGenerator Implementation

View File

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

View File

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

View File

@ -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
/// </summary>
/// <param name="frame">The frame of input to be retrieved</param>
/// <returns></returns>
/// <returns>a string representation of a log entry from the input log file itself</returns>
string GetInput(int frame);
/// <summary>
/// Gets a single frame of input via a controller state
/// </summary>
/// <param name="frame">The frame of input to be retrieved</param>
/// <returns>A controller state representing the specified frame of input, if frame is out of range, will return null</returns>
IController GetInputState(int frame);
#endregion
}
}