Skip to content

Commit

Permalink
Merge pull request #301 from amazingalek/tai/BlockingFix
Browse files Browse the repository at this point in the history
fixed buttons not getting blocked when they should
  • Loading branch information
TAImatem authored Aug 3, 2020
2 parents 17d20c1 + 98b1944 commit 57e2ea8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions OWML.ModHelper.Input/ModInputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ModInputHandler : IModInputHandler
private readonly HashSet<IModInputCombination> _singlesPressed = new HashSet<IModInputCombination>();
private readonly Dictionary<long, HashSet<IModInputCombination>> _comboRegistry = new Dictionary<long, HashSet<IModInputCombination>>();
private readonly HashSet<IModInputCombination> _toResetOnNextFrame = new HashSet<IModInputCombination>();
private readonly float[] _timeout = new float[ModInputLibrary.MaxUsefulKey];
private readonly int[] _blockedFrame = new int[ModInputLibrary.MaxUsefulKey];
private readonly int[] _gameBindingCounter = new int[ModInputLibrary.MaxUsefulKey];
private HashSet<IModInputCombination> _currentCombinations = new HashSet<IModInputCombination>();
private int _lastSingleUpdate;
Expand Down Expand Up @@ -56,7 +56,7 @@ internal bool IsPressedAndIgnored(KeyCode key)
var cleanKey = ModInputLibrary.NormalizeKeyCode(key);
return UnityEngine.Input.GetKey(cleanKey) &&
_currentCombinations.Count > 0 &&
Time.realtimeSinceStartup - _timeout[(int)cleanKey] < Cooldown;
(Time.frameCount - _blockedFrame[(int)cleanKey]) * Time.deltaTime < Cooldown;
}

private long? GetHashFromKeyboard()
Expand All @@ -76,7 +76,7 @@ internal bool IsPressedAndIgnored(KeyCode key)
return null;
}
hash = hash * ModInputLibrary.MaxUsefulKey + code;
if (Time.realtimeSinceStartup - _timeout[code] > Cooldown)
if ((Time.frameCount - _blockedFrame[code]) * Time.deltaTime > Cooldown)
{
countdownTrigger = false;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ private HashSet<IModInputCombination> GetCombinationsFromKeyboard()

while (hash > 0)
{
_timeout[hash % ModInputLibrary.MaxUsefulKey] = Time.realtimeSinceStartup;
_blockedFrame[hash % ModInputLibrary.MaxUsefulKey] = Time.frameCount;
hash /= ModInputLibrary.MaxUsefulKey;
}
return combinations;
Expand Down

0 comments on commit 57e2ea8

Please sign in to comment.