From f7d860cee74ad3b94e0d15ea157783b7760f6d55 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Thu, 31 Jul 2025 15:15:16 -0400 Subject: pke-ui: detect mouse clicks, other small refactors --- src/player-input.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/player-input.cpp') 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 unhandled_events; -/* nocheckin -pk_arr_t unhandledCursorPosEvents{}; -pk_arr_t unhandledCursorEnterEvents{}; -pk_arr_t unhandledKeyEvents{}; -pk_arr_t unhandledMouseButtonEvents{}; -pk_arr_t unhandledScrollEvents{}; -pk_arr_t unhandledWindowFocusEvents{}; -*/ pk_arr_t 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(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 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(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(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(set.actions, set.actionCount); + if (set.actions != nullptr) { + pk_delete_arr(set.actions, set.actionCount); + } pk_arr_remove_at(®isteredInputSets, index); } -- cgit v1.2.3