summaryrefslogtreecommitdiff
path: root/src/player-input.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/player-input.cpp')
-rw-r--r--src/player-input.cpp602
1 files changed, 295 insertions, 307 deletions
diff --git a/src/player-input.cpp b/src/player-input.cpp
index 2274e70..412be75 100644
--- a/src/player-input.cpp
+++ b/src/player-input.cpp
@@ -6,29 +6,34 @@
#include <GLFW/glfw3.h>
-struct CursorEnterEvent {
- bool entered;
-};
-struct CursorPosEvent {
- double x;
- double y;
-};
-struct KeyEvent {
- int32_t button;
- int32_t mods;
- int8_t action;
-};
-struct MouseButtonEvent {
- int32_t button;
- int32_t mods;
- int8_t action;
-};
-struct ScrollEvent {
- double x;
- double y;
-};
-struct WindowFocusEvent {
- bool focused;
+struct pke_input_unhandled_event {
+ pke_input_event_hash type;
+ union pke_input_unhandled_event_data {
+ struct pke_input_unhandled_event_cursor_enter {
+ bool entered;
+ } cursor_enter;
+ struct pke_input_unhandled_event_cursor_pos {
+ double x;
+ double y;
+ } cursor_pos;
+ struct pke_input_unhandled_event_key {
+ int32_t button;
+ int32_t mods;
+ int8_t action;
+ } key;
+ struct pke_input_unhandled_event_mouse_button {
+ int32_t button;
+ int32_t mods;
+ int8_t action;
+ } mouse_button;
+ struct pke_input_unhandled_event_scroll {
+ double x;
+ double y;
+ } scroll;
+ struct pke_input_unhandled_event_window_focus {
+ bool focused;
+ } window_focus;
+ } data;
};
GLFWcursorenterfun prevCursorEnterCallback;
@@ -38,39 +43,42 @@ GLFWmousebuttonfun prevMouseButtonCallback;
GLFWscrollfun prevScrollCallback;
GLFWwindowfocusfun prevWindowFocusCallback;
-TypeSafeInt_B(InputActionSetHandle);
+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<PkeCursorEnterEvent> registeredCursorEnterEvents{};
+pk_arr_t<pke_input_event> registeredCursorEnterEvents{};
bool lastCursorEntered = false;
-pk_arr_t<PkeCursorPosEvent> registeredCursorPosEvents{};
+pk_arr_t<pke_input_event> registeredCursorPosEvents{};
struct {
double x = 0;
double y = 0;
} lastMousePos;
-pk_arr_t<PkeKeyEvent> registeredKeyEvents{};
-pk_arr_t<PkeMouseButtonEvent> registeredMouseButtonEvents{};
-pk_arr_t<PkeScrollEvent> registeredScrollEvents{};
-pk_arr_t<PkeWindowFocusEvent> registeredWindowFocusEvents{};
+pk_arr_t<pke_input_event> registeredKeyEvents{};
+pk_arr_t<pke_input_event> registeredMouseButtonEvents{};
+pk_arr_t<pke_input_event> registeredScrollEvents{};
+pk_arr_t<pke_input_event> registeredWindowFocusEvents{};
bool lastWindowFocus = false;
-pk_arr_t<PkeInputSet> registeredInputSets{};
-pk_arr_t<InputActionSetHandle> activeInputSetStack{};
+pk_arr_t<pke_input_set> registeredInputSets{};
+pk_arr_t<pke_input_action_set_handle> activeInputSetStack{};
-PkeInputAction *FindActionByName(const char *actionName) {
+pke_input_action *FindActionByName(const char *actionName) {
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];
+ pke_input_action_set_handle handle = activeInputSetStack[i-1];
+ 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) {
- PkeInputAction &inputAction = set.actions[k];
+ pke_input_action &inputAction = set.actions[k];
if (strcmp(actionName, inputAction.name) != 0) {
continue;
};
@@ -79,132 +87,132 @@ PkeInputAction *FindActionByName(const char *actionName) {
}
return nullptr;
}
-template<InputEventHash T, typename S> InputEventHash FindActivePkeInputAction_ByAction(const PkeInputAction *inputAction, S *&activeEvent, int32_t index) {
+template<pke_input_event_hash T, typename S> pke_input_event_hash FindActivepke_input_action_ByAction(const pke_input_action *inputAction, S *&activeEvent, int32_t index) {
activeEvent = nullptr;
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != pke_input_event_hash{0}) {
activeEvent = &registeredCursorEnterEvents[inputAction->event_indices[index]];
return PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != pke_input_event_hash{0}) {
activeEvent = &registeredCursorPosEvents[inputAction->event_indices[index]];
return PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != pke_input_event_hash{0}) {
activeEvent = &registeredKeyEvents[inputAction->event_indices[index]];
return PKE_INPUT_HASH_EVENT_TYPE_KEY;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != pke_input_event_hash{0}) {
activeEvent = &registeredMouseButtonEvents[inputAction->event_indices[index]];
return PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != pke_input_event_hash{0}) {
activeEvent = &registeredScrollEvents[inputAction->event_indices[index]];
return PKE_INPUT_HASH_EVENT_TYPE_SCROLL;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != pke_input_event_hash{0}) {
activeEvent = &registeredWindowFocusEvents[inputAction->event_indices[index]];
return PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS;
}
- return InputEventHash{0};
+ return pke_input_event_hash{0};
}
/*
-template<InputEventHash T, typename S> InputEventHash FindActivePkeInputAction_ByName(const char *actionName, S *&activeEvent) {
+template<pke_input_event_hash T, typename S> pke_input_event_hash FindActivepke_input_action_ByName(const char *actionName, S *&activeEvent) {
activeEvent = nullptr;
bool any = false;
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != pke_input_event_hash{0}) {
any = any || bool(registeredCursorEnterEvents.next);
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != pke_input_event_hash{0}) {
any = any || bool(registeredCursorPosEvents.next);
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != pke_input_event_hash{0}) {
any = any || bool(registeredKeyEvents.next);
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != pke_input_event_hash{0}) {
any = any || bool(registeredMouseButtonEvents.next);
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != pke_input_event_hash{0}) {
any = any || bool(registeredScrollEvents.next);
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != pke_input_event_hash{0}) {
any = any || bool(registeredWindowFocusEvents.next);
}
- if (any == false) return InputEventHash{0};
+ if (any == false) return pke_input_event_hash{0};
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];
+ pke_input_action_set_handle handle = activeInputSetStack[i-1];
+ 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) {
- PkeInputAction &inputAction = set.actions[k];
+ pke_input_action &inputAction = set.actions[k];
if (strcmp(actionName, inputAction.name) != 0) {
continue;
};
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != pke_input_event_hash{0}) {
activeEvent = &registeredCursorEnterEvents[inputAction.eventIndex];
return PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != pke_input_event_hash{0}) {
activeEvent = &registeredCursorPosEvents[inputAction.eventIndex];
return PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != pke_input_event_hash{0}) {
activeEvent = &registeredKeyEvents[inputAction.eventIndex];
return PKE_INPUT_HASH_EVENT_TYPE_KEY;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != pke_input_event_hash{0}) {
activeEvent = &registeredMouseButtonEvents[inputAction.eventIndex];
return PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != pke_input_event_hash{0}) {
activeEvent = &registeredScrollEvents[inputAction.eventIndex];
return PKE_INPUT_HASH_EVENT_TYPE_SCROLL;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != pke_input_event_hash{0}) {
activeEvent = &registeredWindowFocusEvents[inputAction.eventIndex];
return PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS;
}
}
}
- return InputEventHash{0};
+ return pke_input_event_hash{0};
}
*/
-template<InputEventHash T, typename S> InputEventHash FindActivePkeInputAction_ByType(const PkeInputEventMask &mask, S *&activeEvent) {
+template<pke_input_event_hash T> pke_input_event_hash FindActivepke_input_action_ByType(const pke_input_event_mask &mask, pke_input_event *&activeEvent) {
uint32_t count, i;
activeEvent = nullptr;
bool any = false;
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != pke_input_event_hash{0}) {
any = any || bool(registeredCursorEnterEvents.next);
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != pke_input_event_hash{0}) {
any = any || bool(registeredCursorPosEvents.next);
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != pke_input_event_hash{0}) {
any = any || bool(registeredKeyEvents.next);
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != pke_input_event_hash{0}) {
any = any || bool(registeredMouseButtonEvents.next);
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != pke_input_event_hash{0}) {
any = any || bool(registeredScrollEvents.next);
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != pke_input_event_hash{0}) {
any = any || bool(registeredWindowFocusEvents.next);
}
- if (any == false) return InputEventHash{0};
+ if (any == false) return pke_input_event_hash{0};
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];
+ pke_input_action_set_handle handle = activeInputSetStack[i-1];
+ 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) {
- PkeInputAction &inputAction = set.actions[k];
+ pke_input_action &inputAction = set.actions[k];
for (int64_t l = 0; l < PKE_INPUT_ACTION_MASK_INDEX_COUNT; ++l) {
- PkeInputEventMask &evMask = inputAction.masks[l];
- if ((evMask.computedHash & mask.computedHash) == InputEventHash{0}) {
+ pke_input_event_mask &evMask = inputAction.masks[l];
+ if ((evMask.computedHash & mask.computedHash) == pke_input_event_hash{0}) {
continue;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != pke_input_event_hash{0}) {
if (evMask.button != mask.button) {
continue;
}
@@ -212,7 +220,7 @@ template<InputEventHash T, typename S> InputEventHash FindActivePkeInputAction_B
continue;
}
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != pke_input_event_hash{0}) {
if (evMask.button != mask.button) {
continue;
}
@@ -220,51 +228,51 @@ template<InputEventHash T, typename S> InputEventHash FindActivePkeInputAction_B
continue;
}
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != pke_input_event_hash{0}) {
activeEvent = &registeredCursorEnterEvents[inputAction.event_indices[l]];
return PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != pke_input_event_hash{0}) {
activeEvent = &registeredCursorPosEvents[inputAction.event_indices[l]];
return PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_KEY) != pke_input_event_hash{0}) {
activeEvent = &registeredKeyEvents[inputAction.event_indices[l]];
return PKE_INPUT_HASH_EVENT_TYPE_KEY;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != pke_input_event_hash{0}) {
activeEvent = &registeredMouseButtonEvents[inputAction.event_indices[l]];
return PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != pke_input_event_hash{0}) {
activeEvent = &registeredScrollEvents[inputAction.event_indices[l]];
return PKE_INPUT_HASH_EVENT_TYPE_SCROLL;
}
- if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != InputEventHash{0}) {
+ if constexpr((T & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != pke_input_event_hash{0}) {
activeEvent = &registeredWindowFocusEvents[inputAction.event_indices[l]];
return PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS;
}
}
}
}
- return InputEventHash{0};
+ return pke_input_event_hash{0};
}
-constexpr auto FindActivePkeInputAction_CursorEnter_ByType = FindActivePkeInputAction_ByType<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER, PkeCursorEnterEvent>;
-constexpr auto FindActivePkeInputAction_CursorPos_ByType = FindActivePkeInputAction_ByType<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS, PkeCursorPosEvent>;
-constexpr auto FindActivePkeInputAction_Key_ByType = FindActivePkeInputAction_ByType<PKE_INPUT_HASH_EVENT_TYPE_KEY, PkeKeyEvent>;
-constexpr auto FindActivePkeInputAction_MouseButton_ByType = FindActivePkeInputAction_ByType<PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON, PkeMouseButtonEvent>;
-constexpr auto FindActivePkeInputAction_Scroll_ByType = FindActivePkeInputAction_ByType<PKE_INPUT_HASH_EVENT_TYPE_SCROLL, PkeScrollEvent>;
-constexpr auto FindActivePkeInputAction_WindowFocus_ByType = FindActivePkeInputAction_ByType<PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS, PkeWindowFocusEvent>;
+constexpr auto FindActivepke_input_action_CursorEnter_ByType = FindActivepke_input_action_ByType<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER>;
+constexpr auto FindActivepke_input_action_CursorPos_ByType = FindActivepke_input_action_ByType<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS>;
+constexpr auto FindActivepke_input_action_Key_ByType = FindActivepke_input_action_ByType<PKE_INPUT_HASH_EVENT_TYPE_KEY>;
+constexpr auto FindActivepke_input_action_MouseButton_ByType = FindActivepke_input_action_ByType<PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON>;
+constexpr auto FindActivepke_input_action_Scroll_ByType = FindActivepke_input_action_ByType<PKE_INPUT_HASH_EVENT_TYPE_SCROLL>;
+constexpr auto FindActivepke_input_action_WindowFocus_ByType = FindActivepke_input_action_ByType<PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS>;
-// constexpr auto FindActivePkeInputAction_CursorEnter_ByName = FindActivePkeInputAction_ByName<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER, PkeCursorEnterEvent>;
-// constexpr auto FindActivePkeInputAction_CursorPos_ByName = FindActivePkeInputAction_ByName<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS, PkeCursorPosEvent>;
-// constexpr auto FindActivePkeInputAction_Key_ByName = FindActivePkeInputAction_ByName<PKE_INPUT_HASH_EVENT_TYPE_KEY, PkeKeyEvent>;
-// constexpr auto FindActivePkeInputAction_MouseButton_ByName = FindActivePkeInputAction_ByName<PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON, PkeMouseButtonEvent>;
-// constexpr auto FindActivePkeInputAction_Scroll_ByName = FindActivePkeInputAction_ByName<PKE_INPUT_HASH_EVENT_TYPE_SCROLL, PkeScrollEvent>;
-// constexpr auto FindActivePkeInputAction_WindowFocus_ByName = FindActivePkeInputAction_ByName<PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS, PkeWindowFocusEvent>;
+// constexpr auto FindActivepke_input_action_CursorEnter_ByName = FindActivepke_input_action_ByName<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER, PkeCursorEnterEvent>;
+// constexpr auto FindActivepke_input_action_CursorPos_ByName = FindActivepke_input_action_ByName<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS, PkeCursorPosEvent>;
+// constexpr auto FindActivepke_input_action_Key_ByName = FindActivepke_input_action_ByName<PKE_INPUT_HASH_EVENT_TYPE_KEY, PkeKeyEvent>;
+// constexpr auto FindActivepke_input_action_MouseButton_ByName = FindActivepke_input_action_ByName<PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON, PkeMouseButtonEvent>;
+// constexpr auto FindActivepke_input_action_Scroll_ByName = FindActivepke_input_action_ByName<PKE_INPUT_HASH_EVENT_TYPE_SCROLL, PkeScrollEvent>;
+// constexpr auto FindActivepke_input_action_WindowFocus_ByName = FindActivepke_input_action_ByName<PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS, PkeWindowFocusEvent>;
-void PkeInput_Tick(double delta) {
+void pke_input_tick(double delta) {
(void)delta;
uint32_t count, i;
// reset everything
@@ -273,144 +281,112 @@ void PkeInput_Tick(double delta) {
count = registeredCursorPosEvents.next;
for (i = 0; i < count; ++i) {
auto &ev = registeredCursorPosEvents[i];
- ev.xMotion = 0;
- ev.yMotion = 0;
+ ev.data.cursor_pos.xMotion = 0;
+ ev.data.cursor_pos.yMotion = 0;
}
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;
+ ev.data.key.thisTick = false;
}
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;
+ ev.data.mouse_button.thisTick = false;
}
count = registeredScrollEvents.next;
for (i = 0; i < count; ++i) {
auto &ev = registeredScrollEvents[i];
- ev.xMotion = 0;
- ev.yMotion = 0;
+ ev.data.scroll.xMotion = 0;
+ ev.data.scroll.yMotion = 0;
}
}
// handle unhandled events
// @performance cache action->event results
- {
- do { // while (0)
- PkeCursorEnterEvent *primaryEvent = nullptr;
- FindActivePkeInputAction_CursorEnter_ByType(PkeInputEventMask {
- .computedHash = PKE_INPUT_HASH_ALL_CURSOR_ENTER_EVENTS
- }, primaryEvent);
- if (primaryEvent == nullptr) {
+ // 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];
+ switch (uh_ev.type) {
+ case PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER:
+ FindActivepke_input_action_CursorEnter_ByType(pke_input_event_mask {
+ .computedHash = PKE_INPUT_HASH_ALL_CURSOR_ENTER_EVENTS
+ }, primary_event);
+ if (primary_event == nullptr) continue;
+ primary_event->data.cursor_enter.isEntered = uh_ev.data.cursor_enter.entered;
+ lastCursorEntered = uh_ev.data.cursor_enter.entered;
break;
- }
- const auto &ev = unhandledCursorEnterEvents[unhandledCursorEnterEvents.next-1];
- primaryEvent->isEntered = ev.entered;
- lastCursorEntered = ev.entered;
- } while (0);
- do { // while (0)
- PkeCursorPosEvent *primaryEvent = nullptr;
- FindActivePkeInputAction_CursorPos_ByType(PkeInputEventMask {
- .computedHash = PKE_INPUT_HASH_ALL_CURSOR_POS_EVENTS
- }, primaryEvent);
- if (primaryEvent == nullptr) {
+ case PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS:
+ FindActivepke_input_action_CursorPos_ByType(pke_input_event_mask {
+ .computedHash = PKE_INPUT_HASH_ALL_CURSOR_POS_EVENTS
+ }, primary_event);
+ if (primary_event == nullptr) continue;
+ primary_event->data.cursor_pos.xMotion += uh_ev.data.cursor_pos.x - lastMousePos.x;
+ primary_event->data.cursor_pos.yMotion += uh_ev.data.cursor_pos.y - lastMousePos.y;
+ lastMousePos.x = uh_ev.data.cursor_pos.x;
+ lastMousePos.y = uh_ev.data.cursor_pos.y;
break;
- }
- 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;
- lastMousePos.x = ev.x;
- lastMousePos.y = ev.y;
- }
- } while (0);
- do { // while (0)
- count = unhandledKeyEvents.next;
- for (i = 0; i < count; ++i) {
- const auto &ev = unhandledKeyEvents[i];
- PkeKeyEvent *primaryEvent = nullptr;
- FindActivePkeInputAction_Key_ByType(PkeInputEventMask {
+ case PKE_INPUT_HASH_EVENT_TYPE_KEY:
+ FindActivepke_input_action_Key_ByType(pke_input_event_mask {
.computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS,
- .button = ev.button,
- .mods = ev.mods,
- }, primaryEvent);
- if (primaryEvent == nullptr) {
- continue;
- }
- if (ev.action == GLFW_PRESS) {
- primaryEvent->isPressed = true;
- primaryEvent->thisTick = true;
- } else if (ev.action == GLFW_RELEASE) {
- primaryEvent->isPressed = false;
- primaryEvent->thisTick = true;
+ .button = uh_ev.data.key.button,
+ .mods = uh_ev.data.key.mods,
+ }, primary_event);
+ if (primary_event == nullptr) continue;
+ if (uh_ev.data.key.action == GLFW_PRESS) {
+ primary_event->data.key.isPressed = true;
+ primary_event->data.key.thisTick = true;
+ } else if (uh_ev.data.key.action == GLFW_RELEASE) {
+ primary_event->data.key.isPressed = false;
+ primary_event->data.key.thisTick = true;
} else {
// repeat
- primaryEvent->isPressed = true;
+ primary_event->data.key.isPressed = true;
}
- }
- } while (0);
- do { // while (0)
- count = unhandledMouseButtonEvents.next;
- for (i = 0; i < count; ++i) {
- const auto &ev = unhandledMouseButtonEvents[i];
- PkeMouseButtonEvent *primaryEvent = nullptr;
- FindActivePkeInputAction_MouseButton_ByType(PkeInputEventMask {
+ break;
+ case PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON:
+ FindActivepke_input_action_MouseButton_ByType(pke_input_event_mask {
.computedHash = PKE_INPUT_HASH_ALL_MOUSE_BUTTON_EVENTS,
- .button = ev.button,
- .mods = ev.mods,
- }, primaryEvent);
- if (primaryEvent == nullptr) {
- continue;
+ .button = uh_ev.data.mouse_button.button,
+ .mods = uh_ev.data.mouse_button.mods,
+ }, primary_event);
+ if (primary_event == nullptr) continue;
+ if (uh_ev.data.mouse_button.action == GLFW_PRESS) {
+ primary_event->data.mouse_button.isPressed = true;
+ primary_event->data.mouse_button.thisTick = true;
+ } else if (uh_ev.data.mouse_button.action == GLFW_RELEASE) {
+ primary_event->data.mouse_button.isPressed = false;
+ primary_event->data.mouse_button.thisTick = true;
}
- if (ev.action == GLFW_PRESS) {
- primaryEvent->isPressed = true;
- primaryEvent->thisTick = true;
- } else if (ev.action == GLFW_RELEASE) {
- primaryEvent->isPressed = false;
- primaryEvent->thisTick = true;
- }
- }
- } while (0);
- do { // while (0)
- PkeScrollEvent *primaryEvent = nullptr;
- FindActivePkeInputAction_Scroll_ByType(PkeInputEventMask {
- .computedHash = PKE_INPUT_HASH_ALL_SCROLL_EVENTS
- }, primaryEvent);
- if (primaryEvent == nullptr) {
break;
- }
- count = unhandledScrollEvents.next;
- for (i = 0; i < count; ++i) {
- const auto &ev = unhandledScrollEvents[i];
- primaryEvent->xMotion += ev.x;
- primaryEvent->yMotion += ev.y;
- }
- } while (0);
- do { // while (0)
- PkeWindowFocusEvent *primaryEvent = nullptr;
- FindActivePkeInputAction_WindowFocus_ByType(PkeInputEventMask {
- .computedHash = PKE_INPUT_HASH_ALL_WINDOW_FOCUS_EVENTS
- }, primaryEvent);
- if (primaryEvent == nullptr) {
+ case PKE_INPUT_HASH_EVENT_TYPE_SCROLL:
+ FindActivepke_input_action_Scroll_ByType(pke_input_event_mask {
+ .computedHash = PKE_INPUT_HASH_ALL_SCROLL_EVENTS
+ }, primary_event);
+ if (primary_event == nullptr) continue;
+ primary_event->data.scroll.xMotion += uh_ev.data.scroll.x;
+ primary_event->data.scroll.yMotion += uh_ev.data.scroll.y;
break;
- }
- const auto &ev = unhandledWindowFocusEvents[unhandledWindowFocusEvents.next-1];
- primaryEvent->isFocused = ev.focused;
- lastWindowFocus = ev.focused;
- } while (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);
+ case PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS:
+ FindActivepke_input_action_WindowFocus_ByType(pke_input_event_mask {
+ .computedHash = PKE_INPUT_HASH_ALL_WINDOW_FOCUS_EVENTS
+ }, primary_event);
+ if (primary_event == nullptr) continue;
+ primary_event->data.window_focus.isFocused = uh_ev.data.window_focus.focused;
+ lastWindowFocus = uh_ev.data.window_focus.focused;
+ break;
+ default:
+ fprintf(stderr, "[pke_input_tick] Unknown unhandled input type: %i", pke_input_event_hash_T(uh_ev.type));
+ break;
+ }
+ }
+ pk_arr_reset(&unhandled_events);
// set boolean events with latest data
// - we do this after processing events to make sure that if a set is
@@ -425,64 +401,49 @@ void PkeInput_Tick(double delta) {
{
count = registeredCursorEnterEvents.next;
for (i = 0; i < count; ++i) {
- registeredCursorEnterEvents[i].isEntered = lastCursorEntered;
+ registeredCursorEnterEvents[i].data.cursor_enter.isEntered = lastCursorEntered;
if (i == count-2) break;
}
count = registeredWindowFocusEvents.next;
for (i = 0; i < count; ++i) {
- registeredWindowFocusEvents[i].isFocused = lastWindowFocus;
+ registeredWindowFocusEvents[i].data.window_focus.isFocused = lastWindowFocus;
if (i == count-2) break;
}
}
}
-PkeInputEventHolder PkeInput_Query(const char *actionName) {
- PkeInputEventBase *ev = nullptr;
+const pke_input_event *pke_input_query_by_action_name(const char *actionName) {
+ pke_input_event *ev = nullptr;
auto *action = FindActionByName(actionName);
- InputEventHash type = InputEventHash{0};
+ if (action == nullptr) return nullptr;
for (int32_t i = 0; i < PKE_INPUT_ACTION_MASK_INDEX_COUNT; ++i) {
- PkeInputEventMask event_mask = action->masks[i];
+ pke_input_event_mask event_mask = action->masks[i];
if (bool(event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER)) {
- PkeCursorEnterEvent *event;
- type = FindActivePkeInputAction_ByAction<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER, PkeCursorEnterEvent>(action, event, i);
- ev = event;
+ FindActivepke_input_action_ByAction<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER>(action, ev, i);
break;
} else if (bool(event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS)) {
- PkeCursorPosEvent *event;
- type = FindActivePkeInputAction_ByAction<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS, PkeCursorPosEvent>(action, event, i);
- ev = event;
+ FindActivepke_input_action_ByAction<PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS>(action, ev, i);
break;
} else if (bool(event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_KEY)) {
- PkeKeyEvent *event;
- type = FindActivePkeInputAction_ByAction<PKE_INPUT_HASH_EVENT_TYPE_KEY, PkeKeyEvent>(action, event, i);
- ev = event;
+ FindActivepke_input_action_ByAction<PKE_INPUT_HASH_EVENT_TYPE_KEY>(action, ev, i);
break;
} else if (bool(event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON)) {
- PkeMouseButtonEvent *event;
- type = FindActivePkeInputAction_ByAction<PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON, PkeMouseButtonEvent>(action, event, i);
- ev = event;
+ FindActivepke_input_action_ByAction<PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON>(action, ev, i);
break;
} else if (bool(event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_SCROLL)) {
- PkeScrollEvent *event;
- type = FindActivePkeInputAction_ByAction<PKE_INPUT_HASH_EVENT_TYPE_SCROLL, PkeScrollEvent>(action, event, i);
- ev = event;
+ FindActivepke_input_action_ByAction<PKE_INPUT_HASH_EVENT_TYPE_SCROLL>(action, ev, i);
break;
} else if (bool(event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS)) {
- PkeWindowFocusEvent *event;
- type = FindActivePkeInputAction_ByAction<PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS, PkeWindowFocusEvent>(action, event, i);
- ev = event;
+ FindActivepke_input_action_ByAction<PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS>(action, ev, i);
break;
}
}
- return PkeInputEventHolder {
- .type = type,
- .ptr = ev,
- };
+ return ev;
}
void CursorEnterCallback(GLFWwindow *window, int entered) {
if (registeredCursorEnterEvents.next) {
- pk_arr_append_t(&unhandledCursorEnterEvents, { .entered = bool(entered) });
+ pk_arr_append_t(&unhandled_events, { .type = PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER, .data = { .cursor_enter = { .entered = bool(entered) } } });
}
if (prevCursorEnterCallback) {
prevCursorEnterCallback(window, entered);
@@ -491,9 +452,15 @@ void CursorEnterCallback(GLFWwindow *window, int entered) {
void CursorPosCallback(GLFWwindow *window, double xPos, double yPos) {
if (registeredCursorPosEvents.next) {
- pk_arr_append_t(&unhandledCursorPosEvents, {
- .x = xPos,
- .y = yPos,
+ pk_arr_append_t(&unhandled_events,
+ {
+ .type = PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS,
+ .data = {
+ .cursor_pos = {
+ .x = xPos,
+ .y = yPos,
+ },
+ },
});
}
if (prevCursorPosCallback) {
@@ -503,10 +470,15 @@ void CursorPosCallback(GLFWwindow *window, double xPos, double yPos) {
void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods) {
if (registeredKeyEvents.next) {
- pk_arr_append_t(&unhandledKeyEvents, {
- .button = key,
- .mods = mods & 0x0F,
- .action = int8_t(action),
+ pk_arr_append_t(&unhandled_events, {
+ .type = PKE_INPUT_HASH_EVENT_TYPE_KEY,
+ .data = {
+ .key = {
+ .button = key,
+ .mods = mods & 0x0F,
+ .action = int8_t(action),
+ },
+ },
});
}
if (prevKeyCallback) {
@@ -516,10 +488,15 @@ void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods
void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods) {
if (registeredMouseButtonEvents.next) {
- pk_arr_append_t(&unhandledMouseButtonEvents, {
- .button = button,
- .mods = mods,
- .action = int8_t(action),
+ pk_arr_append_t(&unhandled_events, {
+ .type = PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON,
+ .data = {
+ .mouse_button = {
+ .button = button,
+ .mods = mods,
+ .action = int8_t(action),
+ },
+ },
});
}
if (prevMouseButtonCallback) {
@@ -529,9 +506,14 @@ void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods) {
void ScrollCallback(GLFWwindow *window, double xOffset, double yOffset) {
if (registeredScrollEvents.next) {
- pk_arr_append_t(&unhandledScrollEvents, {
- .x = xOffset,
- .y = yOffset,
+ pk_arr_append_t(&unhandled_events, {
+ .type = PKE_INPUT_HASH_EVENT_TYPE_SCROLL,
+ .data = {
+ .scroll = {
+ .x = xOffset,
+ .y = yOffset,
+ },
+ },
});
}
if (prevScrollCallback) {
@@ -541,8 +523,13 @@ void ScrollCallback(GLFWwindow *window, double xOffset, double yOffset) {
void WindowFocusCallback(GLFWwindow *window, int focused) {
if (registeredWindowFocusEvents.next) {
- pk_arr_append_t(&unhandledWindowFocusEvents, {
- .focused = bool(focused),
+ pk_arr_append_t(&unhandled_events, {
+ .type = PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS,
+ .data = {
+ .window_focus = {
+ .focused = bool(focused),
+ },
+ },
});
}
if (prevWindowFocusCallback) {
@@ -550,7 +537,7 @@ void WindowFocusCallback(GLFWwindow *window, int focused) {
}
}
-void PkeInput_Init() {
+void pke_input_init() {
prevCursorEnterCallback = glfwSetCursorEnterCallback(window, CursorEnterCallback);
prevCursorPosCallback = glfwSetCursorPosCallback(window, CursorPosCallback);
prevKeyCallback = glfwSetKeyCallback(window, KeyCallback);
@@ -559,72 +546,78 @@ void PkeInput_Init() {
prevWindowFocusCallback = glfwSetWindowFocusCallback(window, WindowFocusCallback);
}
-InputActionSetHandle PkeInput_RegisterSet(const PkeInputSet &set) {
- InputActionSetHandle returnValue{static_cast<InputActionSetHandle_T>(registeredInputSets.next)};
+pke_input_action_set_handle pke_input_register_set(const pke_input_set &set) {
+ pke_input_action_set_handle returnValue{static_cast<pke_input_action_set_handle_T>(registeredInputSets.next)};
pk_arr_append_t(&registeredInputSets, set);
return returnValue;
}
-void PkeInput_ActivateSet(InputActionSetHandle handle) {
- InputActionSetHandle_T index{static_cast<InputActionSetHandle_T>(handle)};
+void pke_input_activate_set(pke_input_action_set_handle handle) {
+ pke_input_action_set_handle_T index{static_cast<pke_input_action_set_handle_T>(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];
+ pke_input_action &action = set.actions[i];
for (int k = 0; k < PKE_INPUT_ACTION_MASK_INDEX_COUNT; ++k) {
- PkeInputEventMask event_mask = action.masks[k];
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != InputEventHash{0}) {
+ pke_input_event_mask event_mask = action.masks[k];
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != pke_input_event_hash{0}) {
action.event_indices[k] = registeredCursorEnterEvents.next;
- PkeCursorEnterEvent ev{};
+ pke_input_event ev{};
ev.sourceSet = handle;
- ev.isEntered = lastCursorEntered;
+ ev.type = PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER;
+ ev.data.cursor_enter.isEntered = lastCursorEntered;
pk_arr_append_t(&registeredCursorEnterEvents, ev);
}
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != InputEventHash{0}) {
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != pke_input_event_hash{0}) {
action.event_indices[k] = registeredCursorPosEvents.next;
- PkeCursorPosEvent ev {};
+ pke_input_event ev {};
ev.sourceSet = handle;
- ev.xMotion = 0;
- ev.yMotion = 0;
+ ev.type = PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS;
+ ev.data.cursor_pos.xMotion = 0;
+ ev.data.cursor_pos.yMotion = 0;
pk_arr_append_t(&registeredCursorPosEvents, ev);
glfwGetCursorPos(window, &lastMousePos.x, &lastMousePos.y);
}
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_KEY) != pke_input_event_hash{0}) {
action.event_indices[k] = registeredKeyEvents.next;
- PkeKeyEvent ev{};
+ pke_input_event ev{};
ev.sourceSet = handle;
- ev.button = event_mask.button;
- ev.mods = event_mask.mods;
+ ev.type = PKE_INPUT_HASH_EVENT_TYPE_KEY;
+ ev.data.key.button = event_mask.button;
+ ev.data.key.mods = event_mask.mods;
pk_arr_append_t(&registeredKeyEvents, ev);
}
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != pke_input_event_hash{0}) {
action.event_indices[k] = registeredMouseButtonEvents.next;
- PkeMouseButtonEvent ev{};
+ pke_input_event ev{};
ev.sourceSet = handle;
- ev.button = event_mask.button;
- ev.mods = event_mask.mods;
+ ev.type = PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON;
+ ev.data.mouse_button.button = event_mask.button;
+ ev.data.mouse_button.mods = event_mask.mods;
pk_arr_append_t(&registeredMouseButtonEvents, ev);
}
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != InputEventHash{0}) {
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != pke_input_event_hash{0}) {
action.event_indices[k] = registeredScrollEvents.next;
- PkeScrollEvent ev{};
+ pke_input_event ev{};
ev.sourceSet = handle;
- ev.xMotion = 0;
- ev.yMotion = 0;
+ ev.type = PKE_INPUT_HASH_EVENT_TYPE_SCROLL;
+ ev.data.scroll.xMotion = 0;
+ ev.data.scroll.yMotion = 0;
pk_arr_append_t(&registeredScrollEvents, ev);
}
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != InputEventHash{0}) {
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != pke_input_event_hash{0}) {
action.event_indices[k] = registeredWindowFocusEvents.next;
- PkeWindowFocusEvent ev{};
+ pke_input_event ev{};
ev.sourceSet = handle;
- ev.isFocused = lastWindowFocus;
+ ev.type = PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS;
+ ev.data.window_focus.isFocused = lastWindowFocus;
pk_arr_append_t(&registeredWindowFocusEvents, ev);
}
}
}
}
-void PkeInput_DeactivateSet(InputActionSetHandle handle) {
+void pke_input_deactivate_set(pke_input_action_set_handle handle) {
int64_t index = -1;
uint32_t count, i;
count = activeInputSetStack.next;
@@ -634,30 +627,30 @@ void PkeInput_DeactivateSet(InputActionSetHandle handle) {
break;
}
}
- assert(index >= 0 && "PkeInput_DeactivateSet - expected InputActionSet to be active");
- assert(index == activeInputSetStack.next - 1 && "PkeInput_UnregisterSet - expected InputActionSet to be the last set active");
- InputActionSetHandle_T handleIndex{static_cast<InputActionSetHandle_T>(handle)};
+ 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");
+ 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) {
- PkeInputAction &action = set.actions[i];
+ pke_input_action &action = set.actions[i];
for (int k = 0; k < PKE_INPUT_ACTION_MASK_INDEX_COUNT; ++k) {
- PkeInputEventMask event_mask = action.masks[k];
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != InputEventHash{0}) {
+ pke_input_event_mask event_mask = action.masks[k];
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER) != pke_input_event_hash{0}) {
pk_arr_remove_at(&registeredCursorEnterEvents, action.event_indices[k]);
}
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != InputEventHash{0}) {
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS) != pke_input_event_hash{0}) {
pk_arr_remove_at(&registeredCursorPosEvents, action.event_indices[k]);
}
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_KEY) != InputEventHash{0}) {
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_KEY) != pke_input_event_hash{0}) {
pk_arr_remove_at(&registeredKeyEvents, action.event_indices[k]);
}
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != InputEventHash{0}) {
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON) != pke_input_event_hash{0}) {
pk_arr_remove_at(&registeredMouseButtonEvents, action.event_indices[k]);
}
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != InputEventHash{0}) {
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_SCROLL) != pke_input_event_hash{0}) {
pk_arr_remove_at(&registeredScrollEvents, action.event_indices[k]);
}
- if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != InputEventHash{0}) {
+ if ((event_mask.computedHash & PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS) != pke_input_event_hash{0}) {
pk_arr_remove_at(&registeredWindowFocusEvents, action.event_indices[k]);
}
}
@@ -666,37 +659,32 @@ void PkeInput_DeactivateSet(InputActionSetHandle handle) {
}
bool PkeInput_pke_arr_find_first_handle(void *search_handle, void *list_handle) {
- return reinterpret_cast<InputActionSetHandle *>(search_handle) == reinterpret_cast<InputActionSetHandle *>(list_handle);
+ return reinterpret_cast<pke_input_action_set_handle *>(search_handle) == reinterpret_cast<pke_input_action_set_handle *>(list_handle);
}
-void PkeInput_UnregisterSet(InputActionSetHandle handle) {
- InputActionSetHandle_T index{static_cast<InputActionSetHandle_T>(handle)};
- assert(index == registeredInputSets.next - 1 && "PkeInput_UnregisterSet - expected InputActionSet to be the last set registered");
+void pke_input_unregister_set(pke_input_action_set_handle handle) {
+ pke_input_action_set_handle_T index{static_cast<pke_input_action_set_handle_T>(handle)};
+ assert(index == registeredInputSets.next - 1 && "pke_input_unregister_set - expected InputActionSet to be the last set registered");
const auto &set = registeredInputSets[index];
if (pk_arr_find_first_index(&activeInputSetStack, &handle, PkeInput_pke_arr_find_first_handle) != uint32_t(-1)) {
- PkeInput_DeactivateSet(handle);
+ pke_input_deactivate_set(handle);
}
- pk_delete_arr<PkeInputAction>(set.actions, set.actionCount);
+ pk_delete_arr<pke_input_action>(set.actions, set.actionCount);
pk_arr_remove_at(&registeredInputSets, index);
}
-pk_arr_t<PkeInputSet> &PkeInput_GetInputSets() {
+pk_arr_t<pke_input_set> &pke_input_get_input_sets() {
return registeredInputSets;
}
-void PkeInput_Teardown() {
+void pke_input_teardown() {
glfwSetWindowFocusCallback(window, prevWindowFocusCallback);
glfwSetScrollCallback(window, prevScrollCallback);
glfwSetMouseButtonCallback(window, prevMouseButtonCallback);
glfwSetKeyCallback(window, prevKeyCallback);
glfwSetCursorPosCallback(window, prevCursorPosCallback);
glfwSetCursorEnterCallback(window, prevCursorEnterCallback);
- 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(&unhandled_events);
pk_arr_reset(&registeredCursorEnterEvents);
pk_arr_reset(&registeredCursorPosEvents);
pk_arr_reset(&registeredKeyEvents);