diff options
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/asset_manager.cc | 26 | ||||
| -rw-r--r-- | src/util/asset_manager.h | 9 |
2 files changed, 22 insertions, 13 deletions
diff --git a/src/util/asset_manager.cc b/src/util/asset_manager.cc index a606b46..2285f3a 100644 --- a/src/util/asset_manager.cc +++ b/src/util/asset_manager.cc @@ -37,7 +37,7 @@ static const size_t kNumProcGenFuncs = sizeof(kAssetManagerProcGenFuncs) / sizeof(kAssetManagerProcGenFuncs[0]); // Array-based cache for assets. -// Initialized to all zeros (nullptr data, 0 size, false is_procedural) +// Initialized to all zeros (nullptr data, 0 size, AssetType::STATIC) // The size is derived from the generated ASSET_LAST_ID enum value. static AssetRecord g_asset_cache[(size_t)AssetId::ASSET_LAST_ID] = {}; @@ -78,7 +78,8 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) { AssetRecord cached_record = source_record; - if (source_record.is_procedural) { + if (source_record.type == AssetType::PROC || + source_record.type == AssetType::PROC_GPU) { // Dynamically generate the asset ProcGenFunc proc_gen_func_ptr = nullptr; for (size_t i = 0; i < kNumProcGenFuncs; ++i) { @@ -131,13 +132,8 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) { cached_record.data = generated_data; cached_record.size = data_size; - cached_record.is_procedural = true; - // proc_gen_func, proc_params, num_proc_params already copied from + // type, proc_gen_func, proc_params, num_proc_params already copied from // source_record - - } else { - // Static asset (copy from g_assets) - cached_record.is_procedural = false; } // Store in cache for future use @@ -187,7 +183,8 @@ void DropAsset(AssetId asset_id, const uint8_t* asset) { // Check if the asset is in cache and is procedural, and if the pointer // matches. This prevents accidentally freeing static data or freeing twice. if (g_asset_cache[index].data == asset && - g_asset_cache[index].is_procedural) { + (g_asset_cache[index].type == AssetType::PROC || + g_asset_cache[index].type == AssetType::PROC_GPU)) { delete[] g_asset_cache[index].data; g_asset_cache[index] = {}; // Zero out the struct to force re-generation } @@ -203,7 +200,9 @@ bool ReloadAssetsFromFile(const char* config_path) { // Clear cache to force reload for (size_t i = 0; i < (size_t)AssetId::ASSET_LAST_ID; ++i) { - if (g_asset_cache[i].is_procedural && g_asset_cache[i].data) { + if ((g_asset_cache[i].type == AssetType::PROC || + g_asset_cache[i].type == AssetType::PROC_GPU) && + g_asset_cache[i].data) { delete[] g_asset_cache[i].data; } g_asset_cache[i] = {}; @@ -213,3 +212,10 @@ bool ReloadAssetsFromFile(const char* config_path) { return true; } #endif // !defined(STRIP_ALL) + +AssetType GetAssetType(AssetId asset_id) { + uint16_t index = (uint16_t)asset_id; + if (index >= (uint16_t)AssetId::ASSET_LAST_ID) + return AssetType::STATIC; + return GetAssetRecordTable()[index].type; +} diff --git a/src/util/asset_manager.h b/src/util/asset_manager.h index 1714c21..09483e5 100644 --- a/src/util/asset_manager.h +++ b/src/util/asset_manager.h @@ -5,12 +5,12 @@ #pragma once #include "asset_manager_dcl.h" +enum class AssetType : uint8_t { STATIC, PROC, PROC_GPU, MP3 }; + struct AssetRecord { const uint8_t* data; // Pointer to asset data (static or dynamic) size_t size; // Size of the asset data - bool is_procedural; // True if data was dynamically allocated by a procedural - // generator - bool is_gpu_procedural; // True if GPU compute shader generates texture + AssetType type; const char* proc_func_name_str; // Name of procedural generation function // (string literal) const float* proc_params; // Parameters for procedural generation (static, @@ -30,6 +30,9 @@ void DropAsset(AssetId asset_id, const uint8_t* asset); // found. AssetId GetAssetIdByName(const char* name); +// Returns the AssetType for a given asset id. +AssetType GetAssetType(AssetId asset_id); + #if !defined(STRIP_ALL) // Hot-reload: Parse and reload assets from config file (debug only) bool ReloadAssetsFromFile(const char* config_path); |
