split preload from asset table
This commit is contained in:
parent
c450e530f6
commit
8d97f6225b
@ -15,6 +15,7 @@ impl LoadCartridgeStep {
|
||||
// Initialize Asset Manager
|
||||
ctx.hw.assets_mut().initialize_for_cartridge(
|
||||
self.cartridge.asset_table.clone(),
|
||||
self.cartridge.preload.clone(),
|
||||
self.cartridge.assets.clone()
|
||||
);
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use crate::hardware::memory_banks::{TileBankPoolInstaller, SoundBankPoolInstaller};
|
||||
use crate::model::{AssetEntry, BankStats, BankType, Color, HandleId, LoadStatus, SlotRef, SlotStats, TileBank, TileSize, SoundBank, Sample};
|
||||
use crate::model::{AssetEntry, BankStats, BankType, Color, HandleId, LoadStatus, SlotRef, SlotStats, TileBank, TileSize, SoundBank, Sample, PreloadEntry};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
use std::thread;
|
||||
@ -149,7 +149,7 @@ impl AssetManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initialize_for_cartridge(&self, assets: Vec<AssetEntry>, 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();
|
||||
@ -160,9 +160,15 @@ impl AssetManager {
|
||||
}
|
||||
*self.assets_data.write().unwrap() = assets_data;
|
||||
|
||||
// Perform Preload for assets marked with preload_slot
|
||||
for entry in assets {
|
||||
if let Some(slot_index) = entry.preload_slot {
|
||||
// Perform Preload for assets in the preload list
|
||||
for item in preload {
|
||||
let entry_opt = {
|
||||
let assets = self.assets.read().unwrap();
|
||||
assets.get(&item.asset_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()) {
|
||||
@ -193,6 +199,8 @@ impl AssetManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eprintln!("[AssetManager] Preload failed: asset '{}' not found in table", item.asset_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -638,7 +646,6 @@ mod tests {
|
||||
"width": 16,
|
||||
"height": 16
|
||||
}),
|
||||
preload_slot: None,
|
||||
};
|
||||
|
||||
let am = AssetManager::new(vec![asset_entry], data, gfx_installer, sound_installer);
|
||||
@ -688,7 +695,6 @@ mod tests {
|
||||
"width": 16,
|
||||
"height": 16
|
||||
}),
|
||||
preload_slot: None,
|
||||
};
|
||||
|
||||
let am = AssetManager::new(vec![asset_entry], data, gfx_installer, sound_installer);
|
||||
@ -727,7 +733,6 @@ mod tests {
|
||||
metadata: serde_json::json!({
|
||||
"sample_rate": 44100
|
||||
}),
|
||||
preload_slot: None,
|
||||
};
|
||||
|
||||
let am = AssetManager::new(vec![asset_entry], data, gfx_installer, sound_installer);
|
||||
@ -767,15 +772,18 @@ mod tests {
|
||||
metadata: serde_json::json!({
|
||||
"sample_rate": 44100
|
||||
}),
|
||||
preload_slot: Some(5),
|
||||
};
|
||||
|
||||
let preload = vec![
|
||||
PreloadEntry { asset_id: "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], data);
|
||||
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());
|
||||
|
||||
@ -20,8 +20,12 @@ pub struct AssetEntry {
|
||||
pub decoded_size: u64,
|
||||
pub codec: String, // e.g., "RAW"
|
||||
pub metadata: serde_json::Value,
|
||||
#[serde(default)]
|
||||
pub preload_slot: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct PreloadEntry {
|
||||
pub asset_id: String,
|
||||
pub slot: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use crate::model::asset::AssetEntry;
|
||||
use crate::model::asset::{AssetEntry, PreloadEntry};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
|
||||
@ -17,6 +17,7 @@ pub struct Cartridge {
|
||||
pub program: Vec<u8>,
|
||||
pub assets: Vec<u8>,
|
||||
pub asset_table: Vec<AssetEntry>,
|
||||
pub preload: Vec<PreloadEntry>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
@ -30,6 +31,8 @@ pub struct CartridgeDTO {
|
||||
pub assets: Vec<u8>,
|
||||
#[serde(default)]
|
||||
pub asset_table: Vec<AssetEntry>,
|
||||
#[serde(default)]
|
||||
pub preload: Vec<PreloadEntry>,
|
||||
}
|
||||
|
||||
impl From<CartridgeDTO> for Cartridge {
|
||||
@ -43,6 +46,7 @@ impl From<CartridgeDTO> for Cartridge {
|
||||
program: dto.program,
|
||||
assets: dto.assets,
|
||||
asset_table: dto.asset_table,
|
||||
preload: dto.preload,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -68,4 +72,6 @@ pub struct CartridgeManifest {
|
||||
pub entrypoint: String,
|
||||
#[serde(default)]
|
||||
pub asset_table: Vec<AssetEntry>,
|
||||
#[serde(default)]
|
||||
pub preload: Vec<PreloadEntry>,
|
||||
}
|
||||
|
||||
@ -64,6 +64,7 @@ impl DirectoryCartridgeLoader {
|
||||
program,
|
||||
assets,
|
||||
asset_table: manifest.asset_table,
|
||||
preload: manifest.preload,
|
||||
};
|
||||
|
||||
Ok(Cartridge::from(dto))
|
||||
|
||||
@ -11,7 +11,7 @@ mod cartridge;
|
||||
mod cartridge_loader;
|
||||
mod window;
|
||||
|
||||
pub use asset::{AssetEntry, BankType, BankStats, LoadStatus, SlotRef, SlotStats, HandleId};
|
||||
pub use asset::{AssetEntry, BankType, BankStats, LoadStatus, SlotRef, SlotStats, HandleId, PreloadEntry};
|
||||
pub use button::{Button, ButtonId};
|
||||
pub use cartridge::{AppMode, Cartridge, CartridgeDTO, CartridgeError};
|
||||
pub use cartridge_loader::{CartridgeLoader, DirectoryCartridgeLoader, PackedCartridgeLoader};
|
||||
|
||||
@ -399,6 +399,7 @@ mod tests {
|
||||
program: rom,
|
||||
assets: vec![],
|
||||
asset_table: vec![],
|
||||
preload: vec![],
|
||||
};
|
||||
os.initialize_vm(&mut vm, &cartridge);
|
||||
|
||||
@ -440,6 +441,7 @@ mod tests {
|
||||
program: rom,
|
||||
assets: vec![],
|
||||
asset_table: vec![],
|
||||
preload: vec![],
|
||||
};
|
||||
os.initialize_vm(&mut vm, &cartridge);
|
||||
|
||||
|
||||
@ -16,8 +16,7 @@
|
||||
"codec": "RAW",
|
||||
"metadata": {
|
||||
"sample_rate": 44100
|
||||
},
|
||||
"preload_slot": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"asset_id": "mouse_cursor",
|
||||
@ -30,8 +29,11 @@
|
||||
"tile_size": 16,
|
||||
"width": 16,
|
||||
"height": 16
|
||||
},
|
||||
"preload_slot": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"preload": [
|
||||
{ "asset_id": "bgm_music", "slot": 0 },
|
||||
{ "asset_id": "mouse_cursor", "slot": 1 }
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user