summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game.cpp8
-rw-r--r--src/main.cpp1
-rw-r--r--src/player-input.cpp17
-rw-r--r--src/player-input.hpp2
4 files changed, 23 insertions, 5 deletions
diff --git a/src/game.cpp b/src/game.cpp
index a0be182..4540d9e 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -1,13 +1,14 @@
#include "game.hpp"
-#include "helpers.hpp"
#include "components.hpp"
-#include "entities.hpp"
#include "dynamic-array.hpp"
+#include "entities.hpp"
+#include "game-settings.hpp"
+#include "helpers.hpp"
#include "imgui.h"
+#include "player-input.hpp"
#include "vendor/glm_include.hpp"
-#include "game-settings.hpp"
#include <cstring>
#include <iomanip>
@@ -359,6 +360,7 @@ void Game_Tick(double delta) {
EntityHandle newEntity = ECS_CreateEntity();
ECS_CreateInstance(newEntity, createInfo.entityTypeEntityHandle);
}
+ PkeInput_Tick(delta);
static double accDelta = 0.0;
accDelta += delta;
UBO.model = glm::rotate(glm::mat4(1.0f), (float)accDelta * glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
diff --git a/src/main.cpp b/src/main.cpp
index f77dee7..e5d82fe 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -125,6 +125,7 @@ int main() {
Game_Teardown();
Event_Teardown();
EntityType_Teardown();
+ PkeInput_Teardown();
ECS_Teardown();
AM_DebugPrint();
AM_Teardown();
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();
diff --git a/src/player-input.hpp b/src/player-input.hpp
index c6429eb..baa4327 100644
--- a/src/player-input.hpp
+++ b/src/player-input.hpp
@@ -50,7 +50,7 @@ struct PkeInputEvent {
int32_t mods;
};
-void PkeInput_Tick();
+void PkeInput_Tick(double delta);
void PkeInput_Init();
void PkeInput_Teardown();