asset preload alignment

This commit is contained in:
2026-03-24 13:40:54 +00:00
parent d7c970a3e2
commit d576f7ddbd
11 changed files with 367 additions and 22 deletions
+13 -17
View File
@@ -2,7 +2,7 @@
use crate::memory_banks::{SoundBankPoolInstaller, TileBankPoolInstaller};
use prometeu_hal::AssetBridge;
use prometeu_hal::asset::{
AssetEntry, AssetLoadError, AssetOpStatus, BankStats, BankType, HandleId, LoadStatus,
AssetEntry, AssetId, AssetLoadError, AssetOpStatus, BankStats, BankType, HandleId, LoadStatus,
PreloadEntry, SlotRef, SlotStats,
};
use prometeu_hal::cartridge::AssetsPayloadSource;
@@ -48,7 +48,7 @@ impl<T> ResidentEntry<T> {
/// This is internal to the AssetManager and not visible to peripherals.
pub struct BankPolicy<T> {
/// Dedup table: asset_id -> resident entry (value + telemetry).
resident: Arc<RwLock<HashMap<u32, ResidentEntry<T>>>>,
resident: Arc<RwLock<HashMap<AssetId, ResidentEntry<T>>>>,
/// Staging area: handle -> value ready to commit.
staging: Arc<RwLock<HashMap<HandleId, Arc<T>>>>,
@@ -63,7 +63,7 @@ impl<T> BankPolicy<T> {
}
/// Try get a resident value by asset_id (dedupe path).
pub fn get_resident(&self, asset_id: u32) -> Option<Arc<T>> {
pub fn get_resident(&self, asset_id: AssetId) -> Option<Arc<T>> {
let mut map = self.resident.write().unwrap();
let entry = map.get_mut(&asset_id)?;
entry.last_used = Instant::now();
@@ -71,7 +71,7 @@ impl<T> BankPolicy<T> {
}
/// Insert or reuse a resident entry. Returns the resident Arc<T>.
pub fn put_resident(&self, asset_id: u32, value: Arc<T>, bytes: usize) -> Arc<T> {
pub fn put_resident(&self, asset_id: AssetId, value: Arc<T>, bytes: usize) -> Arc<T> {
let mut map = self.resident.write().unwrap();
match map.get_mut(&asset_id) {
Some(existing) => {
@@ -104,8 +104,8 @@ impl<T> BankPolicy<T> {
}
pub struct AssetManager {
assets: Arc<RwLock<HashMap<u32, AssetEntry>>>,
name_to_id: Arc<RwLock<HashMap<String, u32>>>,
assets: Arc<RwLock<HashMap<AssetId, AssetEntry>>>,
name_to_id: Arc<RwLock<HashMap<String, AssetId>>>,
handles: Arc<RwLock<HashMap<HandleId, LoadHandleInfo>>>,
next_handle_id: Mutex<HandleId>,
assets_data: Arc<RwLock<AssetsPayloadSource>>,
@@ -115,8 +115,8 @@ pub struct AssetManager {
sound_installer: Arc<dyn SoundBankPoolInstaller>,
/// Track what is installed in each hardware slot (for stats/info).
gfx_slots: Arc<RwLock<[Option<u32>; 16]>>,
sound_slots: Arc<RwLock<[Option<u32>; 16]>>,
gfx_slots: Arc<RwLock<[Option<AssetId>; 16]>>,
sound_slots: Arc<RwLock<[Option<AssetId>; 16]>>,
/// Residency policy for GFX tile banks.
gfx_policy: BankPolicy<TileBank>,
@@ -128,7 +128,7 @@ pub struct AssetManager {
}
struct LoadHandleInfo {
_asset_id: u32,
_asset_id: AssetId,
slot: SlotRef,
status: LoadStatus,
}
@@ -238,8 +238,7 @@ impl AssetManager {
for item in preload {
let entry_opt = {
let assets = self.assets.read().unwrap();
let name_to_id = self.name_to_id.read().unwrap();
name_to_id.get(&item.asset_name).and_then(|id| assets.get(id)).cloned()
assets.get(&item.asset_id).cloned()
};
if let Some(entry) = entry_opt {
@@ -302,10 +301,7 @@ impl AssetManager {
}
}
// else {
// eprintln!(
// "[AssetManager] Preload failed: asset '{}' not found in table",
// item.asset_name
// );
// eprintln!("[AssetManager] Preload failed: asset id '{}' not found in table", item.asset_id);
// }
}
}
@@ -1047,7 +1043,7 @@ mod tests {
}),
};
let preload = vec![PreloadEntry { asset_name: "preload_sound".to_string(), slot: 5 }];
let preload = vec![PreloadEntry { asset_id: 2, slot: 5 }];
let am = AssetManager::new(
vec![],
@@ -1076,7 +1072,7 @@ mod tests {
let mut asset_entry = test_tile_asset_entry("my_tiles", data.len());
asset_entry.asset_id = 10;
let preload = vec![PreloadEntry { asset_name: "my_tiles".to_string(), slot: 3 }];
let preload = vec![PreloadEntry { asset_id: 10, slot: 3 }];
let am = AssetManager::new(
vec![],