From 7e92f38eb3a700e2dd2049d89f23c5afa258d181 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 22 Feb 2015 18:02:56 +0000 Subject: [PATCH] AutofireController - pass in an instance of an emulator rather than use Global.Emulator --- BizHawk.Client.Common/ControllerBinding.cs | 23 +++++++++++-------- .../inputAdapters/InputManager.cs | 10 ++++---- BizHawk.Client.EmuHawk/MainForm.cs | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/BizHawk.Client.Common/ControllerBinding.cs b/BizHawk.Client.Common/ControllerBinding.cs index cc365d7cea..d024b62bd9 100644 --- a/BizHawk.Client.Common/ControllerBinding.cs +++ b/BizHawk.Client.Common/ControllerBinding.cs @@ -217,6 +217,16 @@ namespace BizHawk.Client.Common public class AutofireController : IController { + public AutofireController(ControllerDefinition definition, IEmulator emulator) + { + On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn; + Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff; + _type = definition; + _emulator = emulator; + } + + private readonly IEmulator _emulator; + private readonly ControllerDefinition _type; private readonly WorkingDictionary> _bindings = new WorkingDictionary>(); private readonly WorkingDictionary _buttons = new WorkingDictionary(); @@ -228,20 +238,13 @@ namespace BizHawk.Client.Common public int On { get; set; } public int Off { get; set; } - public AutofireController(ControllerDefinition definition) - { - On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn; - Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff; - _type = definition; - } - public ControllerDefinition Type { get { return _type; } } public bool this[string button] { get { return IsPressed(button); } } public bool IsPressed(string button) { if (_autofire) { - var a = (Global.Emulator.Frame - _buttonStarts[button]) % (On + Off); + var a = (_emulator.Frame - _buttonStarts[button]) % (On + Off); return a < On && _buttons[button]; } @@ -273,7 +276,7 @@ namespace BizHawk.Client.Common { if (_buttons[kvp.Key] == false && controller[bound_button]) { - _buttonStarts[kvp.Key] = Global.Emulator.Frame; + _buttonStarts[kvp.Key] = _emulator.Frame; } } } @@ -311,7 +314,7 @@ namespace BizHawk.Client.Common public void BindMulti(string button, string controlString) { - if (!String.IsNullOrEmpty(controlString)) + if (!string.IsNullOrEmpty(controlString)) { var controlbindings = controlString.Split(','); foreach (var control in controlbindings) diff --git a/BizHawk.Client.Common/inputAdapters/InputManager.cs b/BizHawk.Client.Common/inputAdapters/InputManager.cs index 3ec8a91613..d6b39dafb8 100644 --- a/BizHawk.Client.Common/inputAdapters/InputManager.cs +++ b/BizHawk.Client.Common/inputAdapters/InputManager.cs @@ -40,12 +40,12 @@ namespace BizHawk.Client.Common var def = Global.Emulator.ControllerDefinition; Global.ActiveController = BindToDefinition(def, Global.Config.AllTrollers, Global.Config.AllTrollersAnalog); - Global.AutoFireController = BindToDefinitionAF(def, Global.Config.AllTrollersAutoFire); + Global.AutoFireController = BindToDefinitionAF(def, Global.Emulator, Global.Config.AllTrollersAutoFire); // allow propogating controls that are in the current controller definition but not in the prebaked one // these two lines shouldn't be required anymore under the new system? - Global.ActiveController.ForceType(new ControllerDefinition(Global.Emulator.ControllerDefinition)); - Global.ClickyVirtualPadController.Type = new ControllerDefinition(Global.Emulator.ControllerDefinition); + Global.ActiveController.ForceType(new ControllerDefinition(def)); + Global.ClickyVirtualPadController.Type = new ControllerDefinition(def); RewireInputChain(); } @@ -81,9 +81,9 @@ namespace BizHawk.Client.Common return ret; } - private static AutofireController BindToDefinitionAF(ControllerDefinition def, IDictionary> allbinds) + private static AutofireController BindToDefinitionAF(ControllerDefinition def, IEmulator emulator, IDictionary> allbinds) { - var ret = new AutofireController(def); + var ret = new AutofireController(def, emulator); Dictionary binds; if (allbinds.TryGetValue(def.Name, out binds)) { diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 4a73f6bd4b..32434f2aeb 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -1605,7 +1605,7 @@ namespace BizHawk.Client.EmuHawk Global.ClientControls = controls; Global.NullControls = new Controller(NullEmulator.NullController); - Global.AutofireNullControls = new AutofireController(NullEmulator.NullController); + Global.AutofireNullControls = new AutofireController(NullEmulator.NullController, Global.Emulator); }