summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-07-24 11:41:01 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-07-24 11:41:01 -0400
commit13bb74998afda740bf61df8ddd14c76539937a3b (patch)
tree2f28c733810b5aa8dcb262178834623b11b6d76a /src
parent5e341340de5259acdb119866dc6819a81ed0ca84 (diff)
pke: pke_input_event fat struct refactor
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp6
-rw-r--r--src/player-input.cpp602
-rw-r--r--src/player-input.hpp153
-rw-r--r--src/scene-types.hpp2
-rw-r--r--src/scene.cpp8
-rw-r--r--src/scene.hpp2
-rw-r--r--src/serialization-input.cpp40
-rw-r--r--src/serialization-input.hpp4
-rw-r--r--src/serialization.cpp2
9 files changed, 403 insertions, 416 deletions
diff --git a/src/game.cpp b/src/game.cpp
index edcfecc..aea1039 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -98,7 +98,7 @@ void Game_Tick(double delta) {
EntityType_Tick(delta);
ECS_Tick(delta);
- PkeInput_Tick(delta);
+ pke_input_tick(delta);
pke_ui_tick(delta);
FontType_Tick(delta);
@@ -132,7 +132,7 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) {
pke_scene_master_init();
CreateWindow(windowProps);
EntityType_Init();
- PkeInput_Init();
+ pke_input_init();
pke_ui_init();
pke_ui_init_bindings();
FontType_Init();
@@ -308,7 +308,7 @@ GAME_SHUTDOWN:
EntityType_Teardown();
FontType_Teardown();
pke_ui_teardown();
- PkeInput_Teardown();
+ pke_input_teardown();
pke_scene_master_teardown();
pke_level_teardown();
PkeCamera_Teardown();
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);
diff --git a/src/player-input.hpp b/src/player-input.hpp
index abb8a40..2e8517c 100644
--- a/src/player-input.hpp
+++ b/src/player-input.hpp
@@ -5,95 +5,94 @@
#include <cstdint>
-TypeSafeInt_H(InputActionSetHandle, uint8_t, 0xFF);
-TypeSafeInt_constexpr(InputActionSetFlags, uint8_t, 0xFF);
-TypeSafeInt_constexpr(InputEventHash, uint16_t, 0xFFFF);
+TypeSafeInt_H(pke_input_action_set_handle, uint8_t, 0xFF);
+TypeSafeInt_constexpr(pke_input_action_set_flag, uint8_t, 0xFF);
+TypeSafeInt_constexpr(pke_input_event_hash, uint16_t, 0xFFFF);
-constexpr InputActionSetFlags PKE_INPUT_ACTION_SET_FLAG_NONE = InputActionSetFlags{0x00};
-constexpr InputActionSetFlags PKE_INPUT_ACTION_SET_FLAG_DO_NOT_SERIALIZE = InputActionSetFlags{0x01};
-constexpr InputActionSetFlags PKE_INPUT_ACTION_SET_FLAG_AUTO_ENABLE = InputActionSetFlags{0x02};
+constexpr pke_input_action_set_flag PKE_INPUT_ACTION_SET_FLAG_NONE = pke_input_action_set_flag{0x00};
+constexpr pke_input_action_set_flag PKE_INPUT_ACTION_SET_FLAG_DO_NOT_SERIALIZE = pke_input_action_set_flag{0x01};
+constexpr pke_input_action_set_flag PKE_INPUT_ACTION_SET_FLAG_AUTO_ENABLE = pke_input_action_set_flag{0x02};
-const InputEventHash PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER = InputEventHash {0x0001};
-const InputEventHash PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS = InputEventHash {0x0002};
-const InputEventHash PKE_INPUT_HASH_EVENT_TYPE_KEY = InputEventHash {0x0004};
-const InputEventHash PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON = InputEventHash {0x0008};
-const InputEventHash PKE_INPUT_HASH_EVENT_TYPE_SCROLL = InputEventHash {0x0010};
-const InputEventHash PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS = InputEventHash {0x0020};
-const InputEventHash PKE_INPUT_HASH_CURSOR_ENTERED_FALSE = InputEventHash {0x0040};
-const InputEventHash PKE_INPUT_HASH_CURSOR_ENTERED_TRUE = InputEventHash {0x0080};
-const InputEventHash PKE_INPUT_HASH_KEYBOARD_KEY_ACTION_RELEASE = InputEventHash{0x0100};
-const InputEventHash PKE_INPUT_HASH_KEYBOARD_KEY_ACTION_PRESS = InputEventHash {0x0200};
-const InputEventHash PKE_INPUT_HASH_KEYBOARD_KEY_ACTION_REPEAT = InputEventHash {0x0400};
-const InputEventHash PKE_INPUT_HASH_MOUSE_BUTTON_ACTION_RELEASE = InputEventHash{0x0800};
-const InputEventHash PKE_INPUT_HASH_MOUSE_BUTTON_ACTION_PRESS = InputEventHash {0x1000};
-const InputEventHash PKE_INPUT_HASH_WINDOW_FOCUSED_FALSE = InputEventHash {0x2000};
-const InputEventHash PKE_INPUT_HASH_WINDOW_FOCUSED_TRUE = InputEventHash {0x4000};
+const pke_input_event_hash PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER = pke_input_event_hash {0x0001};
+const pke_input_event_hash PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS = pke_input_event_hash {0x0002};
+const pke_input_event_hash PKE_INPUT_HASH_EVENT_TYPE_KEY = pke_input_event_hash {0x0004};
+const pke_input_event_hash PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON = pke_input_event_hash {0x0008};
+const pke_input_event_hash PKE_INPUT_HASH_EVENT_TYPE_SCROLL = pke_input_event_hash {0x0010};
+const pke_input_event_hash PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS = pke_input_event_hash {0x0020};
+const pke_input_event_hash PKE_INPUT_HASH_CURSOR_ENTERED_FALSE = pke_input_event_hash {0x0040};
+const pke_input_event_hash PKE_INPUT_HASH_CURSOR_ENTERED_TRUE = pke_input_event_hash {0x0080};
+const pke_input_event_hash PKE_INPUT_HASH_KEYBOARD_KEY_ACTION_RELEASE = pke_input_event_hash{0x0100};
+const pke_input_event_hash PKE_INPUT_HASH_KEYBOARD_KEY_ACTION_PRESS = pke_input_event_hash {0x0200};
+const pke_input_event_hash PKE_INPUT_HASH_KEYBOARD_KEY_ACTION_REPEAT = pke_input_event_hash {0x0400};
+const pke_input_event_hash PKE_INPUT_HASH_MOUSE_BUTTON_ACTION_RELEASE = pke_input_event_hash{0x0800};
+const pke_input_event_hash PKE_INPUT_HASH_MOUSE_BUTTON_ACTION_PRESS = pke_input_event_hash {0x1000};
+const pke_input_event_hash PKE_INPUT_HASH_WINDOW_FOCUSED_FALSE = pke_input_event_hash {0x2000};
+const pke_input_event_hash PKE_INPUT_HASH_WINDOW_FOCUSED_TRUE = pke_input_event_hash {0x4000};
-const InputEventHash PKE_INPUT_HASH_ALL_EVENTS =
+const pke_input_event_hash PKE_INPUT_HASH_ALL_EVENTS =
PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER
| PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS
| PKE_INPUT_HASH_EVENT_TYPE_KEY
| PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON
| PKE_INPUT_HASH_EVENT_TYPE_SCROLL
| PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS;
-const InputEventHash PKE_INPUT_HASH_ALL_CURSOR_ENTER_EVENTS =
+const pke_input_event_hash PKE_INPUT_HASH_ALL_CURSOR_ENTER_EVENTS =
PKE_INPUT_HASH_EVENT_TYPE_CURSOR_ENTER
| PKE_INPUT_HASH_CURSOR_ENTERED_FALSE
| PKE_INPUT_HASH_CURSOR_ENTERED_TRUE;
-const InputEventHash PKE_INPUT_HASH_ALL_CURSOR_POS_EVENTS =
+const pke_input_event_hash PKE_INPUT_HASH_ALL_CURSOR_POS_EVENTS =
PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS;
-const InputEventHash PKE_INPUT_HASH_ALL_KEY_EVENTS =
+const pke_input_event_hash PKE_INPUT_HASH_ALL_KEY_EVENTS =
PKE_INPUT_HASH_EVENT_TYPE_KEY
| PKE_INPUT_HASH_KEYBOARD_KEY_ACTION_RELEASE
| PKE_INPUT_HASH_KEYBOARD_KEY_ACTION_PRESS
| PKE_INPUT_HASH_KEYBOARD_KEY_ACTION_REPEAT;
-const InputEventHash PKE_INPUT_HASH_ALL_MOUSE_BUTTON_EVENTS =
+const pke_input_event_hash PKE_INPUT_HASH_ALL_MOUSE_BUTTON_EVENTS =
PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON
| PKE_INPUT_HASH_MOUSE_BUTTON_ACTION_RELEASE
| PKE_INPUT_HASH_MOUSE_BUTTON_ACTION_PRESS;
-const InputEventHash PKE_INPUT_HASH_ALL_SCROLL_EVENTS =
+const pke_input_event_hash PKE_INPUT_HASH_ALL_SCROLL_EVENTS =
PKE_INPUT_HASH_EVENT_TYPE_SCROLL;
-const InputEventHash PKE_INPUT_HASH_ALL_WINDOW_FOCUS_EVENTS =
+const pke_input_event_hash PKE_INPUT_HASH_ALL_WINDOW_FOCUS_EVENTS =
PKE_INPUT_HASH_EVENT_TYPE_WINDOW_FOCUS
| PKE_INPUT_HASH_WINDOW_FOCUSED_FALSE
- | PKE_INPUT_HASH_WINDOW_FOCUSED_FALSE;
+ | PKE_INPUT_HASH_WINDOW_FOCUSED_TRUE;
-struct PkeInputEventBase {
- InputActionSetHandle sourceSet;
-};
-struct PkeInputEventHolder {
- InputEventHash type = InputEventHash{0};
- PkeInputEventBase *ptr = nullptr;
-};
-struct PkeCursorEnterEvent : public PkeInputEventBase {
- bool isEntered;
-};
-struct PkeCursorPosEvent : public PkeInputEventBase {
- double xMotion;
- double yMotion;
-};
-struct PkeKeyEvent : public PkeInputEventBase {
- bool isPressed;
- bool thisTick;
- int32_t button;
- int32_t mods;
-};
-struct PkeMouseButtonEvent : public PkeInputEventBase {
- bool isPressed;
- bool thisTick;
- int32_t button;
- int32_t mods;
-};
-struct PkeScrollEvent : public PkeInputEventBase {
- double xMotion;
- double yMotion;
-};
-struct PkeWindowFocusEvent : public PkeInputEventBase {
- bool isFocused;
+struct pke_input_event {
+ pke_input_action_set_handle sourceSet;
+ pke_input_event_hash type;
+ union pke_input_event_data {
+ struct pke_input_event_cursor_enter {
+ bool isEntered;
+ } cursor_enter;
+ struct pke_input_event_cursor_pos {
+ double xMotion;
+ double yMotion;
+ } cursor_pos;
+ struct pke_input_event_key {
+ bool isPressed;
+ bool thisTick;
+ int32_t button;
+ int32_t mods;
+ } key;
+ struct pke_input_event_mouse_button {
+ bool isPressed;
+ bool thisTick;
+ int32_t button;
+ int32_t mods;
+ } mouse_button;
+ struct pke_input_event_scroll {
+ double xMotion;
+ double yMotion;
+ } scroll;
+ struct pke_input_event_window_focus {
+ bool isFocused;
+ } window_focus;
+ } data;
};
-struct PkeInputEventMask {
- InputEventHash computedHash = InputEventHash{0};
+struct pke_input_event_mask {
+ pke_input_event_hash computedHash = pke_input_event_hash{0};
int32_t button = -1;
int32_t mods = 0;
};
@@ -101,26 +100,26 @@ struct PkeInputEventMask {
#define PKE_INPUT_ACTION_MASK_INDEX_PRIMARY 0
#define PKE_INPUT_ACTION_MASK_INDEX_SECONDARY 1
#define PKE_INPUT_ACTION_MASK_INDEX_COUNT 2
-struct PkeInputAction {
+struct pke_input_action {
const char *name;
- PkeInputEventMask masks[2] = {{},{}};
+ pke_input_event_mask masks[2] = {{},{}};
int32_t event_indices[2] = {-1,-1};
};
-struct PkeInputSet {
+struct pke_input_set {
const char *title;
int64_t actionCount;
- PkeInputAction *actions;
- InputActionSetFlags flags;
+ pke_input_action *actions;
+ pke_input_action_set_flag flags;
};
-void PkeInput_Tick(double delta);
-PkeInputEventHolder PkeInput_Query(const char *actionName);
-void PkeInput_Init();
-InputActionSetHandle PkeInput_RegisterSet(const PkeInputSet &set);
-void PkeInput_ActivateSet(InputActionSetHandle handle);
-void PkeInput_DeactivateSet(InputActionSetHandle handle);
-void PkeInput_UnregisterSet(InputActionSetHandle handle);
-pk_arr_t<PkeInputSet> &PkeInput_GetInputSets();
-void PkeInput_Teardown();
+void pke_input_tick(double delta);
+const pke_input_event *pke_input_query_by_action_name(const char *actionName);
+void pke_input_init();
+pke_input_action_set_handle pke_input_register_set(const pke_input_set &set);
+void pke_input_activate_set(pke_input_action_set_handle handle);
+void pke_input_deactivate_set(pke_input_action_set_handle handle);
+void pke_input_unregister_set(pke_input_action_set_handle handle);
+pk_arr_t<pke_input_set> &pke_input_get_input_sets();
+void pke_input_teardown();
#endif /* PKE_PLAYER_INPUT_HPP */
diff --git a/src/scene-types.hpp b/src/scene-types.hpp
index d010d12..9caea6e 100644
--- a/src/scene-types.hpp
+++ b/src/scene-types.hpp
@@ -14,7 +14,7 @@ struct pke_scene : public Entity_Base {
char name[SCENE_NAME_MAX_LEN] = {'\0'};
SceneHandle scene_handle = SceneHandle_MAX;
pk_arr_t<CameraHandle> cameras;
- pk_arr_t<InputActionSetHandle> input_handles;
+ pk_arr_t<pke_input_action_set_handle> input_handles;
};
#endif /* PKE_SCENE_TYPES_HPP */
diff --git a/src/scene.cpp b/src/scene.cpp
index 6674c7f..5d0b096 100644
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -97,8 +97,8 @@ void pke_scene_remove(SceneHandle handle) {
PkeCamera_Destroy(scn->cameras[i]);
}
for (i = 0; i < scn->input_handles.next; ++i) {
- PkeInput_DeactivateSet(scn->input_handles[i]);
- PkeInput_UnregisterSet(scn->input_handles[i]);
+ pke_input_deactivate_set(scn->input_handles[i]);
+ pke_input_unregister_set(scn->input_handles[i]);
}
if (scn->file_path.reserved > 0) {
pk_delete_arr<char>(scn->file_path.val, scn->file_path.reserved);
@@ -119,9 +119,9 @@ void pke_scene_register_camera(SceneHandle scene_handle, CameraHandle cameraHand
pk_arr_append(&scene->cameras, &cameraHandle);
}
-void pke_scene_register_input_action_set(SceneHandle scene_handle, InputActionSetHandle handle) {
+void pke_scene_register_input_action_set(SceneHandle scene_handle, pke_input_action_set_handle handle) {
assert(scene_handle != SceneHandle_MAX);
- assert(handle != InputActionSetHandle_MAX);
+ assert(handle != pke_input_action_set_handle_MAX);
pke_scene *scene = pke_scene_get_by_handle(scene_handle);
assert(scene != nullptr && "Failed to find scene by requested SceneHandle");
pk_arr_append_t(&scene->input_handles, handle);
diff --git a/src/scene.hpp b/src/scene.hpp
index 6c80b39..0a1e9ce 100644
--- a/src/scene.hpp
+++ b/src/scene.hpp
@@ -16,6 +16,6 @@ pk_bkt_arr *pke_scene_get_scenes();
void pke_scene_remove(SceneHandle handle);
void pke_scene_register_camera(SceneHandle scene_handle, CameraHandle cameraHandle);
-void pke_scene_register_input_action_set(SceneHandle scene_handle, InputActionSetHandle handle);
+void pke_scene_register_input_action_set(SceneHandle scene_handle, pke_input_action_set_handle handle);
#endif /* PKE_SCENE_HPP */
diff --git a/src/serialization-input.cpp b/src/serialization-input.cpp
index eb44389..c4c5cc3 100644
--- a/src/serialization-input.cpp
+++ b/src/serialization-input.cpp
@@ -7,7 +7,7 @@
#include <cstring>
-pk_handle pke_serialize_input_action(srlztn_serialize_helper *h, PkeInputAction *action) {
+pk_handle pke_serialize_input_action(srlztn_serialize_helper *h, pke_input_action *action) {
char *s;
int len;
pke_kve kve{};
@@ -21,7 +21,7 @@ pk_handle pke_serialize_input_action(srlztn_serialize_helper *h, PkeInputAction
kvec.child_handles.bkt = h->bkt;
h->handle_head.itemIndex++;
- compt_a<40==sizeof(PkeInputAction)>();
+ compt_a<40==sizeof(pke_input_action)>();
{
kve.key = SRLZTN_INPUT_ACTION_NAME;
len = strlen(action->name)+1;
@@ -32,14 +32,14 @@ pk_handle pke_serialize_input_action(srlztn_serialize_helper *h, PkeInputAction
pk_arr_append_t(&kvec.arr, kve);
}
for (int i = 0; i < PKE_INPUT_ACTION_MASK_INDEX_COUNT; ++i) {
- if (action->masks[i].computedHash == InputEventHash{0}) {
+ if (action->masks[i].computedHash == pke_input_event_hash{0}) {
continue;
}
{
kve.key = SRLZTN_INPUT_ACTION_MASK_HASH;
- len = snprintf(NULL, 0, "0x%.4hX", static_cast<InputEventHash_T>(action->masks[i].computedHash));
+ len = snprintf(NULL, 0, "0x%.4hX", static_cast<pke_input_event_hash_T>(action->masks[i].computedHash));
s = pk_new_arr<char>(len+1, h->bkt);
- sprintf(s, "0x%.4hX", static_cast<InputEventHash_T>(action->masks[i].computedHash));
+ sprintf(s, "0x%.4hX", static_cast<pke_input_event_hash_T>(action->masks[i].computedHash));
kve.val = s;
kve.end = SRLZTN_KVE_END;
pk_arr_append_t(&kvec.arr, kve);
@@ -68,7 +68,7 @@ pk_handle pke_serialize_input_action(srlztn_serialize_helper *h, PkeInputAction
return kvec.srlztn_handle;
}
-void pke_deserialize_input_action(srlztn_deserialize_helper *h, pke_kve_container *kvec, PkeInputAction &action) {
+void pke_deserialize_input_action(srlztn_deserialize_helper *h, pke_kve_container *kvec, pke_input_action &action) {
(void)h;
uint32_t i;
int32_t mask_index = -1;
@@ -76,7 +76,7 @@ void pke_deserialize_input_action(srlztn_deserialize_helper *h, pke_kve_containe
pke_kve *kve = nullptr;
PK_STN_RES stn_res = PK_STN_RES(0);
- compt_a<40==sizeof(PkeInputAction)>();
+ compt_a<40==sizeof(pke_input_action)>();
for (i = 0; i < kvec->arr.next; ++i) {
kve = &kvec->arr[i];
if (strncmp(kve->key, SRLZTN_INPUT_ACTION_NAME, strlen(SRLZTN_INPUT_ACTION_NAME)) == 0) {
@@ -89,13 +89,13 @@ void pke_deserialize_input_action(srlztn_deserialize_helper *h, pke_kve_containe
if (strncmp(kve->key, SRLZTN_INPUT_ACTION_MASK_HASH, strlen(SRLZTN_INPUT_ACTION_MASK_HASH)) == 0) {
mask_index += 1;
assert(mask_index < PKE_INPUT_ACTION_MASK_INDEX_COUNT);
- InputEventHash_T hash;
+ pke_input_event_hash_T hash;
stn_res = pk_stn(&hash, kve->val, NULL, 16);
if (stn_res != PK_STN_RES_SUCCESS) {
fprintf(stderr, "[%s] Err '%u' parsing '%s' primary from: '%s'\n", __FILE__, stn_res, SRLZTN_INPUT_ACTION_MASK_HASH, kve->val);
continue;
}
- action.masks[mask_index].computedHash = InputEventHash{hash};
+ action.masks[mask_index].computedHash = pke_input_event_hash{hash};
continue;
}
if (strncmp(kve->key, SRLZTN_INPUT_ACTION_MASK_BUTTON, strlen(SRLZTN_INPUT_ACTION_MASK_BUTTON)) == 0) {
@@ -119,7 +119,7 @@ void pke_deserialize_input_action(srlztn_deserialize_helper *h, pke_kve_containe
}
}
-pk_handle pke_serialize_input_set(srlztn_serialize_helper *h, PkeInputSet *input_set) {
+pk_handle pke_serialize_input_set(srlztn_serialize_helper *h, pke_input_set *input_set) {
char *s;
int len;
pke_kve kve{};
@@ -138,7 +138,7 @@ pk_handle pke_serialize_input_set(srlztn_serialize_helper *h, PkeInputSet *input
pk_arr_append_t(&kvec.child_handles, child_handle);
}
- compt_a<32==sizeof(PkeInputSet)>();
+ compt_a<32==sizeof(pke_input_set)>();
{
kve.key = SRLZTN_INPUT_SET_TITLE;
len = strlen(input_set->title)+1;
@@ -150,9 +150,9 @@ pk_handle pke_serialize_input_set(srlztn_serialize_helper *h, PkeInputSet *input
}
{
kve.key = SRLZTN_INPUT_SET_FLAGS;
- len = snprintf(NULL, 0, "0x%.04X", static_cast<InputActionSetFlags_T>(input_set->flags));
+ len = snprintf(NULL, 0, "0x%.04X", static_cast<pke_input_action_set_flag_T>(input_set->flags));
s = pk_new_arr<char>(len+1, h->bkt);
- sprintf(s, "0x%.04X", static_cast<InputActionSetFlags_T>(input_set->flags));
+ sprintf(s, "0x%.04X", static_cast<pke_input_action_set_flag_T>(input_set->flags));
kve.val = s;
kve.end = SRLZTN_KVE_END;
pk_arr_append_t(&kvec.arr, kve);
@@ -167,17 +167,17 @@ void pke_deserialize_input_set(srlztn_deserialize_helper *h, pke_kve_container *
uint32_t i, k;
char *s;
pke_kve *kve = nullptr;
- PkeInputSet set{};
+ pke_input_set set{};
PK_STN_RES stn_res = PK_STN_RES(0);
// TODO specific bucket
set.actionCount = kvec->children.next;
- set.actions = pk_new_arr<PkeInputAction>(kvec->children.next, NULL);
+ set.actions = pk_new_arr<pke_input_action>(kvec->children.next, NULL);
for (k = 0; k < set.actionCount; ++k) {
pke_deserialize_input_action(h, kvec->children[k], set.actions[k]);
}
- compt_a<40==sizeof(PkeInputAction)>();
+ compt_a<40==sizeof(pke_input_action)>();
for (i = 0; i < kvec->arr.next; ++i) {
kve = &kvec->arr[i];
if (strncmp(kve->key, SRLZTN_INPUT_SET_TITLE, strlen(SRLZTN_INPUT_SET_TITLE)) == 0) {
@@ -188,20 +188,20 @@ void pke_deserialize_input_set(srlztn_deserialize_helper *h, pke_kve_container *
continue;
}
if (strncmp(kve->key, SRLZTN_INPUT_SET_FLAGS, strlen(SRLZTN_INPUT_SET_FLAGS)) == 0) {
- InputActionSetFlags_T flags;
+ pke_input_action_set_flag_T flags;
stn_res = pk_stn(&flags, kve->val, NULL, 16);
if (stn_res != PK_STN_RES_SUCCESS) {
fprintf(stderr, "[%s] Err '%u' parsing '%s' primary from: '%s'\n", __FILE__, stn_res, SRLZTN_INPUT_SET_FLAGS, kve->val);
continue;
}
- set.flags = InputActionSetFlags{flags};
+ set.flags = pke_input_action_set_flag{flags};
continue;
}
}
- InputActionSetHandle action_set_handle = PkeInput_RegisterSet(set);
+ pke_input_action_set_handle action_set_handle = pke_input_register_set(set);
pke_scene_register_input_action_set(h->scene->scene_handle, action_set_handle);
if (PK_HAS_FLAG(set.flags, PKE_INPUT_ACTION_SET_FLAG_AUTO_ENABLE)) {
- PkeInput_ActivateSet(action_set_handle);
+ pke_input_activate_set(action_set_handle);
}
}
diff --git a/src/serialization-input.hpp b/src/serialization-input.hpp
index 6a7dde3..9b64751 100644
--- a/src/serialization-input.hpp
+++ b/src/serialization-input.hpp
@@ -4,10 +4,10 @@
#include "player-input.hpp"
#include "serialization.hpp"
-pk_handle pke_serialize_input_action(srlztn_serialize_helper *h, PkeInputAction *action);
+pk_handle pke_serialize_input_action(srlztn_serialize_helper *h, pke_input_action *action);
void pke_deserialize_input_action(srlztn_deserialize_helper *h, pke_kve_container *kvec);
-pk_handle pke_serialize_input_set(srlztn_serialize_helper *h, PkeInputSet *input_set);
+pk_handle pke_serialize_input_set(srlztn_serialize_helper *h, pke_input_set *input_set);
void pke_deserialize_input_set(srlztn_deserialize_helper *h, pke_kve_container *kvec);
#endif /* PKE_SERIALIZATION_INPUT_HPP */
diff --git a/src/serialization.cpp b/src/serialization.cpp
index 397d9a5..0d8f2e1 100644
--- a/src/serialization.cpp
+++ b/src/serialization.cpp
@@ -71,7 +71,7 @@ void pke_serialize_scene(srlztn_serialize_helper *h) {
CamIterFn cam_iter_cb{};
InstIterFn inst_iter_cb{};
- pk_arr_t<PkeInputSet> &sets = PkeInput_GetInputSets();
+ pk_arr_t<pke_input_set> &sets = pke_input_get_input_sets();
for (uint32_t i = 0; i < sets.next; ++i) {
if (PK_HAS_FLAG(sets[i].flags, PKE_INPUT_ACTION_SET_FLAG_DO_NOT_SERIALIZE)) {
continue;