Bk2ControllerAdapter/Bk2Movie - don't new up everytime some things that don't change through the lifetime of the object. HUGE (3x-4x) speedup to TAStudio
This commit is contained in:
parent
4a522263d9
commit
9bb07dca76
|
@ -9,6 +9,15 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public class Bk2ControllerAdapter : IMovieController
|
||||
{
|
||||
private class ControlMap
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public bool IsBool { get; set; }
|
||||
public bool IsFloat { get; set; }
|
||||
}
|
||||
|
||||
private List<ControlMap> _controlsOrdered = new List<ControlMap>();
|
||||
|
||||
private readonly string _logKey = "";
|
||||
private readonly WorkingDictionary<string, bool> _myBoolButtons = new WorkingDictionary<string, bool>();
|
||||
private readonly WorkingDictionary<string, float> _myFloatControls = new WorkingDictionary<string, float>();
|
||||
|
@ -74,6 +83,17 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
_type = new Bk2ControllerDefinition(value);
|
||||
SetLogOverride();
|
||||
|
||||
var def = Global.Emulator.ControllerDefinition;
|
||||
_controlsOrdered = Definition.ControlsOrdered
|
||||
.SelectMany(c => c)
|
||||
.Select(c => new ControlMap
|
||||
{
|
||||
Name = c,
|
||||
IsBool = def.BoolButtons.Contains(c),
|
||||
IsFloat = def.FloatControls.Contains(c)
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,24 +170,22 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (!string.IsNullOrWhiteSpace(mnemonic))
|
||||
{
|
||||
var def = Global.Emulator.ControllerDefinition;
|
||||
var trimmed = mnemonic.Replace("|", "");
|
||||
var buttons = Definition.ControlsOrdered.SelectMany(c => c);
|
||||
var iterator = 0;
|
||||
|
||||
foreach (var key in buttons)
|
||||
foreach (var key in _controlsOrdered)
|
||||
{
|
||||
if (def.BoolButtons.Contains(key))
|
||||
if (key.IsBool)
|
||||
{
|
||||
_myBoolButtons[key] = trimmed[iterator] != '.';
|
||||
_myBoolButtons[key.Name] = trimmed[iterator] != '.';
|
||||
iterator++;
|
||||
}
|
||||
else if (def.FloatControls.Contains(key))
|
||||
else if (key.IsFloat)
|
||||
{
|
||||
var commaIndex = trimmed.Substring(iterator).IndexOf(',');
|
||||
var temp = trimmed.Substring(iterator, commaIndex);
|
||||
var val = int.Parse(temp.Trim());
|
||||
_myFloatControls[key] = val;
|
||||
_myFloatControls[key.Name] = val;
|
||||
|
||||
iterator += commaIndex + 1;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public partial class Bk2Movie : IMovie
|
||||
{
|
||||
private Bk2ControllerAdapter _adapter;
|
||||
|
||||
public Bk2Movie(string filename)
|
||||
: this()
|
||||
{
|
||||
|
@ -127,6 +129,14 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (frame < FrameCount && frame >= 0)
|
||||
{
|
||||
if (_adapter == null)
|
||||
{
|
||||
_adapter = new Bk2ControllerAdapter
|
||||
{
|
||||
Definition = Global.MovieSession.MovieControllerAdapter.Definition
|
||||
};
|
||||
}
|
||||
|
||||
int getFrame;
|
||||
|
||||
if (LoopOffset.HasValue)
|
||||
|
@ -145,13 +155,8 @@ namespace BizHawk.Client.Common
|
|||
getFrame = frame;
|
||||
}
|
||||
|
||||
var adapter = new Bk2ControllerAdapter
|
||||
{
|
||||
Definition = Global.MovieSession.MovieControllerAdapter.Definition
|
||||
};
|
||||
|
||||
adapter.SetControllersAsMnemonic(Log[getFrame]);
|
||||
return adapter;
|
||||
_adapter.SetControllersAsMnemonic(Log[getFrame]);
|
||||
return _adapter;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue