summaryrefslogtreecommitdiff
path: root/src/player-input.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-07-31 15:15:16 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-07-31 15:15:16 -0400
commitf7d860cee74ad3b94e0d15ea157783b7760f6d55 (patch)
treec2d37ae18a4ce1a63da4010516ecc588bfb7903a /src/player-input.cpp
parent8dbacba532e05d76325392d85a75906f2de12350 (diff)
pke-ui: detect mouse clicks, other small refactors
Diffstat (limited to 'src/player-input.cpp')
-rw-r--r--src/player-input.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/player-input.cpp b/src/player-input.cpp
index 2bf412c..29297ab 100644
--- a/src/player-input.cpp
+++ b/src/player-input.cpp
@@ -46,14 +46,6 @@ GLFWwindowfocusfun prevWindowFocusCallback;
TypeSafeInt_B(pke_input_action_set_handle);
pk_arr_t<pke_input_unhandled_event> unhandled_events;
-/* nocheckin
-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{};
-*/
pk_arr_t<pke_input_event> registeredCursorEnterEvents{};
bool lastCursorEntered = false;
@@ -75,6 +67,7 @@ pke_input_action *FindActionByName(const char *actionName) {
uint32_t count = activeInputSetStack.next;
for (uint32_t i = count; i > 0; --i) {
pke_input_action_set_handle handle = activeInputSetStack[i-1];
+ if (handle == pke_input_action_set_handle_MAX) continue;
pke_input_action_set_handle_T index = static_cast<pke_input_action_set_handle_T>(handle);
pke_input_set &set = registeredInputSets[index];
for (int64_t k = 0; k < set.actionCount; ++k) {
@@ -203,6 +196,7 @@ template<pke_input_event_hash T> pke_input_event_hash FindActivepke_input_action
count = activeInputSetStack.next;
for (i = count; i > 0; --i) {
pke_input_action_set_handle handle = activeInputSetStack[i-1];
+ if (handle == pke_input_action_set_handle_MAX) continue;
pke_input_action_set_handle_T index = static_cast<pke_input_action_set_handle_T>(handle);
pke_input_set &set = registeredInputSets[index];
for (int64_t k = 0; k < set.actionCount; ++k) {
@@ -309,7 +303,6 @@ void pke_input_tick(double delta) {
// handle unhandled events
// @performance cache action->event results
// 2025-07-23 JCB I'm not sure what this perf message means.
- // I am in the process of refactoring this.
pke_input_event *primary_event = nullptr;
for (i = 0; i < unhandled_events.next; ++i) {
pke_input_unhandled_event &uh_ev = unhandled_events[i];
@@ -670,8 +663,10 @@ void pke_input_deactivate_set(pke_input_action_set_handle handle) {
break;
}
}
- assert(index >= 0 && "pke_input_deactivate_set - expected InputActionSet to be active");
- assert(index == activeInputSetStack.next - 1 && "pke_input_unregister_set - expected InputActionSet to be the last set active");
+ if (index == 0) {
+ fprintf(stderr, "[pke_input] Attempt to deactivate a non-active set.\n");
+ return;
+ }
pke_input_action_set_handle_T handleIndex{static_cast<pke_input_action_set_handle_T>(handle)};
auto &set = registeredInputSets[handleIndex];
for (int64_t i = set.actionCount - 1; i >= 0; --i) {
@@ -698,7 +693,7 @@ void pke_input_deactivate_set(pke_input_action_set_handle handle) {
}
}
}
- pk_arr_remove_at(&activeInputSetStack, activeInputSetStack.next-1);
+ pk_arr_remove_at(&activeInputSetStack, index);
}
bool PkeInput_pke_arr_find_first_handle(void *search_handle, void *list_handle) {
@@ -712,7 +707,9 @@ void pke_input_unregister_set(pke_input_action_set_handle handle) {
if (pk_arr_find_first_index(&activeInputSetStack, &handle, PkeInput_pke_arr_find_first_handle) != uint32_t(-1)) {
pke_input_deactivate_set(handle);
}
- pk_delete_arr<pke_input_action>(set.actions, set.actionCount);
+ if (set.actions != nullptr) {
+ pk_delete_arr<pke_input_action>(set.actions, set.actionCount);
+ }
pk_arr_remove_at(&registeredInputSets, index);
}