diff --git a/BizHawk.Client.Common/inputAdapters/InputAdapters.cs b/BizHawk.Client.Common/inputAdapters/InputAdapters.cs index 9d616c7ffc..70bf6ebdb3 100644 --- a/BizHawk.Client.Common/inputAdapters/InputAdapters.cs +++ b/BizHawk.Client.Common/inputAdapters/InputAdapters.cs @@ -383,235 +383,140 @@ namespace BizHawk.Client.Common private List _justPressed = new List(); } - /// SuuperW: Old code commented - //public class AutoFireStickyXorAdapter : IController, ISticky - //{ - // public int On { get; set; } - // public int Off { get; set; } - // public WorkingDictionary buttonStarts = new WorkingDictionary(); - // public WorkingDictionary lagStarts = new WorkingDictionary(); // TODO: need a data structure not misc dictionaries - - // private readonly HashSet _stickySet = new HashSet(); - - // public IController Source { get; set; } - - // public void SetOnOffPatternFromConfig() - // { - // On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn; - // Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff; - // } - - // public AutoFireStickyXorAdapter() - // { - // //On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn; - // //Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff; - // On = 1; - // Off = 1; - // } - - // public bool IsPressed(string button) - // { - // return this[button]; - // } - - // public bool this[string button] - // { - // get - // { - // var source = Source[button]; - - // if (_stickySet.Contains(button)) - // { - // var lagcount = 0; - // if (Global.Emulator.CanPollInput() && Global.Config.AutofireLagFrames) - // { - // lagcount = Global.Emulator.AsInputPollable().LagCount; - // } - - // var a = ((Global.Emulator.Frame - lagcount) - (buttonStarts[button] - lagStarts[button])) % (On + Off); - // if (a < On) - // { - // return source ^= true; - // } - // else - // { - // return source ^= false; - // } - // } - - // return source; - // } - - // set - // { - // throw new InvalidOperationException(); - // } - // } - - // public ControllerDefinition Type { get { return Source.Type; } set { throw new InvalidOperationException(); } } - // public bool Locked { get; set; } // Pretty much a hack, - - // // dumb passthrough for floats, because autofire doesn't care about them - // public float GetFloat(string name) - // { - // return Source.GetFloat(name); - // } - - // public void SetSticky(string button, bool isSticky) - // { - // if (isSticky) - // { - // _stickySet.Add(button); - // buttonStarts.Add(button, Global.Emulator.Frame); - - // if (Global.Emulator.CanPollInput()) - // { - // lagStarts.Add(button, Global.Emulator.AsInputPollable().LagCount); - // } - // else - // { - // lagStarts.Add(button, 0); - // } - // } - // else - // { - // _stickySet.Remove(button); - // buttonStarts.Remove(button); - // lagStarts.Remove(button); - // } - // } - - // public bool IsSticky(string button) - // { - // return this._stickySet.Contains(button); - // } - - // public HashSet CurrentStickies - // { - // get - // { - // return this._stickySet; - // } - // } - - // public void ClearStickies() - // { - // _stickySet.Clear(); - // buttonStarts.Clear(); - // lagStarts.Clear(); - // } - - // public void MassToggleStickyState(List buttons) - // { - // foreach (var button in buttons.Where(button => !_justPressed.Contains(button))) - // { - // if (_stickySet.Contains(button)) - // { - // _stickySet.Remove(button); - // } - // else - // { - // _stickySet.Add(button); - // } - // } - - // _justPressed = buttons; - // } - - // /// - // /// Determines if a sticky is current mashing the button itself, - // /// If sticky is not set then false, if set, it returns true if the Source is not pressed, else false - // /// - // public bool StickyIsInEffect(string button) - // { - // if (Source.IsPressed(button)) - // { - // return false; - // } - - // return (IsPressed(button)); // Shortcut logic since we know the Source isn't pressed, Ispressed can only return true if the autofire sticky is in effect for this frame - // } - - // private List _justPressed = new List(); - //} + /// SuuperW: I'm leaving the old class in case I accidentally screwed something up + /// adelikat: You did, the autofire feature this was controlling, putting it back, fix your class public class AutoFireStickyXorAdapter : IController, ISticky { - // TODO: Change the AutoHold adapter to be one of these, with an 'Off' value of 0? - // Probably would have slightly lower performance, but it seems weird to have such a similar class that is only used once. - private int On; - private int Off; + public int On { get; set; } + public int Off { get; set; } + public WorkingDictionary buttonStarts = new WorkingDictionary(); + public WorkingDictionary lagStarts = new WorkingDictionary(); // TODO: need a data structure not misc dictionaries + + private readonly HashSet _stickySet = new HashSet(); + + public IController Source { get; set; } + public void SetOnOffPatternFromConfig() { On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn; Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff; } - private WorkingDictionary _boolPatterns = new WorkingDictionary(); - private WorkingDictionary _floatPatterns = new WorkingDictionary(); - public AutoFireStickyXorAdapter() { - On = 1; Off = 1; + //On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn; + //Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff; + On = 1; + Off = 1; } - public IController Source { get; set; } - - public ControllerDefinition Type - { - get { return Source.Type; } - } - - public bool Locked { get; set; } // Pretty much a hack, - public bool IsPressed(string button) { return this[button]; } - public void SetFloat(string name, float? value, AutoPatternFloat pattern = null) - { - if (value.HasValue) - { - if (pattern == null) - pattern = new AutoPatternFloat(value.Value, On, 0, Off); - _floatPatterns[name] = pattern; - } - else - { - _floatPatterns.Remove(name); - } - } - - public float GetFloat(string name) - { - if (_floatPatterns.ContainsKey(name)) - return _floatPatterns[name].PeekNextValue(); - - if (Source == null) - return 0; - - return Source.GetFloat(name); - } - - public void ClearStickyFloats() - { - _floatPatterns.Clear(); - } - public bool this[string button] { get { var source = Source[button]; - bool patternValue = false; - if (_boolPatterns.ContainsKey(button)) - { // I can't figure a way to determine right here if it should Peek or Get. - patternValue = _boolPatterns[button].PeekNextValue(); + + if (_stickySet.Contains(button)) + { + var lagcount = 0; + if (Global.Emulator.CanPollInput() && Global.Config.AutofireLagFrames) + { + lagcount = Global.Emulator.AsInputPollable().LagCount; + } + + var a = ((Global.Emulator.Frame - lagcount) - (buttonStarts[button] - lagStarts[button])) % (On + Off); + if (a < On) + { + return source ^= true; + } + else + { + return source ^= false; + } } - source ^= patternValue; return source; } + + set + { + throw new InvalidOperationException(); + } + } + + public ControllerDefinition Type { get { return Source.Type; } set { throw new InvalidOperationException(); } } + public bool Locked { get; set; } // Pretty much a hack, + + // dumb passthrough for floats, because autofire doesn't care about them + public float GetFloat(string name) + { + return Source.GetFloat(name); + } + + public void SetSticky(string button, bool isSticky) + { + if (isSticky) + { + _stickySet.Add(button); + buttonStarts.Add(button, Global.Emulator.Frame); + + if (Global.Emulator.CanPollInput()) + { + lagStarts.Add(button, Global.Emulator.AsInputPollable().LagCount); + } + else + { + lagStarts.Add(button, 0); + } + } + else + { + _stickySet.Remove(button); + buttonStarts.Remove(button); + lagStarts.Remove(button); + } + } + + public bool IsSticky(string button) + { + return this._stickySet.Contains(button); + } + + public HashSet CurrentStickies + { + get + { + return this._stickySet; + } + } + + public void ClearStickies() + { + _stickySet.Clear(); + buttonStarts.Clear(); + lagStarts.Clear(); + } + + public void MassToggleStickyState(List buttons) + { + foreach (var button in buttons.Where(button => !_justPressed.Contains(button))) + { + if (_stickySet.Contains(button)) + { + _stickySet.Remove(button); + } + else + { + _stickySet.Add(button); + } + } + + _justPressed = buttons; } /// @@ -620,84 +525,182 @@ namespace BizHawk.Client.Common /// public bool StickyIsInEffect(string button) { - if (IsSticky(button)) + if (Source.IsPressed(button)) { - return !Source.IsPressed(button); + return false; } - return false; + return (IsPressed(button)); // Shortcut logic since we know the Source isn't pressed, Ispressed can only return true if the autofire sticky is in effect for this frame } - public void SetSticky(string button, bool isSticky, AutoPatternBool pattern = null) - { - if (isSticky) - { - if (pattern == null) - pattern = new AutoPatternBool(On, Off); - _boolPatterns[button] = pattern; - } - else - { - _boolPatterns.Remove(button); - } - } - - public void Unset(string button) - { - _boolPatterns.Remove(button); - _floatPatterns.Remove(button); - } - - public bool IsSticky(string button) - { - return _boolPatterns.ContainsKey(button) || _floatPatterns.ContainsKey(button); - } - - public HashSet CurrentStickies - { - get - { - return new HashSet(_boolPatterns.Keys); - } - } - - public void ClearStickies() - { - _boolPatterns.Clear(); - _floatPatterns.Clear(); - } - - public void IncrementLoops(bool lagged) - { - for (int i = 0; i < _boolPatterns.Count; i++) - _boolPatterns.ElementAt(i).Value.GetNextValue(lagged); - for (int i = 0; i < _floatPatterns.Count; i++) - _floatPatterns.ElementAt(i).Value.GetNextValue(lagged); - } - - // SuuperW: What does this even do? I set a breakpoint inside the loop and it wasn't reached. - private WorkingDictionary _toggledButtons = new WorkingDictionary(); private List _justPressed = new List(); - public void MassToggleStickyState(List buttons) - { - foreach (var button in buttons.Where(button => !_justPressed.Contains(button))) - { - if (_boolPatterns.ContainsKey(button)) - { - _toggledButtons[button] = _boolPatterns[button]; - SetSticky(button, false); - } - else - { - _boolPatterns[button] = _toggledButtons[button]; - _toggledButtons.Remove(button); - } - } - - _justPressed = buttons; - } } + // commenting this out, it breaks the autofire hotkey + //public class AutoFireStickyXorAdapter : IController, ISticky + //{ + // // TODO: Change the AutoHold adapter to be one of these, with an 'Off' value of 0? + // // Probably would have slightly lower performance, but it seems weird to have such a similar class that is only used once. + // private int On; + // private int Off; + // public void SetOnOffPatternFromConfig() + // { + // On = Global.Config.AutofireOn < 1 ? 0 : Global.Config.AutofireOn; + // Off = Global.Config.AutofireOff < 1 ? 0 : Global.Config.AutofireOff; + // } + + // private WorkingDictionary _boolPatterns = new WorkingDictionary(); + // private WorkingDictionary _floatPatterns = new WorkingDictionary(); + + // public AutoFireStickyXorAdapter() + // { + // On = 1; Off = 1; + // } + + // public IController Source { get; set; } + + // public ControllerDefinition Type + // { + // get { return Source.Type; } + // } + + // public bool Locked { get; set; } // Pretty much a hack, + + // public bool IsPressed(string button) + // { + // return this[button]; + // } + + // public void SetFloat(string name, float? value, AutoPatternFloat pattern = null) + // { + // if (value.HasValue) + // { + // if (pattern == null) + // pattern = new AutoPatternFloat(value.Value, On, 0, Off); + // _floatPatterns[name] = pattern; + // } + // else + // { + // _floatPatterns.Remove(name); + // } + // } + + // public float GetFloat(string name) + // { + // if (_floatPatterns.ContainsKey(name)) + // return _floatPatterns[name].PeekNextValue(); + + // if (Source == null) + // return 0; + + // return Source.GetFloat(name); + // } + + // public void ClearStickyFloats() + // { + // _floatPatterns.Clear(); + // } + + // public bool this[string button] + // { + // get + // { + // var source = Source[button]; + // bool patternValue = false; + // if (_boolPatterns.ContainsKey(button)) + // { // I can't figure a way to determine right here if it should Peek or Get. + // patternValue = _boolPatterns[button].PeekNextValue(); + // } + // source ^= patternValue; + + // return source; + // } + // } + + // /// + // /// Determines if a sticky is current mashing the button itself, + // /// If sticky is not set then false, if set, it returns true if the Source is not pressed, else false + // /// + // public bool StickyIsInEffect(string button) + // { + // if (IsSticky(button)) + // { + // return !Source.IsPressed(button); + // } + + // return false; + // } + + // public void SetSticky(string button, bool isSticky, AutoPatternBool pattern = null) + // { + // if (isSticky) + // { + // if (pattern == null) + // pattern = new AutoPatternBool(On, Off); + // _boolPatterns[button] = pattern; + // } + // else + // { + // _boolPatterns.Remove(button); + // } + // } + + // public void Unset(string button) + // { + // _boolPatterns.Remove(button); + // _floatPatterns.Remove(button); + // } + + // public bool IsSticky(string button) + // { + // return _boolPatterns.ContainsKey(button) || _floatPatterns.ContainsKey(button); + // } + + // public HashSet CurrentStickies + // { + // get + // { + // return new HashSet(_boolPatterns.Keys); + // } + // } + + // public void ClearStickies() + // { + // _boolPatterns.Clear(); + // _floatPatterns.Clear(); + // } + + // public void IncrementLoops(bool lagged) + // { + // for (int i = 0; i < _boolPatterns.Count; i++) + // _boolPatterns.ElementAt(i).Value.GetNextValue(lagged); + // for (int i = 0; i < _floatPatterns.Count; i++) + // _floatPatterns.ElementAt(i).Value.GetNextValue(lagged); + // } + + // // SuuperW: What does this even do? I set a breakpoint inside the loop and it wasn't reached. + // private WorkingDictionary _toggledButtons = new WorkingDictionary(); + // private List _justPressed = new List(); + // public void MassToggleStickyState(List buttons) + // { + // foreach (var button in buttons.Where(button => !_justPressed.Contains(button))) + // { + // if (_boolPatterns.ContainsKey(button)) + // { + // _toggledButtons[button] = _boolPatterns[button]; + // SetSticky(button, false); + // } + // else + // { + // _boolPatterns[button] = _toggledButtons[button]; + // _toggledButtons.Remove(button); + // } + // } + + // _justPressed = buttons; + // } + //} + /// /// Just copies source to sink, or returns whatever a NullController would if it is disconnected. useful for immovable hardpoints. /// diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index c56ac27182..c2c8e9f555 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -2938,7 +2938,7 @@ namespace BizHawk.Client.EmuHawk { Global.AutoFireController.IncrementStarts(); } - Global.AutofireStickyXORAdapter.IncrementLoops(IsLagFrame); + //Global.AutofireStickyXORAdapter.IncrementLoops(IsLagFrame); PressFrameAdvance = false; diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index c7545e1afc..7a8a90b94e 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -298,7 +298,8 @@ namespace BizHawk.Client.EmuHawk else index += controllerType.BoolButtons.Count - 1; AutoPatternBool p = BoolPatterns[index]; - Global.AutofireStickyXORAdapter.SetSticky(button, isOn.Value, p); + // adelikat: I broke it + //Global.AutofireStickyXORAdapter.SetSticky(button, isOn.Value, p); } else { @@ -309,7 +310,8 @@ namespace BizHawk.Client.EmuHawk float? value = null; if (isOn.Value) value = 0f; AutoPatternFloat p = FloatPatterns[index]; - Global.AutofireStickyXORAdapter.SetFloat(button, value, p); + // adelikat: I broke it + //Global.AutofireStickyXORAdapter.SetFloat(button, value, p); } }