diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-11-15 13:03:48 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-11-15 13:03:48 -0500 |
| commit | 1513216876a0409f45d88cbad14ae8b48fca37e2 (patch) | |
| tree | 32b48d966faf36138dd985e4df739a83cddc5f48 /src/player-input.hpp | |
| parent | 6a30d21c5175c27aeccc8a6ae956c274f3ef9621 (diff) | |
major input refactor and add debug camera
Diffstat (limited to 'src/player-input.hpp')
| -rw-r--r-- | src/player-input.hpp | 157 |
1 files changed, 113 insertions, 44 deletions
diff --git a/src/player-input.hpp b/src/player-input.hpp index a5e64be..a44ae42 100644 --- a/src/player-input.hpp +++ b/src/player-input.hpp @@ -1,59 +1,128 @@ #ifndef PKE_PLAYER_INPUT_HPP #define PKE_PLAYER_INPUT_HPP -#include "dynamic-array.hpp" #include "game-type-defs.hpp" #include "macros.hpp" -TypeSafeInt_H(InputEventHash, int16_t, 0x0FFF); -TypeSafeInt_H(InputEventType, int16_t, 0x0FFF); -TypeSafeInt_H(InputCursorEntered, int16_t, 0x0FFF); -TypeSafeInt_H(InputKeyboardKeyAction, int16_t, 0x0FFF); -TypeSafeInt_H(InputMouseButtonAction, int16_t, 0x0FFF); -TypeSafeInt_H(InputWindowFocused, int16_t, 0x0FFF); - -const InputEventType PKE_INPUT_EVENT_TYPE_CURSOR_ENTER = InputEventType{0}; -const InputEventType PKE_INPUT_EVENT_TYPE_CURSOR_POS = InputEventType{1}; -const InputEventType PKE_INPUT_EVENT_TYPE_KEY = InputEventType{2}; -const InputEventType PKE_INPUT_EVENT_TYPE_MOUSE_BUTTON = InputEventType{3}; -const InputEventType PKE_INPUT_EVENT_TYPE_SCROLL = InputEventType{4}; -const InputEventType PKE_INPUT_EVENT_TYPE_WINDOW_FOCUS = InputEventType{5}; - -const InputCursorEntered PKE_INPUT_CURSOR_ENTERED_UNSET = InputCursorEntered{-1}; -const InputCursorEntered PKE_INPUT_CURSOR_ENTERED_FALSE = InputCursorEntered{0}; -const InputCursorEntered PKE_INPUT_CURSOR_ENTERED_TRUE = InputCursorEntered{1}; - -const InputKeyboardKeyAction PKE_INPUT_KEYBOARD_KEY_ACTION_UNSET = InputKeyboardKeyAction{-1}; -const InputKeyboardKeyAction PKE_INPUT_KEYBOARD_KEY_ACTION_RELEASE = InputKeyboardKeyAction{0}; -const InputKeyboardKeyAction PKE_INPUT_KEYBOARD_KEY_ACTION_PRESS = InputKeyboardKeyAction{1}; -const InputKeyboardKeyAction PKE_INPUT_KEYBOARD_KEY_ACTION_REPEAT = InputKeyboardKeyAction{2}; - -const InputMouseButtonAction PKE_INPUT_MOUSE_BUTTON_ACTION_UNSET = InputMouseButtonAction{-1}; -const InputMouseButtonAction PKE_INPUT_MOUSE_BUTTON_ACTION_RELEASE = InputMouseButtonAction{0}; -const InputMouseButtonAction PKE_INPUT_MOUSE_BUTTON_ACTION_PRESS = InputMouseButtonAction{1}; - -const InputWindowFocused PKE_INPUT_WINDOW_FOCUSED_UNSET = InputWindowFocused{-1}; -const InputWindowFocused PKE_INPUT_WINDOW_FOCUSED_FALSE = InputWindowFocused{0}; -const InputWindowFocused PKE_INPUT_WINDOW_FOCUSED_TRUE = InputWindowFocused{1}; - -struct PkeInputEvent { - InputEventType type; - GameTimePoint timePoint; - InputCursorEntered cursorEntered; - InputKeyboardKeyAction keyboardKeyAction; - InputMouseButtonAction mouseButtonAction; - InputWindowFocused windowFocused; - double x; - double y; +#include <cstdint> + +TypeSafeInt_H(InputActionSetHandle, uint8_t, 0xFF); + +TypeSafeInt_Const_Expr(InputEventHash, uint16_t, 0xFFFF); + +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 InputEventHash 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 = + 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 = + PKE_INPUT_HASH_EVENT_TYPE_CURSOR_POS; +const InputEventHash 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 = + 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 = + PKE_INPUT_HASH_EVENT_TYPE_SCROLL; +const InputEventHash 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; + +struct PkeInputEventBase { }; +struct PkeInputEventHolder { + InputEventHash type = InputEventHash{0}; + PkeInputEventBase *ptr = nullptr; +}; +struct PkeCursorEnterEvent : public PkeInputEventBase { + InputActionSetHandle sourceSet; + bool isEntered; +}; +struct PkeCursorPosEvent : public PkeInputEventBase { + InputActionSetHandle sourceSet; + double xMotion; + double yMotion; +}; +struct PkeKeyEvent : public PkeInputEventBase { + InputActionSetHandle sourceSet; + bool isPressed; + int8_t pressCount; + int32_t button; + int32_t mods; +}; +struct PkeMouseButtonEvent : public PkeInputEventBase { + InputActionSetHandle sourceSet; + bool isPressed; + int8_t pressCount; int32_t button; - int32_t scanCode; int32_t mods; - uint64_t tickCount; +}; +struct PkeScrollEvent : public PkeInputEventBase { + InputActionSetHandle sourceSet; + double xMotion; + double yMotion; +}; +struct PkeWindowFocusEvent : public PkeInputEventBase { + InputActionSetHandle sourceSet; + bool isFocused; +}; + +struct PkeInputEventMask { + InputEventHash computedHash = InputEventHash{0}; + int32_t button = -1; + int32_t mods = 0; +}; + +constexpr uint64_t PKE_INPUT_ACTION_MASK_COUNT = 1; +struct PkeInputAction { + const char *name; + union { + PkeInputEventMask masks[PKE_INPUT_ACTION_MASK_COUNT] = {{}}; + struct { + PkeInputEventMask primaryHash; + }; + }; + int32_t eventIndex; +}; +struct PkeInputSet { + const char *title; + uint64_t actionCount; + PkeInputAction *actions; }; void PkeInput_Tick(double delta); -bool PkeInput_Query(const PkeInputEvent &mask); +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); void PkeInput_Teardown(); #endif /* PKE_PLAYER_INPUT_HPP */ |
