summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio/tracker.cc13
-rw-r--r--src/util/asset_manager.cc26
-rw-r--r--src/util/asset_manager.h9
3 files changed, 24 insertions, 24 deletions
diff --git a/src/audio/tracker.cc b/src/audio/tracker.cc
index 333a337..7ce96fc 100644
--- a/src/audio/tracker.cc
+++ b/src/audio/tracker.cc
@@ -44,15 +44,6 @@ static bool g_cache_initialized = false;
// Forward declarations
static int get_free_pool_slot();
-// Returns true if the asset blob looks like an MP3 file.
-static bool is_mp3_asset(const uint8_t* data, size_t size) {
- if (!data || size < 3) return false;
- // ID3v2 tag prefix
- if (data[0] == 'I' && data[1] == 'D' && data[2] == '3') return true;
- // Raw MP3 sync word: 0xFF followed by 0xE0-0xFF
- if (size >= 2 && data[0] == 0xFF && (data[1] & 0xE0) == 0xE0) return true;
- return false;
-}
#if !defined(STRIP_ALL)
// Decode an in-memory MP3 blob to a heap-allocated spectrogram (caller owns).
@@ -147,7 +138,7 @@ void tracker_init() {
size_t size;
const uint8_t* data = GetAsset(aid, &size);
#if !defined(STRIP_ALL)
- if (data && size > 0 && is_mp3_asset(data, size)) {
+ if (data && size > 0 && GetAssetType(aid) == AssetType::MP3) {
int num_frames = 0;
float* spec_data =
convert_mp3_to_spectrogram(data, size, &num_frames);
@@ -165,7 +156,7 @@ void tracker_init() {
}
} else
#else
- FATAL_CHECK(data == nullptr || !is_mp3_asset(data, size),
+ FATAL_CHECK(data == nullptr || GetAssetType(aid) != AssetType::MP3,
"MP3 assets not supported in STRIP_ALL builds\n");
#endif
if (data && size >= sizeof(SpecHeader)) {
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);