diff options
| -rw-r--r-- | editor/editor.cpp | 8 | ||||
| -rw-r--r-- | src/asset-manager.cpp | 9 | ||||
| -rw-r--r-- | src/asset-manager.hpp | 22 | ||||
| -rw-r--r-- | src/entities.cpp | 2 | ||||
| -rw-r--r-- | src/project.cpp | 15 |
5 files changed, 44 insertions, 12 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index 3a8e068..542769a 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -442,6 +442,7 @@ void RecordImGui_GLM(const char *label, glm::mat4 &mat) { struct assetLabel { AssetKey key = {'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'}; AssetHandle handle{}; + AssetType type{}; }; DynArray<assetLabel> assetEntries{0, nullptr}; int assetLabelCmp(const void *a, const void *b) { @@ -456,6 +457,7 @@ struct AssetPickerSearchStruct { int64_t selectedItem = -1; char source[8]; char safeKey[AssetKeyLength + 1]; + AssetType type{PKE_ASSET_TYPE_ALL}; }; void RecordImGui_AssetPicker(AssetPickerSearchStruct &apss) { if (shouldRebuildAssetList == true) { @@ -469,6 +471,7 @@ void RecordImGui_AssetPicker(AssetPickerSearchStruct &apss) { assetLabel &al = assetEntries.Push(); memcpy(al.key, a.key, AssetKeyLength); al.handle = a.handle; + al.type = a.type; } } } @@ -479,6 +482,9 @@ void RecordImGui_AssetPicker(AssetPickerSearchStruct &apss) { const int64_t iCount = assetEntries.Count(); for (int64_t i = 0; i < iCount; ++i) { const assetLabel &al = assetEntries[i]; + if ((al.type & apss.type) == AssetType{0}) { + continue; + } char buf[AssetKeyLength + 1]; snprintf(buf, AssetKeyLength + 1, "%s", al.key); if (ImGui::Selectable(buf, apss.selectedItem == i)) { @@ -778,10 +784,12 @@ void RecordImGuiModalCreateEntityType() { static AssetPickerSearchStruct apssModel{ .source = {"cet_mdl"}, .safeKey = {""}, + .type = PKE_ASSET_TYPE_MODEL, }; static AssetPickerSearchStruct apssTexture{ .source = {"cet_txr"}, .safeKey = {""}, + .type = PKE_ASSET_TYPE_TEXTURE, }; if (ImGui::Button("Model Key")) { diff --git a/src/asset-manager.cpp b/src/asset-manager.cpp index b93a568..77aeffd 100644 --- a/src/asset-manager.cpp +++ b/src/asset-manager.cpp @@ -54,7 +54,7 @@ inline Asset *AM_Get_Inner(AssetKey key) { return nullptr; } -AssetHandle AM_Register(AssetKey key, const void *data, int64_t size, std::size_t alignment) { +AssetHandle AM_Register(AssetKey key, AssetType type, const void *data, int64_t size, std::size_t alignment) { assert(data != nullptr && "Attempt to register invalid asset data"); assert(data != CAFE_BABE(void) && "Attempt to register invalid asset data"); assert(size != 0 && "Attempt to register asset data of size 0"); @@ -73,10 +73,11 @@ AssetHandle AM_Register(AssetKey key, const void *data, int64_t size, std::size_ asset.ptr = Pke_New(size, alignment); memcpy(asset.ptr, data, size); asset.state = PKE_ASSET_LOADING_STATE_LOADED; + asset.type = type; return assetHandle; } -AssetHandle AM_Register(AssetKey key, const char *path) { +AssetHandle AM_Register(AssetKey key, AssetType type, const char *path) { Asset *searchedAsset = AM_Get_Inner(key); if (searchedAsset != nullptr) { return searchedAsset->handle; @@ -93,6 +94,7 @@ AssetHandle AM_Register(AssetKey key, const char *path) { strncpy(copiedPath, path, pathLen); asset.basePath = copiedPath; asset.state = PKE_ASSET_LOADING_STATE_LOADING; + asset.type = type; std::packaged_task<void()> *task = Pke_New<std::packaged_task<void()>>(); new (task) std::packaged_task<void()>( [&asset] { AM_Load_Task(asset); @@ -102,7 +104,7 @@ AssetHandle AM_Register(AssetKey key, const char *path) { return assetHandle; } -AssetHandle AM_Register(const char *path) { +AssetHandle AM_Register(const char *path, AssetType type) { NULL_CHAR_ARR(assetKey, AssetKeyLength); int64_t pathLen = strlen(path); int64_t pathOffset = (pathLen > AssetKeyLength ? pathLen - AssetKeyLength : 0); @@ -124,6 +126,7 @@ AssetHandle AM_Register(const char *path) { strncpy(copiedPath, path, pathLen); asset.basePath = copiedPath; asset.state = PKE_ASSET_LOADING_STATE_LOADING; + asset.type = type; std::packaged_task<void()> *task = Pke_New<std::packaged_task<void()>>(); new (task) std::packaged_task<void()>( [&asset] { AM_Load_Task(asset); diff --git a/src/asset-manager.hpp b/src/asset-manager.hpp index 71e95f5..fe0a688 100644 --- a/src/asset-manager.hpp +++ b/src/asset-manager.hpp @@ -12,16 +12,23 @@ struct AssetHandle : public PkeHandle { }; constexpr AssetHandle AssetHandle_MAX = AssetHandle{}; TypeSafeInt_Const_Expr(AssetLoadingState, uint8_t, 0xFF); +TypeSafeInt_Const_Expr(AssetType, uint8_t, 0xFF); const int64_t AssetKeyLength = 16; using AssetKey = char[AssetKeyLength]; const AssetLoadingState PKE_ASSET_LOADING_STATE_UNLOADED = AssetLoadingState {0}; -const AssetLoadingState PKE_ASSET_LOADING_STATE_LOADING = AssetLoadingState {1}; -const AssetLoadingState PKE_ASSET_LOADING_STATE_LOADED = AssetLoadingState {2}; -const AssetLoadingState PKE_ASSET_LOADING_STATE_FAILED = AssetLoadingState {3}; +const AssetLoadingState PKE_ASSET_LOADING_STATE_LOADING = AssetLoadingState {1}; +const AssetLoadingState PKE_ASSET_LOADING_STATE_LOADED = AssetLoadingState {2}; +const AssetLoadingState PKE_ASSET_LOADING_STATE_FAILED = AssetLoadingState {3}; -struct Asset{ +const AssetType PKE_ASSET_TYPE_UNSET = AssetType {0x00}; +const AssetType PKE_ASSET_TYPE_SHADER = AssetType {0x01}; +const AssetType PKE_ASSET_TYPE_MODEL = AssetType {0x02}; +const AssetType PKE_ASSET_TYPE_TEXTURE = AssetType {0x04}; +const AssetType PKE_ASSET_TYPE_ALL = AssetType {0xFF}; + +struct Asset { AssetHandle handle{}; AssetKey key = {'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'}; const char *basePath = nullptr; @@ -30,12 +37,13 @@ struct Asset{ std::future<void> future; int8_t referenceCount = 0; AssetLoadingState state = PKE_ASSET_LOADING_STATE_UNLOADED; + AssetType type = PKE_ASSET_TYPE_UNSET; }; void AM_Init(); -AssetHandle AM_Register(const void *data, int64_t size, std::size_t alignment, const char *key); -AssetHandle AM_Register(const char *path); -AssetHandle AM_Register(AssetKey key, const char *path); +AssetHandle AM_Register(AssetKey key, AssetType type, const void *data, int64_t size, std::size_t alignment); +AssetHandle AM_Register(const char *path, AssetType type); +AssetHandle AM_Register(AssetKey key, AssetType type, const char *path); void AM_Release(AssetHandle assetHandle); const Asset *AM_Get(AssetHandle assetHandle); const AssetHandle AM_GetHandle(AssetKey key); diff --git a/src/entities.cpp b/src/entities.cpp index 8d4fdb7..9553a89 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -100,7 +100,7 @@ void EntityType_Load(EntityType &et) { std::filesystem::path gltfPath{asset->basePath}; gltfPath.replace_filename(gltfData->buffers[0].uri); - AssetHandle modelBinHandle = AM_Register(gltfPath.c_str()); + AssetHandle modelBinHandle = AM_Register(gltfPath.c_str(), PKE_ASSET_TYPE_UNSET); if (textureAssetHandle != AssetHandle_MAX) { const Asset *textureAsset = AM_Get(textureAssetHandle); diff --git a/src/project.cpp b/src/project.cpp index 143f5ab..fdde6e0 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -40,6 +40,7 @@ const char* const PKE_PROJ_FILE_ENTITY_TYPE_PHYSICS_STARTING_COLLISION_MASK = "B const char* const PKE_PROJ_FILE_ASSET_KEY = "Asset::Key: "; const char* const PKE_PROJ_FILE_ASSET_BASE_PATH = "Asset::BasePath: "; +const char* const PKE_PROJ_FILE_ASSET_TYPE = "Asset::Type: "; /* void Proj_SerializeProjectSettings(std::ofstream &stream) { @@ -112,6 +113,9 @@ void Proj_SerializeAsset(std::ofstream &stream, const Asset &asset) { if (asset.basePath != nullptr) { stream << PKE_PROJ_FILE_ASSET_BASE_PATH << asset.basePath << std::endl; } + if (asset.type != a.type) { + stream << PKE_PROJ_FILE_ASSET_TYPE << static_cast<AssetType_T>(asset.type) << std::endl; + } } /* @@ -262,9 +266,10 @@ void Proj_ParseAssset(std::ifstream &stream) { char basePath[256]; basePath[0] = '\0'; basePath[255] = '\0'; + AssetType at{PKE_ASSET_TYPE_UNSET}; while (stream.getline(projReadLine, projReadLineLength)) { if (strcmp(projReadLine, PKE_PROJ_FILE_OBJ_END) == 0) { - AM_Register(keyStr, basePath); + AM_Register(keyStr, at, basePath); return; } if (strstr(projReadLine, PKE_PROJ_FILE_ASSET_KEY) != nullptr) { @@ -278,6 +283,14 @@ void Proj_ParseAssset(std::ifstream &stream) { strncpy(basePath, projReadLine + prefixLen, strLen + 1); continue; } + if (strstr(projReadLine, PKE_PROJ_FILE_ASSET_TYPE) != nullptr) { + uint64_t prefixLen = strlen(PKE_PROJ_FILE_ASSET_TYPE); + AssetType_T val{}; + STR2NUM_ERROR result = str2num(val, projReadLine + prefixLen); + at = AssetType{val}; + assert(result == STR2NUM_ERROR::SUCCESS); + continue; + } } } |
