Replace global config access in DirectInput wrapper with encapsulation

fixes b01f52c01; this required a whole lot of rearchitecting for one obscure
feature which will become obsolete with the move to .NET Core anyway, and I'm
not happy about it
This commit is contained in:
YoshiRulz 2020-10-06 09:13:16 +10:00 committed by James Groom
parent 02e0804712
commit 69a05641e7
5 changed files with 17 additions and 5 deletions

View File

@ -19,5 +19,7 @@ namespace BizHawk.Client.Common
void ProcessHostGamepads(Action<string?, bool, ClientInputFocus> handleButton, Action<string?, int> handleAxis);
IEnumerable<KeyEvent> ProcessHostKeyboards();
void UpdateConfig(Config config);
}
}

View File

@ -10,6 +10,8 @@ namespace BizHawk.Client.EmuHawk
{
internal sealed class DirectInputAdapter : HostInputAdapter
{
private Config? _config;
public void DeInitAll()
{
KeyInput.Cleanup();
@ -51,7 +53,9 @@ namespace BizHawk.Client.EmuHawk
}
}
public IEnumerable<KeyEvent> ProcessHostKeyboards() => KeyInput.Update().Concat(IPCKeyInput.Update());
public IEnumerable<KeyEvent> ProcessHostKeyboards() => KeyInput.Update(_config).Concat(IPCKeyInput.Update());
public void UpdateConfig(Config config) => _config = config;
}
internal sealed class OpenTKInputAdapter : HostInputAdapter
@ -78,5 +82,7 @@ namespace BizHawk.Client.EmuHawk
}
public IEnumerable<KeyEvent> ProcessHostKeyboards() => OTK_Keyboard.Update();
public void UpdateConfig(Config config) {}
}
}

View File

@ -120,6 +120,7 @@ namespace BizHawk.Client.EmuHawk
private Input()
{
Adapter.UpdateConfig(GlobalWin.Config);
UpdateThread = new Thread(UpdateThreadProc)
{
IsBackground = true,
@ -331,6 +332,8 @@ namespace BizHawk.Client.EmuHawk
{
while (true)
{
Adapter.UpdateConfig(GlobalWin.Config);
var keyEvents = Adapter.ProcessHostKeyboards();
Adapter.PreprocessHostGamepads();

View File

@ -66,8 +66,10 @@ namespace BizHawk.Client.EmuHawk
{Key.NumberPad0, OpenTK.Input.Key.Keypad0}, {Key.NumberPad1, OpenTK.Input.Key.Keypad1}, {Key.NumberPad2, OpenTK.Input.Key.Keypad2}, {Key.NumberPad3, OpenTK.Input.Key.Keypad3}, {Key.NumberPad4, OpenTK.Input.Key.Keypad4}, {Key.NumberPad5, OpenTK.Input.Key.Keypad5}, {Key.NumberPad6, OpenTK.Input.Key.Keypad6}, {Key.NumberPad7, OpenTK.Input.Key.Keypad7}, {Key.NumberPad8, OpenTK.Input.Key.Keypad8}, {Key.NumberPad9, OpenTK.Input.Key.Keypad9}, {Key.NumberPadPlus, OpenTK.Input.Key.KeypadAdd}, {Key.NumberPadPeriod, OpenTK.Input.Key.KeypadDecimal}, {Key.NumberPadSlash, OpenTK.Input.Key.KeypadDivide}, {Key.NumberPadEnter, OpenTK.Input.Key.KeypadEnter}, {Key.NumberPadStar, OpenTK.Input.Key.KeypadMultiply}, {Key.NumberPadMinus, OpenTK.Input.Key.KeypadSubtract}
};
public static IEnumerable<KeyEvent> Update()
public static IEnumerable<KeyEvent> Update(Config config)
{
OpenTK.Input.Key Mapped(Key k) => KeyEnumMap[config.HandleAlternateKeyboardLayouts ? KeyboardMapping.Handle(k) : k];
lock (SyncObj)
{
EventList.Clear();
@ -83,9 +85,9 @@ namespace BizHawk.Client.EmuHawk
foreach (var e in events)
{
foreach (var k in e.PressedKeys)
EventList.Add(new KeyEvent { Key = KeyEnumMap[KeyboardMapping.Handle(k)], Pressed = true });
EventList.Add(new KeyEvent { Key = Mapped(k), Pressed = true });
foreach (var k in e.ReleasedKeys)
EventList.Add(new KeyEvent { Key = KeyEnumMap[KeyboardMapping.Handle(k)], Pressed = false });
EventList.Add(new KeyEvent { Key = Mapped(k), Pressed = false });
}
}

View File

@ -11,7 +11,6 @@ namespace BizHawk.Client.EmuHawk
public static Key Handle(Key key)
{
if (!GlobalWin.Config.HandleAlternateKeyboardLayouts) return key;
ScanCode inputScanCode = SlimDXScanCodeMap[(int)key];
Keys virtualKey = (Keys)BizHawk.Common.Win32Imports.MapVirtualKey((uint)inputScanCode, MAPVK_VSC_TO_VK_EX);
ScanCode standardScanCode = GetStandardScanCode(virtualKey);