TasMovie - cache mnemonic look ups, gives a noticeable speed boost to drawing

This commit is contained in:
adelikat 2020-06-20 16:00:08 -05:00
parent 249259d7b3
commit c6694a5e29
1 changed files with 10 additions and 3 deletions

View File

@ -40,8 +40,15 @@ namespace BizHawk.Client.Common
TasStateManager.Attach(emulator);
base.Attach(emulator);
foreach (var button in emulator.ControllerDefinition.BoolButtons)
{
_mnemonicCache[button] = Bk2MnemonicLookup.Lookup(button, emulator.SystemId);
}
}
private readonly Dictionary<string, char> _mnemonicCache = new Dictionary<string, char>();
public override bool StartsFromSavestate
{
get => base.StartsFromSavestate;
@ -127,15 +134,15 @@ namespace BizHawk.Client.Common
_displayCache = (frame, GetInputState(frame));
}
return CreateDisplayValueForButton(_displayCache.Controller, Emulator.SystemId, buttonName);
return CreateDisplayValueForButton(_displayCache.Controller, buttonName);
}
private static string CreateDisplayValueForButton(IController adapter, string systemId, string buttonName)
private string CreateDisplayValueForButton(IController adapter, string buttonName)
{
if (adapter.Definition.BoolButtons.Contains(buttonName))
{
return adapter.IsPressed(buttonName)
? Bk2MnemonicLookup.Lookup(buttonName, systemId).ToString()
? _mnemonicCache[buttonName].ToString()
: "";
}