diff options
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(); |
