summaryrefslogtreecommitdiff
path: root/src/util/asset_manager.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/asset_manager.cc')
-rw-r--r--src/util/asset_manager.cc26
1 files changed, 16 insertions, 10 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;
+}