From d3d72e3b099ce134a120e6dd1bb106f3e76e3305 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Fri, 20 Oct 2023 09:35:58 -0400 Subject: Remove expired unhandled events --- src/player-input.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/player-input.cpp') diff --git a/src/player-input.cpp b/src/player-input.cpp index 4b34fdd..8392619 100644 --- a/src/player-input.cpp +++ b/src/player-input.cpp @@ -2,6 +2,7 @@ #include "player-input.hpp" #include "window.hpp" #include "game-settings.hpp" +#include GLFWcursorenterfun prevCursorEnterCallback; GLFWcursorposfun prevCursorPosCallback; @@ -19,7 +20,21 @@ TypeSafeInt_B(InputWindowFocused); DynArray UnhandledPkeInputEvents{0, nullptr}; -void PkeInput_Tick() { } +void PkeInput_Tick(double delta) { + // If we haven't handled an event within two seconds, we probably don't need it + static GameTimeDuration eventExpiration(std::chrono::seconds(2)); + int64_t removeCount = 0; + int64_t unhandledCount = UnhandledPkeInputEvents.Count(); + auto expiredTime = pkeSettings.steadyClock.now() - eventExpiration; + for (int64_t i = 0; i < unhandledCount; ++i) { + if (UnhandledPkeInputEvents[i].timePoint < expiredTime) { + removeCount += 1; + continue; + } + break; + } + UnhandledPkeInputEvents.Remove(0, removeCount); +} void CursorEnterCallback(GLFWwindow *window, int entered) { auto &ev = UnhandledPkeInputEvents.Push(); -- cgit v1.2.3