diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-07-24 11:41:01 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-07-24 11:41:01 -0400 |
| commit | 13bb74998afda740bf61df8ddd14c76539937a3b (patch) | |
| tree | 2f28c733810b5aa8dcb262178834623b11b6d76a /editor | |
| parent | 5e341340de5259acdb119866dc6819a81ed0ca84 (diff) | |
pke: pke_input_event fat struct refactor
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/editor.cpp | 161 |
1 files changed, 69 insertions, 92 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index c9c673b..24ffe27 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -60,7 +60,7 @@ const char* const dbgCtrl_ImGui_Toggle = "debug-imgui-toggle"; ThreadPoolHandle threadPoolHandle = ThreadPoolHandle_MAX; -InputActionSetHandle debugControlsHandle = InputActionSetHandle_MAX; +pke_input_action_set_handle debugControlsHandle = pke_input_action_set_handle_MAX; bool shouldSetupEditor = true; bool shouldDisableEditor = false; bool shouldRebuildProjectDir = true; @@ -232,11 +232,12 @@ void PkeEditor_Tick(double delta) { bool imGuiHovered = ImGui::GetIO().WantCaptureMouse; + const pke_input_event *holder = nullptr; if (selectedEntity != nullptr && !imGuiHovered) { - auto holder = PkeInput_Query(dbgCtrl_ClearSelection); - if (holder.type != InputEventHash{0}) { - const PkeMouseButtonEvent *mbEvent = static_cast<PkeMouseButtonEvent *>(holder.ptr); - if (mbEvent->isPressed) { + holder = pke_input_query_by_action_name(dbgCtrl_ClearSelection); + if (holder != nullptr) { + assert(holder->type == PKE_INPUT_HASH_EVENT_TYPE_MOUSE_BUTTON); + if (holder->data.mouse_button.isPressed) { selectedEntity = nullptr; selected_ui_box = nullptr; } @@ -274,10 +275,9 @@ void PkeEditor_Tick(double delta) { } if (hoveredEntity != nullptr) { - auto holder = PkeInput_Query(dbgCtrl_SelectHovered); - if (holder.type != InputEventHash{0}) { - const PkeMouseButtonEvent *mbEvent = static_cast<PkeMouseButtonEvent *>(holder.ptr); - if (mbEvent->isPressed) { + auto holder = pke_input_query_by_action_name(dbgCtrl_SelectHovered); + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + if (holder->data.mouse_button.isPressed) { selectedEntity = hoveredEntity; } } @@ -338,12 +338,10 @@ void PkeEditor_Tick(double delta) { pk_arr_remove_at(&entityInstancesToCreate, entityInstancesToCreate.next-1); } - PkeInputEventHolder holder = PkeInput_Query(dbgCtrl_CameraButtonMask); - if (holder.type != InputEventHash{0}) { - PkeMouseButtonEvent *toggleCameraMovement; - toggleCameraMovement = static_cast<PkeMouseButtonEvent *>(holder.ptr); - if (toggleCameraMovement->thisTick) { - if (toggleCameraMovement->isPressed && pkeSettings.editorSettings.isUsingDebugCamera == false) { + holder = pke_input_query_by_action_name(dbgCtrl_CameraButtonMask); + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + if (holder->data.mouse_button.thisTick) { + if (holder->data.mouse_button.isPressed && pkeSettings.editorSettings.isUsingDebugCamera == false) { pkeSettings.editorSettings.isUsingDebugCamera = true; glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); selectedCamera = CameraHandle_MAX; @@ -361,7 +359,7 @@ void PkeEditor_Tick(double delta) { NullCamera.stale = PKE_CAMERA_STALE_ALL; ActiveCamera = &NullCamera; } - } else if (toggleCameraMovement->isPressed && pkeSettings.editorSettings.isUsingDebugCamera == true) { + } else if (holder->data.mouse_button.isPressed && pkeSettings.editorSettings.isUsingDebugCamera == true) { pkeSettings.editorSettings.isUsingDebugCamera = false; glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } @@ -369,21 +367,20 @@ void PkeEditor_Tick(double delta) { } if (pkeSettings.editorSettings.isUsingDebugCamera && ActiveCamera == &NullCamera) { - holder = PkeInput_Query(dbgCtrl_CameraRot); + holder = pke_input_query_by_action_name(dbgCtrl_CameraRot); btTransform trfm; NullCameraInstance.bt.motionState->getWorldTransform(trfm); - if (holder.type != InputEventHash{0}) { - const PkeCursorPosEvent *posEvent = static_cast<PkeCursorPosEvent *>(holder.ptr); - if (posEvent->xMotion || posEvent->yMotion) { + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + if (holder->data.cursor_pos.xMotion || holder->data.cursor_pos.yMotion) { glm::quat gRot; BulletToGlm(trfm.getRotation(), gRot); glm::vec3 axis1Heading = glm::conjugate(gRot) * glm::vec3(1.f, 0.f, 0.f); glm::vec3 axis2Heading = glm::conjugate(gRot) * glm::vec3(0.f, 1.f, 0.f); - glm::quat pitch = glm::angleAxis(float(posEvent->yMotion) * 0.01f, glm::normalize(axis1Heading)); - glm::quat yaw = glm::angleAxis(float(posEvent->xMotion) * 0.01f, glm::normalize(axis2Heading)); + glm::quat pitch = glm::angleAxis(float(holder->data.cursor_pos.yMotion) * 0.01f, glm::normalize(axis1Heading)); + glm::quat yaw = glm::angleAxis(float(holder->data.cursor_pos.xMotion) * 0.01f, glm::normalize(axis2Heading)); glm::quat rot = gRot * pitch * yaw; auto eul = glm::eulerAngles(rot); gRot = glm::quat(eul); @@ -403,60 +400,44 @@ void PkeEditor_Tick(double delta) { double rotCCCount = 0; double rotCCount = 0; - holder = PkeInput_Query(dbgCtrl_CameraLeft); - if (holder.type != InputEventHash{0}) { - PkeKeyEvent *keyLeft; - keyLeft = static_cast<PkeKeyEvent *>(holder.ptr); - leftCount = keyLeft->isPressed ? 1 : 0; + holder = pke_input_query_by_action_name(dbgCtrl_CameraLeft); + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + leftCount = holder->data.key.isPressed ? 1 : 0; } - holder = PkeInput_Query(dbgCtrl_CameraRight); - if (holder.type != InputEventHash{0}) { - PkeKeyEvent *keyRight; - keyRight = static_cast<PkeKeyEvent *>(holder.ptr); - rightCount = keyRight->isPressed ? 1 : 0; + holder = pke_input_query_by_action_name(dbgCtrl_CameraRight); + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + rightCount = holder->data.key.isPressed ? 1 : 0; } - holder = PkeInput_Query(dbgCtrl_CameraForward); - if (holder.type != InputEventHash{0}) { - PkeKeyEvent *keyForward; - keyForward = static_cast<PkeKeyEvent *>(holder.ptr); - forwardCount = keyForward->isPressed ? 1 : 0; + holder = pke_input_query_by_action_name(dbgCtrl_CameraForward); + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + forwardCount = holder->data.key.isPressed ? 1 : 0; } - holder = PkeInput_Query(dbgCtrl_CameraBack); - if (holder.type != InputEventHash{0}) { - PkeKeyEvent *keyBack; - keyBack = static_cast<PkeKeyEvent *>(holder.ptr); - backCount = keyBack->isPressed ? 1 : 0; + holder = pke_input_query_by_action_name(dbgCtrl_CameraBack); + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + backCount = holder->data.key.isPressed ? 1 : 0; } - holder = PkeInput_Query(dbgCtrl_CameraUp); - if (holder.type != InputEventHash{0}) { - PkeKeyEvent *keyUp; - keyUp = static_cast<PkeKeyEvent *>(holder.ptr); - upCount = keyUp->isPressed ? 1 : 0; + holder = pke_input_query_by_action_name(dbgCtrl_CameraUp); + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + upCount = holder->data.key.isPressed ? 1 : 0; } - holder = PkeInput_Query(dbgCtrl_CameraDown); - if (holder.type != InputEventHash{0}) { - PkeKeyEvent *keyDown; - keyDown = static_cast<PkeKeyEvent *>(holder.ptr); - downCount = keyDown->isPressed ? 1 : 0; + holder = pke_input_query_by_action_name(dbgCtrl_CameraDown); + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + downCount = holder->data.key.isPressed ? 1 : 0; } - holder = PkeInput_Query(dbgCtrl_CameraRotCC); - if (holder.type != InputEventHash{0}) { - PkeKeyEvent *keyRotCC; - keyRotCC = static_cast<PkeKeyEvent *>(holder.ptr); - rotCCCount = keyRotCC->isPressed ? 1 : 0; + holder = pke_input_query_by_action_name(dbgCtrl_CameraRotCC); + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + rotCCCount = holder->data.key.isPressed ? 1 : 0; } - holder = PkeInput_Query(dbgCtrl_CameraRotC); - if (holder.type != InputEventHash{0}) { - PkeKeyEvent *keyRotC; - keyRotC = static_cast<PkeKeyEvent *>(holder.ptr); - rotCCount = keyRotC->isPressed ? 1 : 0; + holder = pke_input_query_by_action_name(dbgCtrl_CameraRotC); + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + rotCCount = holder->data.key.isPressed ? 1 : 0; } double accelerated = delta * 10.f; @@ -494,21 +475,17 @@ void PkeEditor_Tick(double delta) { NullCameraInstance.bt.rigidBody->activate(); } - holder = PkeInput_Query(dbgCtrl_DeleteSelectedItem); - if (holder.type != InputEventHash{0} && selectedEntity != nullptr) { - PkeKeyEvent *delSelectedItemEvent; - delSelectedItemEvent = static_cast<PkeKeyEvent *>(holder.ptr); - if (delSelectedItemEvent->isPressed == true) { + holder = pke_input_query_by_action_name(dbgCtrl_DeleteSelectedItem); + if (holder != nullptr && holder->type != pke_input_event_hash{0} && selectedEntity != nullptr) { + if (holder->data.key.isPressed == true) { ECS_MarkForRemoval(ECS_GetEntity(selectedEntity->entHandle)); selectedEntity = nullptr; } } - holder = PkeInput_Query(dbgCtrl_ImGui_Toggle); - if (holder.type != InputEventHash{0}) { - PkeKeyEvent *key; - key = static_cast<PkeKeyEvent *>(holder.ptr); - if (key->isPressed && key->thisTick == true) { + holder = pke_input_query_by_action_name(dbgCtrl_ImGui_Toggle); + if (holder != nullptr && holder->type != pke_input_event_hash{0}) { + if (holder->data.key.isPressed && holder->data.key.thisTick == true) { pkeSettings.isShowingEditor = !pkeSettings.isShowingEditor; } } @@ -1933,13 +1910,13 @@ void PkeEditor_RecordImGui() { void PkeEditor_Setup() { shouldSetupEditor = false; - PkeInput_ActivateSet(debugControlsHandle); + pke_input_activate_set(debugControlsHandle); } void PkeEditor_Disable() { shouldDisableEditor = false; - if (debugControlsHandle != InputActionSetHandle_MAX) - PkeInput_DeactivateSet(debugControlsHandle); + if (debugControlsHandle != pke_input_action_set_handle_MAX) + pke_input_deactivate_set(debugControlsHandle); } void PkeEditor_Teardown() { @@ -1956,83 +1933,83 @@ void PkeEditor_Init() { pkeSettings.isSimulationPaused = true; pkeSettings.isShowingEditor = true; - PkeInputSet debugControlsSet{}; + pke_input_set debugControlsSet{}; debugControlsSet.title = "debug-editor-controls"; debugControlsSet.actionCount = 14; - debugControlsSet.actions = pk_new_arr<PkeInputAction>(debugControlsSet.actionCount); + debugControlsSet.actions = pk_new_arr<pke_input_action>(debugControlsSet.actionCount); debugControlsSet.flags = PKE_INPUT_ACTION_SET_FLAG_DO_NOT_SERIALIZE; debugControlsSet.actions[0].name = dbgCtrl_CameraLeft; - debugControlsSet.actions[0].masks[0] = PkeInputEventMask { + debugControlsSet.actions[0].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, .button = GLFW_KEY_A, }; debugControlsSet.actions[1].name = dbgCtrl_CameraRight; - debugControlsSet.actions[1].masks[0] = PkeInputEventMask { + debugControlsSet.actions[1].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, .button = GLFW_KEY_D, }; debugControlsSet.actions[2].name = dbgCtrl_CameraForward; - debugControlsSet.actions[2].masks[0] = PkeInputEventMask { + debugControlsSet.actions[2].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, .button = GLFW_KEY_W, }; debugControlsSet.actions[3].name = dbgCtrl_CameraBack; - debugControlsSet.actions[3].masks[0] = PkeInputEventMask { + debugControlsSet.actions[3].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, .button = GLFW_KEY_S, }; debugControlsSet.actions[4].name = dbgCtrl_CameraUp; - debugControlsSet.actions[4].masks[0] = PkeInputEventMask { + debugControlsSet.actions[4].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, .button = GLFW_KEY_R, }; debugControlsSet.actions[5].name = dbgCtrl_CameraDown; - debugControlsSet.actions[5].masks[0] = PkeInputEventMask { + debugControlsSet.actions[5].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, .button = GLFW_KEY_F, }; debugControlsSet.actions[6].name = dbgCtrl_CameraRotCC; - debugControlsSet.actions[6].masks[0] = PkeInputEventMask { + debugControlsSet.actions[6].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, .button = GLFW_KEY_Q, }; debugControlsSet.actions[7].name = dbgCtrl_CameraRotC; - debugControlsSet.actions[7].masks[0] = PkeInputEventMask { + debugControlsSet.actions[7].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, .button = GLFW_KEY_E, }; debugControlsSet.actions[8].name = dbgCtrl_CameraRot; - debugControlsSet.actions[8].masks[0] = PkeInputEventMask { + debugControlsSet.actions[8].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_CURSOR_POS_EVENTS, }; debugControlsSet.actions[9].name = dbgCtrl_CameraButtonMask; - debugControlsSet.actions[9].masks[0] = PkeInputEventMask { + debugControlsSet.actions[9].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_MOUSE_BUTTON_EVENTS, .button = GLFW_MOUSE_BUTTON_MIDDLE, }; debugControlsSet.actions[10].name = dbgCtrl_SelectHovered; - debugControlsSet.actions[10].masks[0] = PkeInputEventMask { + debugControlsSet.actions[10].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_MOUSE_BUTTON_EVENTS, .button = GLFW_MOUSE_BUTTON_LEFT, }; debugControlsSet.actions[11].name = dbgCtrl_ClearSelection; - debugControlsSet.actions[11].masks[0] = PkeInputEventMask { + debugControlsSet.actions[11].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_MOUSE_BUTTON_EVENTS, .button = GLFW_MOUSE_BUTTON_RIGHT, }; debugControlsSet.actions[12].name = dbgCtrl_DeleteSelectedItem; - debugControlsSet.actions[12].masks[0] = PkeInputEventMask { + debugControlsSet.actions[12].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, .button = GLFW_KEY_DELETE, }; debugControlsSet.actions[13].name = dbgCtrl_ImGui_Toggle; - debugControlsSet.actions[13].masks[0] = PkeInputEventMask { + debugControlsSet.actions[13].masks[0] = pke_input_event_mask { .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, .button = GLFW_KEY_F1, }; - debugControlsHandle = PkeInput_RegisterSet(debugControlsSet); + debugControlsHandle = pke_input_register_set(debugControlsSet); btTransform trfm{}; trfm.setIdentity(); |
