summaryrefslogtreecommitdiff
path: root/src/player-input.hpp
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/player-input.hpp
parent5e341340de5259acdb119866dc6819a81ed0ca84 (diff)
pke: pke_input_event fat struct refactor
Diffstat (limited to 'src/player-input.hpp')
-rw-r--r--src/player-input.hpp153
1 files changed, 76 insertions, 77 deletions
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 */