diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-10-20 09:35:58 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-10-20 09:35:58 -0400 |
| commit | d3d72e3b099ce134a120e6dd1bb106f3e76e3305 (patch) | |
| tree | 9362ee93c908d724bdebf6944de14b95ec954438 /src/player-input.cpp | |
| parent | 7889bdb53b3ec8157c8e0ffe7f4023435d023abf (diff) | |
Remove expired unhandled events
Diffstat (limited to 'src/player-input.cpp')
| -rw-r--r-- | src/player-input.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
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 <chrono> GLFWcursorenterfun prevCursorEnterCallback; GLFWcursorposfun prevCursorPosCallback; @@ -19,7 +20,21 @@ TypeSafeInt_B(InputWindowFocused); DynArray<PkeInputEvent> 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(); |
