summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-05-30 14:41:54 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-05-30 14:41:54 -0400
commit781410537a1c7ddac340efabeedd4c9309e5cf39 (patch)
tree7253babcfc7fd8766095fdf89eca7a9fd3952912 /editor
parent6ff0a1f8f7775752db8219dc270a56c4e64b4c7e (diff)
pke: asset: BucketContainer>pk_bkt_arr_t & cleanup
Diffstat (limited to 'editor')
-rw-r--r--editor/editor.cpp112
1 files changed, 50 insertions, 62 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 667508d..3de8d85 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -534,22 +534,19 @@ struct AssetPickerSearchStruct {
AssetType type{PKE_ASSET_TYPE_ALL};
};
void RecordImGui_AssetPicker(AssetPickerSearchStruct &apss) {
- assetLabel tmp{};
if (shouldRebuildAssetList == true) {
if (assetEntries.next == 0) {
- pk_handle_bucket_index_T bCount = AM_GetBucketCount();
- for (pk_handle_bucket_index_T b = 0; b < bCount; ++b) {
- pk_handle_item_index_T iCount = 0;
- Asset *assets = AM_GetAssets(b, iCount);
- for (pk_handle_item_index_T i = 0; i < iCount; ++i) {
- const Asset &a = assets[i];
- tmp.key[AssetKeyLength-1] = '\0';
- tmp.handle = a.handle;
- tmp.type = a.type;
- strncpy(tmp.key, a.key, AssetKeyLength);
- pk_arr_append_t(&assetEntries, tmp);
- }
- }
+ auto asset_iter_fn = [](void *user_data, void *arr_obj_data) {
+ (void)user_data;
+ assetLabel tmp{};
+ const Asset &a = *reinterpret_cast<Asset*>(arr_obj_data);
+ tmp.key[AssetKeyLength-1] = '\0';
+ tmp.handle = a.handle;
+ tmp.type = a.type;
+ strncpy(tmp.key, a.key, AssetKeyLength);
+ pk_arr_append_t(&assetEntries, tmp);
+ };
+ pk_bkt_arr_iterate(AM_GetAssets(), asset_iter_fn, NULL);
}
std::qsort(assetEntries.data, assetEntries.next, sizeof(assetLabel), assetLabelCmp);
}
@@ -576,12 +573,12 @@ void RecordImGui_AssetPicker(AssetPickerSearchStruct &apss) {
void RecordImGuiModalCreateAsset() {
if (ImGui::BeginPopupModal("CreateAsset", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
static char assetPath[256];
- static char assetKey[AssetKeyLength + 1];
+ static char assetKeyBuffer[AssetKeyLength + 1];
static AssetType type;
assetPath[255] = '\0';
- assetKey[AssetKeyLength] = '\0';
+ assetKeyBuffer[AssetKeyLength] = '\0';
- ImGui::InputText("Asset Key", assetKey, AssetKeyLength);
+ ImGui::InputText("Asset Key", assetKeyBuffer, AssetKeyLength+1);
static uint32_t assetTypeMask = 0U;
if (ImGui::CheckboxFlags("Shader", &assetTypeMask, 1U << static_cast<AssetType_T>(PKE_ASSET_TYPE_SHADER))) {
@@ -620,6 +617,8 @@ void RecordImGuiModalCreateAsset() {
bool shouldClose = false;
if (ImGui::Button("Create")) {
+ AssetKey assetKey = {'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
+ memcpy(assetKey, assetKeyBuffer, PK_MIN(AssetKeyLength, strlen(assetKeyBuffer)));
AM_Register(assetKey, type, assetPath);
shouldRebuildAssetList = true;
pk_arr_clear(&assetEntries);
@@ -633,7 +632,7 @@ void RecordImGuiModalCreateAsset() {
if (shouldClose) {
type = PKE_ASSET_TYPE_UNSET;
assetTypeMask = 0U;
- assetKey[0] = '\0';
+ assetKeyBuffer[0] = '\0';
assetPath[0] = '\0';
ImGui::CloseCurrentPopup();
}
@@ -975,23 +974,18 @@ bool RecordImGui_GenerateMTSDFModal() {
ImGui::Text("Select font:");
ImGui::BeginDisabled(msdf_settings.minimum_scale <= 0.0 || msdf_settings.px_range <= 0.0);
- pk_handle_bucket_index_T asset_bucket_count = AM_GetBucketCount();
- for (pk_handle_bucket_index_T b = 0; b < asset_bucket_count; ++b) {
- pk_handle_item_index_T count;
- auto *assets = AM_GetAssets(b, count);
- for (pk_handle_item_index_T i = 0; i < count; ++i) {
- const auto &asset = assets[i];
- if (asset.handle == AssetHandle_MAX)
- continue;
- if (!PK_HAS_FLAG(asset.type, PKE_ASSET_TYPE_FONT)) {
- continue;
- }
- if (ImGui::Selectable(asset.basePath)) {
- GenerateMTSDF(&msdf_settings, &asset);
- ImGui::CloseCurrentPopup();
- }
+ auto asset_iter_fn = [](void *user_data, void *arr_obj_data) {
+ (void)user_data;
+ const Asset &a = *reinterpret_cast<Asset*>(arr_obj_data);
+ if (!PK_HAS_FLAG(a.type, PKE_ASSET_TYPE_FONT)) {
+ return;
}
- }
+ if (ImGui::Selectable(a.basePath)) {
+ GenerateMTSDF(&msdf_settings, &a);
+ ImGui::CloseCurrentPopup();
+ }
+ };
+ pk_bkt_arr_iterate(AM_GetAssets(), asset_iter_fn, NULL);
ImGui::EndDisabled();
ImGui::Separator();
if (ImGui::Button("Cancel")) {
@@ -1070,35 +1064,29 @@ void RecordImGuiAssets() {
ImGui::TableSetupColumn("Ref Count");
ImGui::TableHeadersRow();
- pk_handle_bucket_index_T asset_bucket_count = AM_GetBucketCount();
- for (pk_handle_bucket_index_T b = 0; b < asset_bucket_count; ++b) {
- pk_handle_item_index_T count;
- auto *assets = AM_GetAssets(b, count);
- ImGui::PushID(b);
- for (pk_handle_item_index_T i = 0; i < count; ++i) {
- const auto &asset = assets[i];
- if (asset.handle == AssetHandle_MAX)
- continue;
- ImGui::PushID(i);
- ImGui::TableNextRow();
- ImGui::TableSetColumnIndex(0);
- // buttons go here
- ImGui::TableSetColumnIndex(1);
- ImGui::Text("%i", (uint8_t)asset.type);
- ImGui::TableSetColumnIndex(2);
- ImGui::Text("0x%08X 0x%08X", asset.handle.bucketIndex, asset.handle.itemIndex);
- ImGui::TableSetColumnIndex(3);
- ImGui::Text("%.16s", asset.key);
- ImGui::TableSetColumnIndex(4);
- ImGui::Text("%p", asset.ptr);
- ImGui::TableSetColumnIndex(5);
- ImGui::Text("%li", asset.size);
- ImGui::TableSetColumnIndex(6);
- ImGui::Text("%hhi", asset.referenceCount);
- ImGui::PopID();
- }
+ size_t counter = 0;
+ auto asset_iter_fn = [](void *user_data, void *arr_obj_data) {
+ size_t &counter = *reinterpret_cast<size_t*>(user_data);
+ const Asset &asset = *reinterpret_cast<Asset*>(arr_obj_data);
+ ImGui::PushID(counter++);
+ ImGui::TableNextRow();
+ ImGui::TableSetColumnIndex(0);
+ // buttons go here
+ ImGui::TableSetColumnIndex(1);
+ ImGui::Text("%i", (uint8_t)asset.type);
+ ImGui::TableSetColumnIndex(2);
+ ImGui::Text("0x%.08X 0x%.08X", asset.handle.b, asset.handle.i);
+ ImGui::TableSetColumnIndex(3);
+ ImGui::Text("%.16s", asset.key);
+ ImGui::TableSetColumnIndex(4);
+ ImGui::Text("%p", asset.ptr);
+ ImGui::TableSetColumnIndex(5);
+ ImGui::Text("%li", asset.size);
+ ImGui::TableSetColumnIndex(6);
+ ImGui::Text("%hhi", asset.referenceCount);
ImGui::PopID();
- }
+ };
+ pk_bkt_arr_iterate(AM_GetAssets(), asset_iter_fn, &counter);
ImGui::EndTable();
}
ImGui::End();