diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-05-21 14:16:47 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-05-21 14:16:47 -0400 |
| commit | 813b7ca3aa0e366ab49f998f024ad106b44aff0c (patch) | |
| tree | 6f0b7cf1e86ff39031479e21780461da8222f188 /editor | |
| parent | 104a579c9e3bce425bcb4a857083f84ca1f1a3e0 (diff) | |
pke: project-settings DynArray to pk_arr_t
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/editor.cpp | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index 8345964..af6aa57 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -65,7 +65,7 @@ bool shouldDisableEditor = false; bool shouldRebuildProjectDir = true; bool shouldRebuildAssetList = true; -DynArray<EntityType *> entityInstancesToCreate{16}; +pk_arr_t<EntityType *> entityInstancesToCreate{}; CompInstance *selectedEntity = nullptr; CompInstance *hoveredEntity = nullptr; bool shouldCreateEntityType = false; @@ -315,8 +315,8 @@ void PkeEditor_Tick(double delta) { entityTypeToCreate = EntityType{}; shouldCreateEntityType = false; } - while (entityInstancesToCreate.Count() > 0) { - EntityType *et = entityInstancesToCreate.Pop(); + while (entityInstancesToCreate.next > 0) { + EntityType *et = entityInstancesToCreate[entityInstancesToCreate.next-1]; if (et->createInstanceCallback.func) { // TODO function signature // reinterpret_cast<void(*)()>(et->createInstanceCallback.func)(); @@ -324,6 +324,7 @@ void PkeEditor_Tick(double delta) { } else { EntityType_CreateGenericInstance(et, editor_mstr.active_scene, nullptr); } + pk_arr_remove_at(&entityInstancesToCreate, entityInstancesToCreate.next-1); } PkeInputEventHolder holder = PkeInput_Query(dbgCtrl_CameraButtonMask); @@ -517,7 +518,7 @@ struct assetLabel { AssetHandle handle{}; AssetType type{}; }; -DynArray<assetLabel> assetEntries{0, nullptr}; +pk_arr_t<assetLabel> assetEntries{}; int assetLabelCmp(const void *a, const void *b) { const auto &tA = *static_cast<const assetLabel *>(a); const auto &tB = *static_cast<const assetLabel *>(b); @@ -533,28 +534,29 @@ struct AssetPickerSearchStruct { AssetType type{PKE_ASSET_TYPE_ALL}; }; void RecordImGui_AssetPicker(AssetPickerSearchStruct &apss) { + assetLabel tmp{}; if (shouldRebuildAssetList == true) { - if (assetEntries.Count() == 0) { + 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]; - assetLabel &al = assetEntries.Push(); - strncpy(al.key, a.key, AssetKeyLength); - al.key[AssetKeyLength-1] = '\0'; - al.handle = a.handle; - al.type = a.type; + 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); } } } - std::qsort(assetEntries.GetPtr(), assetEntries.Count(), sizeof(assetLabel), assetLabelCmp); + std::qsort(assetEntries.data, assetEntries.next, sizeof(assetLabel), assetLabelCmp); } if (ImGui::BeginPopup(apss.source)) { ImGui::SeparatorText("Asset"); - const int64_t iCount = assetEntries.Count(); - for (int64_t i = 0; i < iCount; ++i) { + const uint32_t iCount = assetEntries.next; + for (uint32_t i = 0; i < iCount; ++i) { const assetLabel &al = assetEntries[i]; if ((al.type & apss.type) == AssetType{0}) { continue; @@ -620,7 +622,7 @@ void RecordImGuiModalCreateAsset() { if (ImGui::Button("Create")) { AM_Register(assetKey, type, assetPath); shouldRebuildAssetList = true; - assetEntries.Resize(0); + pk_arr_clear(&assetEntries); shouldClose = true; } ImGui::SameLine(); @@ -753,7 +755,7 @@ void RecordImGuiEntityTypes() { ImGui::Text("count: %li", et.detailsCount); ImGui::TableSetColumnIndex(4); if (ImGui::Button("Add")) { - entityInstancesToCreate.Push(const_cast<EntityType *>(&et)); + pk_arr_append_t(&entityInstancesToCreate, const_cast<EntityType *>(&et)); } ImGui::SameLine(); ImGui::Text("count: %u", et.details[0].grBinds->instanceCounter); @@ -1573,9 +1575,9 @@ struct fsEntry { int type = 0; char *name = nullptr; char *path = nullptr; - DynArray<fsEntry> children{0, nullptr}; + pk_arr_t<fsEntry> children{}; }; -DynArray<fsEntry> fsEntries{0, nullptr}; +pk_arr_t<fsEntry> fsEntries{}; std::regex reg_sceneFile(".+\\.ps[tb]f$", std::regex_constants::icase); int fsEntryComp(const void *a, const void *b) { const auto &fsA = *static_cast<const fsEntry *>(a); @@ -1592,14 +1594,22 @@ int fsEntryComp(const void *a, const void *b) { } return 0; } -void SortRecursive(DynArray<fsEntry> &arr) { - std::qsort(arr.GetPtr(), arr.Count(), sizeof(fsEntry), fsEntryComp); - for (long i = 0; i < arr.Count(); ++i) { +void SortRecursive(pk_arr_t<fsEntry> &arr) { + std::qsort(arr.data, arr.next, sizeof(fsEntry), fsEntryComp); + for (uint32_t i = 0; i < arr.next; ++i) { SortRecursive(arr[i].children); } } void BuildDirRecursive(const std::filesystem::directory_entry &de, fsEntry *dirFsEntry) { - auto &entry = dirFsEntry == nullptr ? fsEntries.Push() : dirFsEntry->children.Push(); + fsEntry *entry_ptr; + if (dirFsEntry == nullptr) { + pk_arr_append_t(&fsEntries, {}); + entry_ptr = &fsEntries[fsEntries.next-1]; + } else { + pk_arr_append_t(&dirFsEntry->children, {}); + entry_ptr = &dirFsEntry->children[dirFsEntry->children.next-1]; + } + fsEntry &entry = *entry_ptr; auto fullPath = std::filesystem::absolute(de.path()); auto len = strlen(fullPath.c_str()); // TODO leaky @@ -1640,7 +1650,7 @@ void BuildProjectMenuRecursive(fsEntry &entry) { } } else if (entry.type == 0) { if (ImGui::TreeNode(entry.name)) { - for (long i = 0; i < entry.children.Count(); ++i) { + for (uint32_t i = 0; i < entry.children.next; ++i) { BuildProjectMenuRecursive(entry.children[i]); } ImGui::TreePop(); @@ -1654,7 +1664,7 @@ void RecordImGuiProjectBrowser() { } if (shouldRebuildProjectDir == true) { shouldRebuildProjectDir = false; - fsEntries.Resize(0); + pk_arr_clear(&fsEntries); std::filesystem::directory_iterator di{std::filesystem::current_path()}; for (const std::filesystem::directory_entry &sde : di) { if (sde.is_directory() @@ -1665,7 +1675,7 @@ void RecordImGuiProjectBrowser() { } SortRecursive(fsEntries); } - for (long i = 0; i < fsEntries.Count(); ++i) { + for (uint32_t i = 0; i < fsEntries.next; ++i) { BuildProjectMenuRecursive(fsEntries[i]); } ImGui::End(); @@ -1748,7 +1758,7 @@ void RecordImGuiSceneEditor() { if (ImGui::Button("Create Instance")) { Entity_Base *entity = ECS_GetEntity(selectedEntity->entHandle); auto *entityType = static_cast<EntityType *>(entity); - entityInstancesToCreate.Push(entityType); + pk_arr_append_t(&entityInstancesToCreate, entityType); } } entType = EntityType_FindByEntityHandle(selectedEntity->entHandle); @@ -1808,7 +1818,7 @@ void PkeEditor_Teardown() { } if (threadPoolHandle != ThreadPoolHandle_MAX) PkeThreads_Teardown(threadPoolHandle); - entityInstancesToCreate.~DynArray(); + pk_arr_reset(&entityInstancesToCreate); } void PkeEditor_Init() { |
