diff options
| -rw-r--r-- | src/game.cpp | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/src/game.cpp b/src/game.cpp index bd13a22..95c9f31 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -55,6 +55,8 @@ const char *dbgCtrl_CameraRotCC = "debug-camera-rot-counter-clockwise"; const char *dbgCtrl_CameraRotC = "debug-camera-rot-clockwise"; const char *dbgCtrl_CameraRot = "debug-camera-rot"; const char *dbgCtrl_UnlockCamera = "debug-camera-unlock"; +const char *dbgCtrl_SelectHovered = "debug-select-hovered"; +const char *dbgCtrl_ClearSelection = "debug-clear-selection"; InputActionSetHandle debugControlsHandle = InputActionSetHandle_MAX; struct EntityTypeInstanceCreateInfo { @@ -94,6 +96,7 @@ const char *PKE_FILE_INSTANCE_PHYSICS_COLLISION_MASK = "InstPos::CollisionMask: char consoleBuffer[consoleBufferCount][consoleLineLength]; long consoleBufferIndex = 0; EntityHandle selectedEntity = EntityHandle_MAX; +EntityHandle hoveredEntity = EntityHandle_MAX; bool shouldCreateEntityType = false; EntityType *entityTypeToCreate = nullptr; @@ -529,8 +532,22 @@ void Game_Tick(double delta) { } ECS_Tick_Early(delta); + PkeInput_Tick(delta); + + bool imGuiHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow); + + if (selectedEntity != EntityHandle_MAX && !imGuiHovered) { + auto holder = PkeInput_Query(dbgCtrl_ClearSelection); + if (holder.type != InputEventHash{0}) { + const PkeMouseButtonEvent *mbEvent = static_cast<PkeMouseButtonEvent *>(holder.ptr); + if (mbEvent->isPressed) { + selectedEntity = EntityHandle_MAX; + } + } + } // raycast for hovering - do // while(0) + hoveredEntity = EntityHandle_MAX; + if (!imGuiHovered) { double xMousePos, yMousePos; glfwGetCursorPos(window, &xMousePos, &yMousePos); @@ -549,17 +566,30 @@ void Game_Tick(double delta) { BtDynamicsWorld->rayTest(rayOrigin, rayDestination, rayResult); if (rayResult.hasHit()) { EntityHandle_T hoveredEntity_T{reinterpret_cast<EntityHandle_T>(rayResult.m_collisionObject->getUserPointer())}; - EntityHandle hoveredEntity{hoveredEntity_T}; - const auto *inst = ECS_GetInstance(hoveredEntity); - const auto *grBinds = ECS_GetGrBinds(inst->grBindsHandle); - pkeDebugHitbox.instanceBuffer = grBinds->instanceBuffer; - pkeDebugHitbox.instanceStartingIndex = inst->index; - } else { - pkeDebugHitbox.instanceBuffer = VK_NULL_HANDLE; - pkeDebugHitbox.instanceStartingIndex = 0; + hoveredEntity = EntityHandle{hoveredEntity_T}; + } + } + + if (hoveredEntity != EntityHandle_MAX) { + auto holder = PkeInput_Query(dbgCtrl_SelectHovered); + if (holder.type != InputEventHash{0}) { + const PkeMouseButtonEvent *mbEvent = static_cast<PkeMouseButtonEvent *>(holder.ptr); + if (mbEvent->isPressed) { + selectedEntity = hoveredEntity; + } } } - while (0); + + EntityHandle focusedHandle = selectedEntity != EntityHandle_MAX ? selectedEntity : hoveredEntity; + if (focusedHandle != EntityHandle_MAX) { + const auto *inst = ECS_GetInstance(focusedHandle); + const auto *grBinds = ECS_GetGrBinds(inst->grBindsHandle); + pkeDebugHitbox.instanceBuffer = grBinds->instanceBuffer; + pkeDebugHitbox.instanceStartingIndex = inst->index; + } else { + pkeDebugHitbox.instanceBuffer = VK_NULL_HANDLE; + pkeDebugHitbox.instanceStartingIndex = 0; + } if (shouldCreateEntityType) { assert(entityTypeToCreate != nullptr); @@ -602,7 +632,6 @@ void Game_Tick(double delta) { compInst.bt.rigidBody->setUserPointer(reinterpret_cast<void *>(compInst.entHandle)); } - PkeInput_Tick(delta); PkeInputEventHolder holder = PkeInput_Query(dbgCtrl_UnlockCamera); if (holder.type != InputEventHash{0}) { PkeKeyEvent *keyEsc; @@ -726,7 +755,6 @@ void Game_Tick(double delta) { cameraDefault.stale = cameraDefault.stale | PKE_CAMERA_STALE_ROT; } EntityType_Tick_Late(delta); - EntityType_Tick_Late(delta); ECS_Tick_Late(delta); if (shouldTeardownEditor) { teardownEditor(); @@ -1075,7 +1103,7 @@ void Game_Init() { PkeInputSet debugControlsSet; debugControlsSet.title = "debug-editor-controls"; - debugControlsSet.actionCount = 10; + debugControlsSet.actionCount = 12; debugControlsSet.actions = Pke_New<PkeInputAction>(debugControlsSet.actionCount); debugControlsSet.actions[0].name = dbgCtrl_CameraLeft; @@ -1127,6 +1155,16 @@ void Game_Init() { .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, .button = GLFW_KEY_ESCAPE, }; + debugControlsSet.actions[10].name = dbgCtrl_SelectHovered; + debugControlsSet.actions[10].primaryHash = PkeInputEventMask { + .computedHash = PKE_INPUT_HASH_ALL_MOUSE_BUTTON_EVENTS, + .button = GLFW_MOUSE_BUTTON_LEFT, + }; + debugControlsSet.actions[11].name = dbgCtrl_ClearSelection; + debugControlsSet.actions[11].primaryHash = PkeInputEventMask { + .computedHash = PKE_INPUT_HASH_ALL_MOUSE_BUTTON_EVENTS, + .button = GLFW_MOUSE_BUTTON_RIGHT, + }; debugControlsHandle = PkeInput_RegisterSet(debugControlsSet); |
