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.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/util/asset_manager.cc b/src/util/asset_manager.cc
index 2285f3a..52a60ee 100644
--- a/src/util/asset_manager.cc
+++ b/src/util/asset_manager.cc
@@ -76,6 +76,39 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) {
AssetRecord source_record = assets[index];
+#if !defined(DEMO_STRIP_ALL)
+ if (source_record.type == AssetType::SPEC ||
+ source_record.type == AssetType::MP3) {
+ const char* path = (const char*)source_record.data;
+ FILE* f = fopen(path, "rb");
+ if (!f) {
+ if (out_size)
+ *out_size = 0;
+ return nullptr;
+ }
+ fseek(f, 0, SEEK_END);
+ long size = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ uint8_t* buffer = new (std::nothrow) uint8_t[size + 1];
+ if (!buffer) {
+ fclose(f);
+ if (out_size)
+ *out_size = 0;
+ return nullptr;
+ }
+ fread(buffer, 1, size, f);
+ fclose(f);
+ buffer[size] = 0; // Null-terminate
+
+ g_asset_cache[index].data = buffer;
+ g_asset_cache[index].size = size;
+ g_asset_cache[index].type = source_record.type;
+ if (out_size)
+ *out_size = size;
+ return buffer;
+ }
+#endif
+
AssetRecord cached_record = source_record;
if (source_record.type == AssetType::PROC ||
@@ -188,6 +221,14 @@ void DropAsset(AssetId asset_id, const uint8_t* asset) {
delete[] g_asset_cache[index].data;
g_asset_cache[index] = {}; // Zero out the struct to force re-generation
}
+#if !defined(DEMO_STRIP_ALL)
+ if (g_asset_cache[index].data == asset &&
+ (g_asset_cache[index].type == AssetType::SPEC ||
+ g_asset_cache[index].type == AssetType::MP3)) {
+ delete[] g_asset_cache[index].data;
+ g_asset_cache[index] = {};
+ }
+#endif
// For static assets, no dynamic memory to free.
}