From 44bee2df087de447ab9943009149acbff2148220 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Fri, 24 Nov 2023 16:18:55 +0300 Subject: [PATCH] perf: Check If Inputs Have Been Listened On --- Engine.Input/KeyboardInputsBehaviour.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Engine.Input/KeyboardInputsBehaviour.cs b/Engine.Input/KeyboardInputsBehaviour.cs index 55dc232..cb29144 100644 --- a/Engine.Input/KeyboardInputsBehaviour.cs +++ b/Engine.Input/KeyboardInputsBehaviour.cs @@ -59,17 +59,27 @@ public class KeyboardInputsBehaviour : BehaviourOverride, IKeyboardInputs for (int i = 0; i < cachePressedCurrentlyCount; i++) { Keys currentlyPressedKey = cachePressedCurrently[i]; - if (!WasPressed(currentlyPressedKey)) - if (OnPressed.TryGetValue(currentlyPressedKey, out var action)) - action.Invoke(this, currentlyPressedKey); + + if (!OnPressed.TryGetValue(currentlyPressedKey, out var action)) + continue; + + if (WasPressed(currentlyPressedKey)) + continue; + + action.Invoke(this, currentlyPressedKey); } for (int i = 0; i < cachePressedPreviouslyCount; i++) { Keys previouslyPressedKey = cachePressedPreviously[i]; - if (!IsPressed(previouslyPressedKey)) - if (OnReleased.TryGetValue(previouslyPressedKey, out var action)) - action.Invoke(this, previouslyPressedKey); + + if (!OnReleased.TryGetValue(previouslyPressedKey, out var action)) + continue; + + if (IsPressed(previouslyPressedKey)) + continue; + + action.Invoke(this, previouslyPressedKey); } Array.Copy(cachePressedCurrently, cachePressedPreviously, cachePressedCurrentlyCount);