diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-11-06 22:24:47 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-11-06 22:24:47 -0500 |
| commit | 5da699cff8a39bf1dc41b2d302c3e9c202496971 (patch) | |
| tree | b152c07867b27855089cb8d1f736c9b42c00ce19 | |
| parent | 8d0ddad577c6e3275380d271450c2257414a2019 (diff) | |
pke: static-ui invis state flags + update buffer
| -rw-r--r-- | src/static-ui.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/static-ui.cpp b/src/static-ui.cpp index 8addb7e..c61b0aa 100644 --- a/src/static-ui.cpp +++ b/src/static-ui.cpp @@ -182,12 +182,20 @@ Some restrictions: void pke_ui_update_state(pke_ui_box &box) { double mouse_x, mouse_y; + PKE_UI_BOX_STATE_FLAG old_state; + PKE_UI_BOX_STATE_FLAG flgs; // update state - PKE_UI_BOX_STATE_FLAG old_state = box.state_flags; - PKE_UI_BOX_STATE_FLAG flgs; + old_state = box.state_flags; box.state_flags = PKE_UI_BOX_STATE_FLAG_NONE; + if (PK_HAS_FLAG(box.flags, PKE_UI_BOX_FLAG_VISIBILITY_INVISIBLE)) { + // invisible boxes have no state + box.state_flags_mem = PKE_UI_BOX_STATE_FLAG_NONE; + return; + } + + if (pke_ui_master.state.mouse_left == nullptr || (pke_ui_master.state.mouse_left->data.mouse_button.isPressed == false && pke_ui_master.state.mouse_left->data.mouse_button.thisTick == false)) { flgs = PKE_UI_BOX_STATE_FLAG_ON_BTN_PRIMARY_RELEASE | PKE_UI_BOX_STATE_FLAG_ON_BTN_PRIMARY_PRESS | PKE_UI_BOX_STATE_FLAG_ON_BTN_PRIMARY_PRESSED; box.state_flags_mem &= ~flgs; @@ -435,6 +443,10 @@ bool pke_ui_calc_px(pk_arr_t<pke_ui_box_instance_buffer_item> &buffer, pk_arr_t< } if (PK_HAS_FLAG(box->flags, PKE_UI_BOX_FLAG_VISIBILITY_INVISIBLE)) { + // TODO PERF we need to track state changes + // currently this updates the buffer every frame if: + // - box type text (always invisible with visible text) + pke_ui_master.should_update_buffer = true; return true; } @@ -551,6 +563,7 @@ int pke_ui_box_ibi_sort_for_buffer(const void *lhs, const void *rhs) { void pke_ui_update_instance_buffer(pk_arr_t<pke_ui_box_instance_buffer_item> &arr) { VkResult vkResult; + VkDeviceSize sz; if (arr.next == 0) { pke_ui_master.bindings.instance_counter = 0; return; @@ -603,7 +616,8 @@ void pke_ui_update_instance_buffer(pk_arr_t<pke_ui_box_instance_buffer_item> &ar } if (arr.next > 0 && arr.data != nullptr ) { PKVK_TmpBufferDetails tmpBufferDetails{}; - PKVK_BeginBuffer(graphicsFamilyIndex, sizeof(pke_ui_box_instance_buffer_item) * arr.next, tmpBufferDetails); + sz = sizeof(pke_ui_box_instance_buffer_item) * arr.next; + PKVK_BeginBuffer(graphicsFamilyIndex, sz, tmpBufferDetails); { VkCommandBufferBeginInfo vkCommandBufferBeginInfo; vkCommandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; @@ -614,12 +628,12 @@ void pke_ui_update_instance_buffer(pk_arr_t<pke_ui_box_instance_buffer_item> &ar vkResult = vkBeginCommandBuffer(tmpBufferDetails.cmdBuffer, &vkCommandBufferBeginInfo); assert(vkResult == VK_SUCCESS); - memcpy(tmpBufferDetails.deviceData, arr.data, sizeof(pke_ui_box_instance_buffer_item) * arr.next); + memcpy(tmpBufferDetails.deviceData, arr.data, sz); VkBufferCopy vk_buffer_copy{}; vk_buffer_copy.srcOffset = 0; vk_buffer_copy.dstOffset = 0; - vk_buffer_copy.size = sizeof(pke_ui_box_instance_buffer_item) * arr.next; + vk_buffer_copy.size = sz; vkCmdCopyBuffer(tmpBufferDetails.cmdBuffer, tmpBufferDetails.buffer, pke_ui_master.bindings.bd_instance.buffer, 1, &vk_buffer_copy); vkResult = vkEndCommandBuffer(tmpBufferDetails.cmdBuffer); |
