quality baseline
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
use std::thread;
|
||||
use std::time::Instant;
|
||||
use prometeu_hal::asset::{AssetEntry, BankStats, BankType, HandleId, LoadStatus, PreloadEntry, SlotRef, SlotStats};
|
||||
use crate::memory_banks::{SoundBankPoolInstaller, TileBankPoolInstaller};
|
||||
use prometeu_hal::AssetBridge;
|
||||
use prometeu_hal::asset::{
|
||||
AssetEntry, BankStats, BankType, HandleId, LoadStatus, PreloadEntry, SlotRef, SlotStats,
|
||||
};
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::sample::Sample;
|
||||
use prometeu_hal::sound_bank::SoundBank;
|
||||
use prometeu_hal::tile_bank::{TileBank, TileSize};
|
||||
use crate::memory_banks::{SoundBankPoolInstaller, TileBankPoolInstaller};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
use std::thread;
|
||||
use std::time::Instant;
|
||||
|
||||
/// Resident metadata for a decoded/materialized asset inside a BankPolicy.
|
||||
#[derive(Debug)]
|
||||
@@ -21,7 +23,6 @@ pub struct ResidentEntry<T> {
|
||||
|
||||
// /// Pin count (optional): if > 0, entry should not be evicted by policy.
|
||||
// pub pins: u32,
|
||||
|
||||
/// Telemetry / profiling fields (optional but useful).
|
||||
pub loads: u64,
|
||||
pub last_used: Instant,
|
||||
@@ -129,16 +130,41 @@ struct LoadHandleInfo {
|
||||
}
|
||||
|
||||
impl AssetBridge for AssetManager {
|
||||
fn initialize_for_cartridge(&self, assets: Vec<AssetEntry>, preload: Vec<PreloadEntry>, assets_data: Vec<u8>) { self.initialize_for_cartridge(assets, preload, assets_data) }
|
||||
fn load(&self, asset_name: &str, slot: SlotRef) -> Result<HandleId, String> { self.load(asset_name, slot) }
|
||||
fn status(&self, handle: HandleId) -> LoadStatus { self.status(handle) }
|
||||
fn commit(&self, handle: HandleId) { self.commit(handle) }
|
||||
fn cancel(&self, handle: HandleId) { self.cancel(handle) }
|
||||
fn apply_commits(&self) { self.apply_commits() }
|
||||
fn bank_info(&self, kind: BankType) -> BankStats { self.bank_info(kind) }
|
||||
fn slot_info(&self, slot: SlotRef) -> SlotStats { self.slot_info(slot) }
|
||||
fn find_slot_by_name(&self, asset_name: &str, kind: BankType) -> Option<u8> { self.find_slot_by_name(asset_name, kind) }
|
||||
fn shutdown(&self) { self.shutdown() }
|
||||
fn initialize_for_cartridge(
|
||||
&self,
|
||||
assets: Vec<AssetEntry>,
|
||||
preload: Vec<PreloadEntry>,
|
||||
assets_data: Vec<u8>,
|
||||
) {
|
||||
self.initialize_for_cartridge(assets, preload, assets_data)
|
||||
}
|
||||
fn load(&self, asset_name: &str, slot: SlotRef) -> Result<HandleId, String> {
|
||||
self.load(asset_name, slot)
|
||||
}
|
||||
fn status(&self, handle: HandleId) -> LoadStatus {
|
||||
self.status(handle)
|
||||
}
|
||||
fn commit(&self, handle: HandleId) {
|
||||
self.commit(handle)
|
||||
}
|
||||
fn cancel(&self, handle: HandleId) {
|
||||
self.cancel(handle)
|
||||
}
|
||||
fn apply_commits(&self) {
|
||||
self.apply_commits()
|
||||
}
|
||||
fn bank_info(&self, kind: BankType) -> BankStats {
|
||||
self.bank_info(kind)
|
||||
}
|
||||
fn slot_info(&self, slot: SlotRef) -> SlotStats {
|
||||
self.slot_info(slot)
|
||||
}
|
||||
fn find_slot_by_name(&self, asset_name: &str, kind: BankType) -> Option<u8> {
|
||||
self.find_slot_by_name(asset_name, kind)
|
||||
}
|
||||
fn shutdown(&self) {
|
||||
self.shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
impl AssetManager {
|
||||
@@ -171,7 +197,12 @@ impl AssetManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initialize_for_cartridge(&self, assets: Vec<AssetEntry>, preload: Vec<PreloadEntry>, assets_data: Vec<u8>) {
|
||||
pub fn initialize_for_cartridge(
|
||||
&self,
|
||||
assets: Vec<AssetEntry>,
|
||||
preload: Vec<PreloadEntry>,
|
||||
assets_data: Vec<u8>,
|
||||
) {
|
||||
self.shutdown();
|
||||
{
|
||||
let mut asset_map = self.assets.write().unwrap();
|
||||
@@ -190,45 +221,70 @@ impl AssetManager {
|
||||
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()
|
||||
name_to_id.get(&item.asset_name).and_then(|id| assets.get(id)).cloned()
|
||||
};
|
||||
|
||||
if let Some(entry) = entry_opt {
|
||||
let slot_index = item.slot;
|
||||
match entry.bank_type {
|
||||
BankType::TILES => {
|
||||
if let Ok(bank) = Self::perform_load_tile_bank(&entry, self.assets_data.clone()) {
|
||||
if let Ok(bank) =
|
||||
Self::perform_load_tile_bank(&entry, self.assets_data.clone())
|
||||
{
|
||||
let bank_arc = Arc::new(bank);
|
||||
self.gfx_policy.put_resident(entry.asset_id, Arc::clone(&bank_arc), entry.decoded_size as usize);
|
||||
self.gfx_policy.put_resident(
|
||||
entry.asset_id,
|
||||
Arc::clone(&bank_arc),
|
||||
entry.decoded_size as usize,
|
||||
);
|
||||
self.gfx_installer.install_tile_bank(slot_index, bank_arc);
|
||||
let mut slots = self.gfx_slots.write().unwrap();
|
||||
if slot_index < slots.len() {
|
||||
slots[slot_index] = Some(entry.asset_id);
|
||||
}
|
||||
println!("[AssetManager] Preloaded tile asset '{}' (id: {}) into slot {}", entry.asset_name, entry.asset_id, slot_index);
|
||||
println!(
|
||||
"[AssetManager] Preloaded tile asset '{}' (id: {}) into slot {}",
|
||||
entry.asset_name, entry.asset_id, slot_index
|
||||
);
|
||||
} else {
|
||||
eprintln!("[AssetManager] Failed to preload tile asset '{}'", entry.asset_name);
|
||||
eprintln!(
|
||||
"[AssetManager] Failed to preload tile asset '{}'",
|
||||
entry.asset_name
|
||||
);
|
||||
}
|
||||
}
|
||||
BankType::SOUNDS => {
|
||||
if let Ok(bank) = Self::perform_load_sound_bank(&entry, self.assets_data.clone()) {
|
||||
if let Ok(bank) =
|
||||
Self::perform_load_sound_bank(&entry, self.assets_data.clone())
|
||||
{
|
||||
let bank_arc = Arc::new(bank);
|
||||
self.sound_policy.put_resident(entry.asset_id, Arc::clone(&bank_arc), entry.decoded_size as usize);
|
||||
self.sound_policy.put_resident(
|
||||
entry.asset_id,
|
||||
Arc::clone(&bank_arc),
|
||||
entry.decoded_size as usize,
|
||||
);
|
||||
self.sound_installer.install_sound_bank(slot_index, bank_arc);
|
||||
let mut slots = self.sound_slots.write().unwrap();
|
||||
if slot_index < slots.len() {
|
||||
slots[slot_index] = Some(entry.asset_id);
|
||||
}
|
||||
println!("[AssetManager] Preloaded sound asset '{}' (id: {}) into slot {}", entry.asset_name, entry.asset_id, slot_index);
|
||||
println!(
|
||||
"[AssetManager] Preloaded sound asset '{}' (id: {}) into slot {}",
|
||||
entry.asset_name, entry.asset_id, slot_index
|
||||
);
|
||||
} else {
|
||||
eprintln!("[AssetManager] Failed to preload sound asset '{}'", entry.asset_name);
|
||||
eprintln!(
|
||||
"[AssetManager] Failed to preload sound asset '{}'",
|
||||
entry.asset_name
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eprintln!("[AssetManager] Preload failed: asset '{}' not found in table", item.asset_name);
|
||||
eprintln!(
|
||||
"[AssetManager] Preload failed: asset '{}' not found in table",
|
||||
item.asset_name
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,7 +293,9 @@ impl AssetManager {
|
||||
let entry = {
|
||||
let assets = self.assets.read().unwrap();
|
||||
let name_to_id = self.name_to_id.read().unwrap();
|
||||
let id = name_to_id.get(asset_name).ok_or_else(|| format!("Asset not found: {}", asset_name))?;
|
||||
let id = name_to_id
|
||||
.get(asset_name)
|
||||
.ok_or_else(|| format!("Asset not found: {}", asset_name))?;
|
||||
assets.get(id).ok_or_else(|| format!("Asset ID {} not found in table", id))?.clone()
|
||||
};
|
||||
let asset_id = entry.asset_id;
|
||||
@@ -256,31 +314,33 @@ impl AssetManager {
|
||||
if let Some(bank) = self.gfx_policy.get_resident(asset_id) {
|
||||
self.gfx_policy.stage(handle_id, bank);
|
||||
true
|
||||
} else { false }
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
BankType::SOUNDS => {
|
||||
if let Some(bank) = self.sound_policy.get_resident(asset_id) {
|
||||
self.sound_policy.stage(handle_id, bank);
|
||||
true
|
||||
} else { false }
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if already_resident {
|
||||
self.handles.write().unwrap().insert(handle_id, LoadHandleInfo {
|
||||
_asset_id: asset_id,
|
||||
slot,
|
||||
status: LoadStatus::READY,
|
||||
});
|
||||
self.handles.write().unwrap().insert(
|
||||
handle_id,
|
||||
LoadHandleInfo { _asset_id: asset_id, slot, status: LoadStatus::READY },
|
||||
);
|
||||
return Ok(handle_id);
|
||||
}
|
||||
|
||||
// Not resident, start loading
|
||||
self.handles.write().unwrap().insert(handle_id, LoadHandleInfo {
|
||||
_asset_id: asset_id,
|
||||
slot,
|
||||
status: LoadStatus::PENDING,
|
||||
});
|
||||
self.handles.write().unwrap().insert(
|
||||
handle_id,
|
||||
LoadHandleInfo { _asset_id: asset_id, slot, status: LoadStatus::PENDING },
|
||||
);
|
||||
|
||||
let handles = self.handles.clone();
|
||||
let assets_data = self.assets_data.clone();
|
||||
@@ -319,7 +379,10 @@ impl AssetManager {
|
||||
existing.loads += 1;
|
||||
Arc::clone(&existing.value)
|
||||
} else {
|
||||
let entry = ResidentEntry::new(Arc::clone(&bank_arc), entry_clone.decoded_size as usize);
|
||||
let entry = ResidentEntry::new(
|
||||
Arc::clone(&bank_arc),
|
||||
entry_clone.decoded_size as usize,
|
||||
);
|
||||
map.insert(asset_id, entry);
|
||||
bank_arc
|
||||
}
|
||||
@@ -327,11 +390,15 @@ impl AssetManager {
|
||||
gfx_policy_staging.write().unwrap().insert(handle_id, resident_arc);
|
||||
let mut handles_map = handles.write().unwrap();
|
||||
if let Some(h) = handles_map.get_mut(&handle_id) {
|
||||
if h.status == LoadStatus::LOADING { h.status = LoadStatus::READY; }
|
||||
if h.status == LoadStatus::LOADING {
|
||||
h.status = LoadStatus::READY;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut handles_map = handles.write().unwrap();
|
||||
if let Some(h) = handles_map.get_mut(&handle_id) { h.status = LoadStatus::ERROR; }
|
||||
if let Some(h) = handles_map.get_mut(&handle_id) {
|
||||
h.status = LoadStatus::ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
BankType::SOUNDS => {
|
||||
@@ -345,7 +412,10 @@ impl AssetManager {
|
||||
existing.loads += 1;
|
||||
Arc::clone(&existing.value)
|
||||
} else {
|
||||
let entry = ResidentEntry::new(Arc::clone(&bank_arc), entry_clone.decoded_size as usize);
|
||||
let entry = ResidentEntry::new(
|
||||
Arc::clone(&bank_arc),
|
||||
entry_clone.decoded_size as usize,
|
||||
);
|
||||
map.insert(asset_id, entry);
|
||||
bank_arc
|
||||
}
|
||||
@@ -353,11 +423,15 @@ impl AssetManager {
|
||||
sound_policy_staging.write().unwrap().insert(handle_id, resident_arc);
|
||||
let mut handles_map = handles.write().unwrap();
|
||||
if let Some(h) = handles_map.get_mut(&handle_id) {
|
||||
if h.status == LoadStatus::LOADING { h.status = LoadStatus::READY; }
|
||||
if h.status == LoadStatus::LOADING {
|
||||
h.status = LoadStatus::READY;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut handles_map = handles.write().unwrap();
|
||||
if let Some(h) = handles_map.get_mut(&handle_id) { h.status = LoadStatus::ERROR; }
|
||||
if let Some(h) = handles_map.get_mut(&handle_id) {
|
||||
h.status = LoadStatus::ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,16 +440,19 @@ impl AssetManager {
|
||||
Ok(handle_id)
|
||||
}
|
||||
|
||||
fn perform_load_tile_bank(entry: &AssetEntry, assets_data: Arc<RwLock<Vec<u8>>>) -> Result<TileBank, String> {
|
||||
fn perform_load_tile_bank(
|
||||
entry: &AssetEntry,
|
||||
assets_data: Arc<RwLock<Vec<u8>>>,
|
||||
) -> Result<TileBank, String> {
|
||||
if entry.codec != "RAW" {
|
||||
return Err(format!("Unsupported codec: {}", entry.codec));
|
||||
}
|
||||
|
||||
let assets_data = assets_data.read().unwrap();
|
||||
|
||||
|
||||
let start = entry.offset as usize;
|
||||
let end = start + entry.size as usize;
|
||||
|
||||
|
||||
if end > assets_data.len() {
|
||||
return Err("Asset offset/size out of bounds".to_string());
|
||||
}
|
||||
@@ -383,9 +460,12 @@ impl AssetManager {
|
||||
let buffer = &assets_data[start..end];
|
||||
|
||||
// Decode TILEBANK metadata
|
||||
let tile_size_val = entry.metadata.get("tile_size").and_then(|v| v.as_u64()).ok_or("Missing tile_size")?;
|
||||
let width = entry.metadata.get("width").and_then(|v| v.as_u64()).ok_or("Missing width")? as usize;
|
||||
let height = entry.metadata.get("height").and_then(|v| v.as_u64()).ok_or("Missing height")? as usize;
|
||||
let tile_size_val =
|
||||
entry.metadata.get("tile_size").and_then(|v| v.as_u64()).ok_or("Missing tile_size")?;
|
||||
let width =
|
||||
entry.metadata.get("width").and_then(|v| v.as_u64()).ok_or("Missing width")? as usize;
|
||||
let height =
|
||||
entry.metadata.get("height").and_then(|v| v.as_u64()).ok_or("Missing height")? as usize;
|
||||
|
||||
let tile_size = match tile_size_val {
|
||||
8 => TileSize::Size8,
|
||||
@@ -406,42 +486,41 @@ impl AssetManager {
|
||||
for p in 0..64 {
|
||||
for c in 0..16 {
|
||||
let offset = (p * 16 + c) * 2;
|
||||
let color_raw = u16::from_le_bytes([palette_data[offset], palette_data[offset + 1]]);
|
||||
let color_raw =
|
||||
u16::from_le_bytes([palette_data[offset], palette_data[offset + 1]]);
|
||||
palettes[p][c] = Color(color_raw);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(TileBank {
|
||||
tile_size,
|
||||
width,
|
||||
height,
|
||||
pixel_indices,
|
||||
palettes,
|
||||
})
|
||||
Ok(TileBank { tile_size, width, height, pixel_indices, palettes })
|
||||
}
|
||||
|
||||
fn perform_load_sound_bank(entry: &AssetEntry, assets_data: Arc<RwLock<Vec<u8>>>) -> Result<SoundBank, String> {
|
||||
fn perform_load_sound_bank(
|
||||
entry: &AssetEntry,
|
||||
assets_data: Arc<RwLock<Vec<u8>>>,
|
||||
) -> Result<SoundBank, String> {
|
||||
if entry.codec != "RAW" {
|
||||
return Err(format!("Unsupported codec: {}", entry.codec));
|
||||
}
|
||||
|
||||
let assets_data = assets_data.read().unwrap();
|
||||
|
||||
|
||||
let start = entry.offset as usize;
|
||||
let end = start + entry.size as usize;
|
||||
|
||||
|
||||
if end > assets_data.len() {
|
||||
return Err("Asset offset/size out of bounds".to_string());
|
||||
}
|
||||
|
||||
let buffer = &assets_data[start..end];
|
||||
|
||||
let sample_rate = entry.metadata.get("sample_rate").and_then(|v| v.as_u64()).unwrap_or(44100) as u32;
|
||||
|
||||
let sample_rate =
|
||||
entry.metadata.get("sample_rate").and_then(|v| v.as_u64()).unwrap_or(44100) as u32;
|
||||
|
||||
let mut data = Vec::with_capacity(buffer.len() / 2);
|
||||
for i in (0..buffer.len()).step_by(2) {
|
||||
if i + 1 < buffer.len() {
|
||||
data.push(i16::from_le_bytes([buffer[i], buffer[i+1]]));
|
||||
data.push(i16::from_le_bytes([buffer[i], buffer[i + 1]]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -526,7 +605,7 @@ impl AssetManager {
|
||||
let staging = self.gfx_policy.staging.read().unwrap();
|
||||
let assets = self.assets.read().unwrap();
|
||||
let handles = self.handles.read().unwrap();
|
||||
|
||||
|
||||
for (handle_id, _) in staging.iter() {
|
||||
if let Some(h) = handles.get(handle_id) {
|
||||
if let Some(entry) = assets.get(&h._asset_id) {
|
||||
@@ -540,7 +619,9 @@ impl AssetManager {
|
||||
{
|
||||
let slots = self.gfx_slots.read().unwrap();
|
||||
for s in slots.iter() {
|
||||
if s.is_some() { slots_occupied += 1; }
|
||||
if s.is_some() {
|
||||
slots_occupied += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,7 +648,7 @@ impl AssetManager {
|
||||
let staging = self.sound_policy.staging.read().unwrap();
|
||||
let assets = self.assets.read().unwrap();
|
||||
let handles = self.handles.read().unwrap();
|
||||
|
||||
|
||||
for (handle_id, _) in staging.iter() {
|
||||
if let Some(h) = handles.get(handle_id) {
|
||||
if let Some(entry) = assets.get(&h._asset_id) {
|
||||
@@ -581,7 +662,9 @@ impl AssetManager {
|
||||
{
|
||||
let slots = self.sound_slots.read().unwrap();
|
||||
for s in slots.iter() {
|
||||
if s.is_some() { slots_occupied += 1; }
|
||||
if s.is_some() {
|
||||
slots_occupied += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,9 +685,13 @@ impl AssetManager {
|
||||
BankType::TILES => {
|
||||
let slots = self.gfx_slots.read().unwrap();
|
||||
let asset_id = slots.get(slot.index).and_then(|s| s.clone());
|
||||
|
||||
|
||||
let (bytes, asset_name) = if let Some(id) = &asset_id {
|
||||
let bytes = self.gfx_policy.resident.read().unwrap()
|
||||
let bytes = self
|
||||
.gfx_policy
|
||||
.resident
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(id)
|
||||
.map(|entry| entry.bytes)
|
||||
.unwrap_or(0);
|
||||
@@ -614,19 +701,18 @@ impl AssetManager {
|
||||
(0, None)
|
||||
};
|
||||
|
||||
SlotStats {
|
||||
asset_id,
|
||||
asset_name,
|
||||
generation: 0,
|
||||
resident_bytes: bytes,
|
||||
}
|
||||
SlotStats { asset_id, asset_name, generation: 0, resident_bytes: bytes }
|
||||
}
|
||||
BankType::SOUNDS => {
|
||||
let slots = self.sound_slots.read().unwrap();
|
||||
let asset_id = slots.get(slot.index).and_then(|s| s.clone());
|
||||
|
||||
|
||||
let (bytes, asset_name) = if let Some(id) = &asset_id {
|
||||
let bytes = self.sound_policy.resident.read().unwrap()
|
||||
let bytes = self
|
||||
.sound_policy
|
||||
.resident
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(id)
|
||||
.map(|entry| entry.bytes)
|
||||
.unwrap_or(0);
|
||||
@@ -636,12 +722,7 @@ impl AssetManager {
|
||||
(0, None)
|
||||
};
|
||||
|
||||
SlotStats {
|
||||
asset_id,
|
||||
asset_name,
|
||||
generation: 0,
|
||||
resident_bytes: bytes,
|
||||
}
|
||||
SlotStats { asset_id, asset_name, generation: 0, resident_bytes: bytes }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -663,7 +744,7 @@ impl AssetManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn shutdown(&self) {
|
||||
self.gfx_policy.clear();
|
||||
self.sound_policy.clear();
|
||||
@@ -705,18 +786,18 @@ mod tests {
|
||||
|
||||
let am = AssetManager::new(vec![asset_entry], data, gfx_installer, sound_installer);
|
||||
let slot = SlotRef::gfx(0);
|
||||
|
||||
|
||||
let handle = am.load("test_tiles", slot).expect("Should start loading");
|
||||
|
||||
|
||||
let mut status = am.status(handle);
|
||||
let start = Instant::now();
|
||||
while status != LoadStatus::READY && start.elapsed().as_secs() < 5 {
|
||||
thread::sleep(std::time::Duration::from_millis(10));
|
||||
status = am.status(handle);
|
||||
}
|
||||
|
||||
|
||||
assert_eq!(status, LoadStatus::READY);
|
||||
|
||||
|
||||
{
|
||||
let staging = am.gfx_policy.staging.read().unwrap();
|
||||
assert!(staging.contains_key(&handle));
|
||||
@@ -724,7 +805,7 @@ mod tests {
|
||||
|
||||
am.commit(handle);
|
||||
am.apply_commits();
|
||||
|
||||
|
||||
assert_eq!(am.status(handle), LoadStatus::COMMITTED);
|
||||
assert!(banks.tile_bank_slot(0).is_some());
|
||||
}
|
||||
@@ -754,13 +835,13 @@ mod tests {
|
||||
};
|
||||
|
||||
let am = AssetManager::new(vec![asset_entry], data, gfx_installer, sound_installer);
|
||||
|
||||
|
||||
let handle1 = am.load("test_tiles", SlotRef::gfx(0)).unwrap();
|
||||
let start = Instant::now();
|
||||
while am.status(handle1) != LoadStatus::READY && start.elapsed().as_secs() < 5 {
|
||||
thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
|
||||
|
||||
let handle2 = am.load("test_tiles", SlotRef::gfx(1)).unwrap();
|
||||
assert_eq!(am.status(handle2), LoadStatus::READY);
|
||||
|
||||
@@ -794,19 +875,19 @@ mod tests {
|
||||
|
||||
let am = AssetManager::new(vec![asset_entry], data, gfx_installer, sound_installer);
|
||||
let slot = SlotRef::audio(0);
|
||||
|
||||
|
||||
let handle = am.load("test_sound", slot).expect("Should start loading");
|
||||
|
||||
|
||||
let start = Instant::now();
|
||||
while am.status(handle) != LoadStatus::READY && start.elapsed().as_secs() < 5 {
|
||||
thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
|
||||
|
||||
assert_eq!(am.status(handle), LoadStatus::READY);
|
||||
|
||||
|
||||
am.commit(handle);
|
||||
am.apply_commits();
|
||||
|
||||
|
||||
assert_eq!(am.status(handle), LoadStatus::COMMITTED);
|
||||
assert!(banks.sound_bank_slot(0).is_some());
|
||||
}
|
||||
@@ -818,7 +899,7 @@ mod tests {
|
||||
let sound_installer = Arc::clone(&banks) as Arc<dyn SoundBankPoolInstaller>;
|
||||
|
||||
let data = vec![0u8; 200];
|
||||
|
||||
|
||||
let asset_entry = AssetEntry {
|
||||
asset_id: 2,
|
||||
asset_name: "preload_sound".to_string(),
|
||||
@@ -832,17 +913,15 @@ mod tests {
|
||||
}),
|
||||
};
|
||||
|
||||
let preload = vec![
|
||||
PreloadEntry { asset_name: "preload_sound".to_string(), slot: 5 }
|
||||
];
|
||||
let preload = vec![PreloadEntry { asset_name: "preload_sound".to_string(), slot: 5 }];
|
||||
|
||||
let am = AssetManager::new(vec![], vec![], gfx_installer, sound_installer);
|
||||
|
||||
|
||||
// Before init, slot 5 is empty
|
||||
assert!(banks.sound_bank_slot(5).is_none());
|
||||
|
||||
am.initialize_for_cartridge(vec![asset_entry], preload, data);
|
||||
|
||||
|
||||
// After init, slot 5 should be occupied because of preload
|
||||
assert!(banks.sound_bank_slot(5).is_some());
|
||||
assert_eq!(am.slot_info(SlotRef::audio(5)).asset_id, Some(2));
|
||||
@@ -868,9 +947,7 @@ mod tests {
|
||||
metadata: serde_json::json!({ "tile_size": 16, "width": 16, "height": 16 }),
|
||||
};
|
||||
|
||||
let preload = vec![
|
||||
PreloadEntry { asset_name: "my_tiles".to_string(), slot: 3 }
|
||||
];
|
||||
let preload = vec![PreloadEntry { asset_name: "my_tiles".to_string(), slot: 3 }];
|
||||
|
||||
let am = AssetManager::new(vec![], vec![], gfx_installer, sound_installer);
|
||||
am.initialize_for_cartridge(vec![asset_entry], preload, data);
|
||||
|
||||
Reference in New Issue
Block a user