summaryrefslogtreecommitdiff
path: root/src/player-input.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-05-21 12:06:36 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-05-21 12:06:36 -0400
commitf75a2a682b0a66a6f1fb92395e3e760970c0f99b (patch)
treea8bddce4324ddcad2475ae8c9b4a44e2cd9df338 /src/player-input.cpp
parent957a10c1d6f4ae734905cb7031981dca4cc21980 (diff)
pke: player-input DynArray to pk_arr_t
Diffstat (limited to 'src/player-input.cpp')
-rw-r--r--src/player-input.cpp290
1 files changed, 150 insertions, 140 deletions
diff --git a/src/player-input.cpp b/src/player-input.cpp
index a75daa3..8ecc2cc 100644
--- a/src/player-input.cpp
+++ b/src/player-input.cpp
@@ -1,7 +1,7 @@
#include "player-input.hpp"
-#include "dynamic-array.hpp"
+#include "pk.h"
#include "window.hpp"
#include <GLFW/glfw3.h>
@@ -40,35 +40,33 @@ GLFWwindowfocusfun prevWindowFocusCallback;
TypeSafeInt_B(InputActionSetHandle);
-DynArray<CursorPosEvent> unhandledCursorPosEvents{512, nullptr};
-DynArray<CursorEnterEvent> unhandledCursorEnterEvents{8, nullptr};
-DynArray<KeyEvent> unhandledKeyEvents{8, nullptr};
-DynArray<MouseButtonEvent> unhandledMouseButtonEvents{8, nullptr};
-DynArray<ScrollEvent> unhandledScrollEvents{8, nullptr};
-DynArray<WindowFocusEvent> unhandledWindowFocusEvents{8, nullptr};
+pk_arr_t<CursorPosEvent> unhandledCursorPosEvents{};
+pk_arr_t<CursorEnterEvent> unhandledCursorEnterEvents{};
+pk_arr_t<KeyEvent> unhandledKeyEvents{};
+pk_arr_t<MouseButtonEvent> unhandledMouseButtonEvents{};
+pk_arr_t<ScrollEvent> unhandledScrollEvents{};
+pk_arr_t<WindowFocusEvent> unhandledWindowFocusEvents{};
-DynArray<PkeCursorEnterEvent> registeredCursorEnterEvents{8, nullptr};
+pk_arr_t<PkeCursorEnterEvent> registeredCursorEnterEvents{};
bool lastCursorEntered = false;
-DynArray<PkeCursorPosEvent> registeredCursorPosEvents{8, nullptr};
+pk_arr_t<PkeCursorPosEvent> registeredCursorPosEvents{};
struct {
double x = 0;
double y = 0;
} lastMousePos;
-DynArray<PkeKeyEvent> registeredKeyEvents{8, nullptr};
-DynArray<PkeMouseButtonEvent> registeredMouseButtonEvents{8, nullptr};
-DynArray<PkeScrollEvent> registeredScrollEvents{8, nullptr};
-DynArray<PkeWindowFocusEvent> registeredWindowFocusEvents{8, nullptr};
+pk_arr_t<PkeKeyEvent> registeredKeyEvents{};
+pk_arr_t<PkeMouseButtonEvent> registeredMouseButtonEvents{};
+pk_arr_t<PkeScrollEvent> registeredScrollEvents{};
+pk_arr_t<PkeWindowFocusEvent> registeredWindowFocusEvents{};
bool lastWindowFocus = false;
-// DynArray<PkeInputEvent> UnhandledPkeInputEvents{1024, nullptr};
-
-DynArray<PkeInputSet> registeredInputSets{0, nullptr};
-DynArray<InputActionSetHandle> activeInputSetStack{0, nullptr};
+pk_arr_t<PkeInputSet> registeredInputSets{};
+pk_arr_t<InputActionSetHandle> activeInputSetStack{};
PkeInputAction *FindActionByName(const char *actionName) {
- int64_t count = activeInputSetStack.Count();
- for (int64_t i = count - 1; i >= 0; --i) {
- InputActionSetHandle handle = activeInputSetStack[i];
+ uint32_t count = activeInputSetStack.next;
+ for (uint32_t i = count; i > 0; --i) {
+ InputActionSetHandle handle = activeInputSetStack[i-1];
InputActionSetHandle_T index = static_cast<InputActionSetHandle_T>(handle);
PkeInputSet &set = registeredInputSets[index];
for (int64_t k = 0; k < set.actionCount; ++k) {
@@ -113,28 +111,27 @@ template<InputEventHash T, typename S> InputEventHash FindActivePkeInputAction_B
activeEvent = nullptr;
bool any = false;
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != InputEventHash{0}) {
- any = any || bool(registeredCursorEnterEvents.Count());
+ any = any || bool(registeredCursorEnterEvents.next);
}
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != InputEventHash{0}) {
- any = any || bool(registeredCursorPosEvents.Count());
+ any = any || bool(registeredCursorPosEvents.next);
}
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
- any = any || bool(registeredKeyEvents.Count());
+ any = any || bool(registeredKeyEvents.next);
}
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
- any = any || bool(registeredMouseButtonEvents.Count());
+ any = any || bool(registeredMouseButtonEvents.next);
}
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != InputEventHash{0}) {
- any = any || bool(registeredScrollEvents.Count());
+ any = any || bool(registeredScrollEvents.next);
}
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != InputEventHash{0}) {
- any = any || bool(registeredWindowFocusEvents.Count());
+ any = any || bool(registeredWindowFocusEvents.next);
}
if (any == false) return InputEventHash{0};
- int64_t count = 0;
- count = activeInputSetStack.Count();
- for (int64_t i = count - 1; i >= 0; --i) {
- InputActionSetHandle handle = activeInputSetStack[i];
+ uint32_t count = activeInputSetStack.next;
+ for (uint32_t i = count; i > 0; --i) {
+ InputActionSetHandle handle = activeInputSetStack[i-1];
InputActionSetHandle_T index = static_cast<InputActionSetHandle_T>(handle);
PkeInputSet &set = registeredInputSets[index];
for (int64_t k = 0; k < set.actionCount; ++k) {
@@ -171,31 +168,31 @@ template<InputEventHash T, typename S> InputEventHash FindActivePkeInputAction_B
return InputEventHash{0};
}
template<InputEventHash T, typename S> InputEventHash FindActivePkeInputAction_ByType(const PkeInputEventMask &mask, S *&activeEvent) {
+ uint32_t count, i;
activeEvent = nullptr;
bool any = false;
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != InputEventHash{0}) {
- any = any || bool(registeredCursorEnterEvents.Count());
+ any = any || bool(registeredCursorEnterEvents.next);
}
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != InputEventHash{0}) {
- any = any || bool(registeredCursorPosEvents.Count());
+ any = any || bool(registeredCursorPosEvents.next);
}
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
- any = any || bool(registeredKeyEvents.Count());
+ any = any || bool(registeredKeyEvents.next);
}
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
- any = any || bool(registeredMouseButtonEvents.Count());
+ any = any || bool(registeredMouseButtonEvents.next);
}
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != InputEventHash{0}) {
- any = any || bool(registeredScrollEvents.Count());
+ any = any || bool(registeredScrollEvents.next);
}
if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != InputEventHash{0}) {
- any = any || bool(registeredWindowFocusEvents.Count());
+ any = any || bool(registeredWindowFocusEvents.next);
}
if (any == false) return InputEventHash{0};
- int64_t count = 0;
- count = activeInputSetStack.Count();
- for (int64_t i = count - 1; i >= 0; --i) {
- InputActionSetHandle handle = activeInputSetStack[i];
+ count = activeInputSetStack.next;
+ for (i = count; i > 0; --i) {
+ InputActionSetHandle handle = activeInputSetStack[i-1];
InputActionSetHandle_T index = static_cast<InputActionSetHandle_T>(handle);
PkeInputSet &set = registeredInputSets[index];
for (int64_t k = 0; k < set.actionCount; ++k) {
@@ -267,32 +264,32 @@ constexpr auto FindActivePkeInputAction_WindowFocus_ByType = FindActivePkeInputA
void PkeInput_Tick(double delta) {
(void)delta;
+ uint32_t count, i;
// reset everything
// @performance could happen concurrently
{
- int64_t count = 0;
- count = registeredCursorPosEvents.Count();
- for (int64_t i = 0; i < count; ++i) {
+ count = registeredCursorPosEvents.next;
+ for (i = 0; i < count; ++i) {
auto &ev = registeredCursorPosEvents[i];
ev.xMotion = 0;
ev.yMotion = 0;
}
- count = registeredKeyEvents.Count();
- for (int64_t i = 0; i < count; ++i) {
+ count = registeredKeyEvents.next;
+ for (i = 0; i < count; ++i) {
auto &ev = registeredKeyEvents[i];
// TODO the idea here was right, but wrong place and too wide a swath
// if (i < count - 1) ev.isPressed = false;
ev.thisTick = false;
}
- count = registeredMouseButtonEvents.Count();
- for (int64_t i = 0; i < count; ++i) {
+ count = registeredMouseButtonEvents.next;
+ for (i = 0; i < count; ++i) {
auto &ev = registeredMouseButtonEvents[i];
// TODO the idea here was right, but wrong place and too wide a swath
// if (i < count - 1) ev.isPressed = false;
ev.thisTick = false;
}
- count = registeredScrollEvents.Count();
- for (int64_t i = 0; i < count; ++i) {
+ count = registeredScrollEvents.next;
+ for (i = 0; i < count; ++i) {
auto &ev = registeredScrollEvents[i];
ev.xMotion = 0;
ev.yMotion = 0;
@@ -310,7 +307,7 @@ void PkeInput_Tick(double delta) {
if (primaryEvent == nullptr) {
break;
}
- const auto &ev = unhandledCursorEnterEvents[unhandledCursorEnterEvents.Count() - 1];
+ const auto &ev = unhandledCursorEnterEvents[unhandledCursorEnterEvents.next-1];
primaryEvent->isEntered = ev.entered;
lastCursorEntered = ev.entered;
} while (0);
@@ -322,8 +319,8 @@ void PkeInput_Tick(double delta) {
if (primaryEvent == nullptr) {
break;
}
- int64_t count = unhandledCursorPosEvents.Count();
- for (long i = 0; i < count; ++i) {
+ count = unhandledCursorPosEvents.next;
+ for (i = 0; i < count; ++i) {
const auto &ev = unhandledCursorPosEvents[i];
primaryEvent->xMotion += ev.x - lastMousePos.x;
primaryEvent->yMotion += ev.y - lastMousePos.y;
@@ -332,8 +329,8 @@ void PkeInput_Tick(double delta) {
}
} while (0);
do { // while (0)
- int64_t count = unhandledKeyEvents.Count();
- for (long i = 0; i < count; ++i) {
+ count = unhandledKeyEvents.next;
+ for (i = 0; i < count; ++i) {
const auto &ev = unhandledKeyEvents[i];
PkeKeyEvent *primaryEvent = nullptr;
FindActivePkeInputAction_Key_ByType(PkeInputEventMask {
@@ -357,8 +354,8 @@ void PkeInput_Tick(double delta) {
}
} while (0);
do { // while (0)
- int64_t count = unhandledMouseButtonEvents.Count();
- for (long i = 0; i < count; ++i) {
+ count = unhandledMouseButtonEvents.next;
+ for (i = 0; i < count; ++i) {
const auto &ev = unhandledMouseButtonEvents[i];
PkeMouseButtonEvent *primaryEvent = nullptr;
FindActivePkeInputAction_MouseButton_ByType(PkeInputEventMask {
@@ -386,8 +383,8 @@ void PkeInput_Tick(double delta) {
if (primaryEvent == nullptr) {
break;
}
- int64_t count = unhandledScrollEvents.Count();
- for (long i = 0; i < count; ++i) {
+ count = unhandledScrollEvents.next;
+ for (i = 0; i < count; ++i) {
const auto &ev = unhandledScrollEvents[i];
primaryEvent->xMotion += ev.x;
primaryEvent->yMotion += ev.y;
@@ -401,34 +398,38 @@ void PkeInput_Tick(double delta) {
if (primaryEvent == nullptr) {
break;
}
- const auto &ev = unhandledWindowFocusEvents[unhandledWindowFocusEvents.Count() - 1];
+ const auto &ev = unhandledWindowFocusEvents[unhandledWindowFocusEvents.next-1];
primaryEvent->isFocused = ev.focused;
lastWindowFocus = ev.focused;
} while (0);
}
- unhandledCursorEnterEvents.Resize(0);
- unhandledCursorPosEvents.Resize(0);
- unhandledKeyEvents.Resize(0);
- unhandledMouseButtonEvents.Resize(0);
- unhandledScrollEvents.Resize(0);
- unhandledWindowFocusEvents.Resize(0);
+ pk_arr_reset(&unhandledCursorEnterEvents);
+ pk_arr_reset(&unhandledCursorPosEvents);
+ pk_arr_reset(&unhandledKeyEvents);
+ pk_arr_reset(&unhandledMouseButtonEvents);
+ pk_arr_reset(&unhandledScrollEvents);
+ pk_arr_reset(&unhandledWindowFocusEvents);
// set boolean events with latest data
// - we do this after processing events to make sure that if a set is
// unregistered, the appropriate values are propagated
// - theoretically this scenario could be handled on unregister,
// but I'm not sure which would be more performant
+ // JCB 2025-05-21
+ // I'm refactoring this and it seems to skip the last element.
+ // At a glance, I'm not sure if this is intentional or a bug.
+ // I'm going to preserve this logic in my refactor.
+ // Update this comment as needed and make sure to document the purpose.
{
- int64_t count = 0;
- count = registeredCursorEnterEvents.Count();
- for (int64_t i = 0; i < count - 1; ++i) {
- auto &ev = registeredCursorEnterEvents[i];
- ev.isEntered = lastCursorEntered;
+ count = registeredCursorEnterEvents.next;
+ for (i = 0; i < count; ++i) {
+ registeredCursorEnterEvents[i].isEntered = lastCursorEntered;
+ if (i == count-2) break;
}
- count = registeredWindowFocusEvents.Count();
- for (int64_t i = 0; i < count - 1; ++i) {
- auto &ev = registeredWindowFocusEvents[i];
- ev.isFocused = lastWindowFocus;
+ count = registeredWindowFocusEvents.next;
+ for (i = 0; i < count; ++i) {
+ registeredWindowFocusEvents[i].isFocused = lastWindowFocus;
+ if (i == count-2) break;
}
}
}
@@ -469,9 +470,8 @@ PkeInputEventHolder PkeInput_Query(const char *actionName) {
}
void CursorEnterCallback(GLFWwindow *window, int entered) {
- if (registeredCursorEnterEvents.Count()) {
- auto &ev = unhandledCursorEnterEvents.Push();
- ev.entered = bool(entered);
+ if (registeredCursorEnterEvents.next) {
+ pk_arr_append_t(&unhandledCursorEnterEvents, { .entered = bool(entered) });
}
if (prevCursorEnterCallback) {
prevCursorEnterCallback(window, entered);
@@ -479,10 +479,11 @@ void CursorEnterCallback(GLFWwindow *window, int entered) {
}
void CursorPosCallback(GLFWwindow *window, double xPos, double yPos) {
- if (registeredCursorPosEvents.Count()) {
- auto &ev = unhandledCursorPosEvents.Push();
- ev.x = xPos;
- ev.y = yPos;
+ if (registeredCursorPosEvents.next) {
+ pk_arr_append_t(&unhandledCursorPosEvents, {
+ .x = xPos,
+ .y = yPos,
+ });
}
if (prevCursorPosCallback) {
prevCursorPosCallback(window, xPos, yPos);
@@ -490,11 +491,12 @@ void CursorPosCallback(GLFWwindow *window, double xPos, double yPos) {
}
void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods) {
- if (registeredKeyEvents.Count()) {
- auto &ev = unhandledKeyEvents.Push();
- ev.button = key;
- ev.mods = mods & 0x0F;
- ev.action = action;
+ if (registeredKeyEvents.next) {
+ pk_arr_append_t(&unhandledKeyEvents, {
+ .button = key,
+ .mods = mods & 0x0F,
+ .action = int8_t(action),
+ });
}
if (prevKeyCallback) {
prevKeyCallback(window, key, scancode, action, mods);
@@ -502,11 +504,12 @@ void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods
}
void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods) {
- if (registeredMouseButtonEvents.Count()) {
- auto &ev = unhandledMouseButtonEvents.Push();
- ev.button = button;
- ev.mods = mods;
- ev.action = action;
+ if (registeredMouseButtonEvents.next) {
+ pk_arr_append_t(&unhandledMouseButtonEvents, {
+ .button = button,
+ .mods = mods,
+ .action = int8_t(action),
+ });
}
if (prevMouseButtonCallback) {
prevMouseButtonCallback(window, button, action, mods);
@@ -514,10 +517,11 @@ void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods) {
}
void ScrollCallback(GLFWwindow *window, double xOffset, double yOffset) {
- if (registeredScrollEvents.Count()) {
- auto &ev = unhandledScrollEvents.Push();
- ev.x = xOffset;
- ev.y = yOffset;
+ if (registeredScrollEvents.next) {
+ pk_arr_append_t(&unhandledScrollEvents, {
+ .x = xOffset,
+ .y = yOffset,
+ });
}
if (prevScrollCallback) {
prevScrollCallback(window, xOffset, yOffset);
@@ -525,9 +529,10 @@ void ScrollCallback(GLFWwindow *window, double xOffset, double yOffset) {
}
void WindowFocusCallback(GLFWwindow *window, int focused) {
- if (registeredWindowFocusEvents.Count()) {
- auto &ev = unhandledWindowFocusEvents.Push();
- ev.focused = focused;
+ if (registeredWindowFocusEvents.next) {
+ pk_arr_append_t(&unhandledWindowFocusEvents, {
+ .focused = bool(focused),
+ });
}
if (prevWindowFocusCallback) {
prevWindowFocusCallback(window, focused);
@@ -544,14 +549,14 @@ void PkeInput_Init() {
}
InputActionSetHandle PkeInput_RegisterSet(const PkeInputSet &set) {
- InputActionSetHandle returnValue{static_cast<InputActionSetHandle_T>(registeredInputSets.Count())};
- registeredInputSets.Push(set);
+ InputActionSetHandle returnValue{static_cast<InputActionSetHandle_T>(registeredInputSets.next)};
+ pk_arr_append_t(&registeredInputSets, set);
return returnValue;
}
void PkeInput_ActivateSet(InputActionSetHandle handle) {
InputActionSetHandle_T index{static_cast<InputActionSetHandle_T>(handle)};
- activeInputSetStack.Push(handle);
+ pk_arr_append_t(&activeInputSetStack, handle);
auto &set = registeredInputSets[index];
for (int64_t i = 0; i < set.actionCount; ++i) {
PkeInputAction &action = set.actions[i];
@@ -572,66 +577,67 @@ void PkeInput_ActivateSet(InputActionSetHandle handle) {
// there might be fewer oddities
// Maybe you just have to restrict certain actions to certain input types
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != InputEventHash{0}) {
- action.eventIndex = registeredCursorEnterEvents.Count();
+ action.eventIndex = registeredCursorEnterEvents.next;
PkeCursorEnterEvent ev{};
ev.sourceSet = handle;
ev.isEntered = lastCursorEntered;
- registeredCursorEnterEvents.Push(ev);
+ pk_arr_append_t(&registeredCursorEnterEvents, ev);
}
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != InputEventHash{0}) {
- action.eventIndex = registeredCursorPosEvents.Count();
+ action.eventIndex = registeredCursorPosEvents.next;
PkeCursorPosEvent ev {};
ev.sourceSet = handle;
ev.xMotion = 0;
ev.yMotion = 0;
- registeredCursorPosEvents.Push(ev);
+ pk_arr_append_t(&registeredCursorPosEvents, ev);
glfwGetCursorPos(window, &lastMousePos.x, &lastMousePos.y);
}
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
- action.eventIndex = registeredKeyEvents.Count();
+ action.eventIndex = registeredKeyEvents.next;
PkeKeyEvent ev{};
ev.sourceSet = handle;
ev.button = action.primaryHash.button;
ev.mods = action.primaryHash.mods;
- registeredKeyEvents.Push(ev);
+ pk_arr_append_t(&registeredKeyEvents, ev);
}
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
- action.eventIndex = registeredMouseButtonEvents.Count();
+ action.eventIndex = registeredMouseButtonEvents.next;
PkeMouseButtonEvent ev{};
ev.sourceSet = handle;
ev.button = action.primaryHash.button;
ev.mods = action.primaryHash.mods;
- registeredMouseButtonEvents.Push(ev);
+ pk_arr_append_t(&registeredMouseButtonEvents, ev);
}
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != InputEventHash{0}) {
- action.eventIndex = registeredScrollEvents.Count();
+ action.eventIndex = registeredScrollEvents.next;
PkeScrollEvent ev{};
ev.sourceSet = handle;
ev.xMotion = 0;
ev.yMotion = 0;
- registeredScrollEvents.Push(ev);
+ pk_arr_append_t(&registeredScrollEvents, ev);
}
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != InputEventHash{0}) {
- action.eventIndex = registeredWindowFocusEvents.Count();
+ action.eventIndex = registeredWindowFocusEvents.next;
PkeWindowFocusEvent ev{};
ev.sourceSet = handle;
ev.isFocused = lastWindowFocus;
- registeredWindowFocusEvents.Push(ev);
+ pk_arr_append_t(&registeredWindowFocusEvents, ev);
}
}
}
void PkeInput_DeactivateSet(InputActionSetHandle handle) {
int64_t index = -1;
- auto count = activeInputSetStack.Count();
- for (int64_t i = 0; i < count; ++i) {
+ uint32_t count, i;
+ count = activeInputSetStack.next;
+ for (i = 0; i < count; ++i) {
if (activeInputSetStack[i] == handle) {
index = i;
break;
}
}
assert(index >= 0 && "PkeInput_DeactivateSet - expected InputActionSet to be active");
- assert(index == activeInputSetStack.Count() - 1 && "PkeInput_UnregisterSet - expected InputActionSet to be the last set active");
+ assert(index == activeInputSetStack.next - 1 && "PkeInput_UnregisterSet - expected InputActionSet to be the last set active");
InputActionSetHandle_T handleIndex{static_cast<InputActionSetHandle_T>(handle)};
auto &set = registeredInputSets[handleIndex];
for (int64_t i = set.actionCount - 1; i >= 0; --i) {
@@ -639,36 +645,40 @@ void PkeInput_DeactivateSet(InputActionSetHandle handle) {
// TODO doesn't support multiple masks - how do we align scroll + button
// WITHOUT having two events allocated?
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != InputEventHash{0}) {
- registeredCursorEnterEvents.Remove(action.eventIndex);
+ pk_arr_remove_at(&registeredCursorEnterEvents, action.eventIndex);
}
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != InputEventHash{0}) {
- registeredCursorPosEvents.Remove(action.eventIndex);
+ pk_arr_remove_at(&registeredCursorPosEvents, action.eventIndex);
}
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
- registeredKeyEvents.Remove(action.eventIndex);
+ pk_arr_remove_at(&registeredKeyEvents, action.eventIndex);
}
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
- registeredMouseButtonEvents.Remove(action.eventIndex);
+ pk_arr_remove_at(&registeredMouseButtonEvents, action.eventIndex);
}
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != InputEventHash{0}) {
- registeredScrollEvents.Remove(action.eventIndex);
+ pk_arr_remove_at(&registeredScrollEvents, action.eventIndex);
}
if ((action.primaryHash.computedHash & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != InputEventHash{0}) {
- registeredWindowFocusEvents.Remove(action.eventIndex);
+ pk_arr_remove_at(&registeredWindowFocusEvents, action.eventIndex);
}
}
- activeInputSetStack.Pop();
+ pk_arr_remove_at(&activeInputSetStack, activeInputSetStack.next-1);
+}
+
+bool PkeInput_pke_arr_find_first_handle(void *search_handle, void *list_handle) {
+ return reinterpret_cast<InputActionSetHandle *>(search_handle) == reinterpret_cast<InputActionSetHandle *>(list_handle);
}
void PkeInput_UnregisterSet(InputActionSetHandle handle) {
InputActionSetHandle_T index{static_cast<InputActionSetHandle_T>(handle)};
- assert(index == registeredInputSets.Count() - 1 && "PkeInput_UnregisterSet - expected InputActionSet to be the last set registered");
+ assert(index == registeredInputSets.next - 1 && "PkeInput_UnregisterSet - expected InputActionSet to be the last set registered");
const auto &set = registeredInputSets[index];
- if (activeInputSetStack.Has(handle)) {
+ if (pk_arr_find_first_index(&activeInputSetStack, &handle, PkeInput_pke_arr_find_first_handle) != uint32_t(-1)) {
PkeInput_DeactivateSet(handle);
}
pk_delete<PkeInputAction>(set.actions, set.actionCount);
- registeredInputSets.Remove(index);
+ pk_arr_remove_at(&registeredInputSets, index);
}
void PkeInput_Teardown() {
@@ -678,19 +688,19 @@ void PkeInput_Teardown() {
glfwSetKeyCallback(window, prevKeyCallback);
glfwSetCursorPosCallback(window, prevCursorPosCallback);
glfwSetCursorEnterCallback(window, prevCursorEnterCallback);
- unhandledCursorPosEvents.~DynArray();
- unhandledCursorEnterEvents.~DynArray();
- unhandledKeyEvents.~DynArray();
- unhandledMouseButtonEvents.~DynArray();
- unhandledScrollEvents.~DynArray();
- unhandledWindowFocusEvents.~DynArray();
- registeredCursorEnterEvents.~DynArray();
- registeredCursorPosEvents.~DynArray();
- registeredKeyEvents.~DynArray();
- registeredMouseButtonEvents.~DynArray();
- registeredScrollEvents.~DynArray();
- registeredWindowFocusEvents.~DynArray();
- activeInputSetStack.~DynArray();
- registeredInputSets.~DynArray();
+ pk_arr_reset(&unhandledCursorPosEvents);
+ pk_arr_reset(&unhandledCursorEnterEvents);
+ pk_arr_reset(&unhandledKeyEvents);
+ pk_arr_reset(&unhandledMouseButtonEvents);
+ pk_arr_reset(&unhandledScrollEvents);
+ pk_arr_reset(&unhandledWindowFocusEvents);
+ pk_arr_reset(&registeredCursorEnterEvents);
+ pk_arr_reset(&registeredCursorPosEvents);
+ pk_arr_reset(&registeredKeyEvents);
+ pk_arr_reset(&registeredMouseButtonEvents);
+ pk_arr_reset(&registeredScrollEvents);
+ pk_arr_reset(&registeredWindowFocusEvents);
+ pk_arr_reset(&activeInputSetStack);
+ pk_arr_reset(&registeredInputSets);
}