Encapsulate GlobalWin.Config access in Input

This commit is contained in:
YoshiRulz 2020-11-30 19:21:13 +10:00
parent 4e38028b49
commit 32f571144e
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 16 additions and 10 deletions

View File

@ -106,22 +106,28 @@ namespace BizHawk.Client.EmuHawk
Alt = 262144 Alt = 262144
} }
private static readonly Lazy<Input> _instance = new Lazy<Input>(() => new Input()); private static readonly Lazy<Input> _instance = new Lazy<Input>(() => new Input(() => GlobalWin.Config));
public static Input Instance => _instance.Value; public static Input Instance => _instance.Value;
private readonly Thread _updateThread; private readonly Thread _updateThread;
public readonly HostInputAdapter Adapter = GlobalWin.Config.HostInputMethod switch public readonly HostInputAdapter Adapter;
{
EHostInputMethod.OpenTK => new OpenTKInputAdapter(),
EHostInputMethod.DirectInput => new DirectInputAdapter(),
_ => throw new Exception()
};
private Input() private readonly Func<Config> _getConfigCallback;
private Input(Func<Config> getConfigCallback)
{ {
Adapter.UpdateConfig(GlobalWin.Config); _getConfigCallback = getConfigCallback;
var config = _getConfigCallback();
Adapter = config.HostInputMethod switch
{
EHostInputMethod.OpenTK => new OpenTKInputAdapter(),
EHostInputMethod.DirectInput => new DirectInputAdapter(),
_ => throw new Exception()
};
Adapter.UpdateConfig(config);
_updateThread = new Thread(UpdateThreadProc) _updateThread = new Thread(UpdateThreadProc)
{ {
IsBackground = true, IsBackground = true,
@ -377,7 +383,7 @@ namespace BizHawk.Client.EmuHawk
}; };
while (true) while (true)
{ {
Adapter.UpdateConfig(GlobalWin.Config); Adapter.UpdateConfig(_getConfigCallback());
var keyEvents = Adapter.ProcessHostKeyboards(); var keyEvents = Adapter.ProcessHostKeyboards();
Adapter.PreprocessHostGamepads(); Adapter.PreprocessHostGamepads();