From 053ee9a45ea18eec66b6d4fa56cc0dc4fb80b6ae Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 14 Mar 2018 16:49:19 -0400 Subject: [PATCH] feos, i dont know, try this --- .../inputAdapters/BitwiseAdapters.cs | 26 +++++++++++++++++++ .../inputAdapters/InputAdapterExtensions.cs | 13 ++++++++++ .../DisplayManager/OSDManager.cs | 3 ++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/BizHawk.Client.Common/inputAdapters/BitwiseAdapters.cs b/BizHawk.Client.Common/inputAdapters/BitwiseAdapters.cs index 4987babdff..69e2ae8de8 100644 --- a/BizHawk.Client.Common/inputAdapters/BitwiseAdapters.cs +++ b/BizHawk.Client.Common/inputAdapters/BitwiseAdapters.cs @@ -27,6 +27,32 @@ namespace BizHawk.Client.Common internal IController SourceAnd { get; set; } } + public class XorAdapter : IController + { + public ControllerDefinition Definition => Source.Definition; + + public bool IsPressed(string button) + { + if (Source != null && SourceXor != null) + { + return Source.IsPressed(button) ^ SourceXor.IsPressed(button); + } + + return false; + } + + // pass floats solely from the original source + // this works in the code because SourceOr is the autofire controller + public float GetFloat(string name) + { + return Source.GetFloat(name); + } + + internal IController Source { get; set; } + internal IController SourceXor { get; set; } + } + + public class ORAdapter : IController { public ControllerDefinition Definition => Source.Definition; diff --git a/BizHawk.Client.Common/inputAdapters/InputAdapterExtensions.cs b/BizHawk.Client.Common/inputAdapters/InputAdapterExtensions.cs index 6df7308f66..8fb59c3509 100644 --- a/BizHawk.Client.Common/inputAdapters/InputAdapterExtensions.cs +++ b/BizHawk.Client.Common/inputAdapters/InputAdapterExtensions.cs @@ -16,6 +16,19 @@ namespace BizHawk.Client.Common.InputAdapterExtensions }; } + /// + /// Creates a new IController that is in a state of a bitwise Xor of the source and target controllers + /// + public static IController Xor(this IController source, IController target) + { + return new XorAdapter + { + Source = source, + SourceXor = target + }; + } + + /// /// Creates a new IController that is in a state of a bitwise Or of the source and target controllers /// diff --git a/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs b/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs index c3c3cc0519..01107e0435 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs @@ -369,6 +369,7 @@ namespace BizHawk.Client.EmuHawk //next, draw the immediate input. //that is, whatever's being held down interactively right this moment even if the game is paused //this includes things held down due to autohold or autofire + //I know, this is all really confusing var immediate = InputStrImmediate(); g.DrawString(immediate, MessageFont, immediateColor, x, y); @@ -377,7 +378,7 @@ namespace BizHawk.Client.EmuHawk //basically we're tinting whatever's pressed because it's sticky specially //in order to achieve this we want to avoid drawing anything pink that isnt actually held down right now //so we make an AND adapter and combine it using immediate & sticky - var autoString = MakeStringFor(Global.AutofireStickyXORAdapter.And(Global.StickyXORAdapter.Or(Global.AutofireStickyXORAdapter))); + var autoString = MakeStringFor(Global.StickyXORAdapter.Source.Xor(Global.AutofireStickyXORAdapter).And(Global.AutofireStickyXORAdapter)); g.DrawString(autoString, MessageFont, autoColor, x, y); //recolor everything that's changed from the previous input