This commit is contained in:
Nilton Constantino 2026-01-22 11:47:32 +00:00
parent 0374f57242
commit e2e1ee2db9
No known key found for this signature in database
3 changed files with 17 additions and 17 deletions

View File

@ -343,7 +343,7 @@ impl AssetManager {
if h.status == LoadStatus::READY {
if let Some(bank) = self.gfx_policy.take_staging(handle_id) {
if h.slot.asset_type == BankType::TILES {
self.gfx_installer.install_tilebank(h.slot.index, bank);
self.gfx_installer.install_tile_bank(h.slot.index, bank);
// Update internal tracking of what's in the slot
let mut slots = self.gfx_slots.write().unwrap();
@ -477,7 +477,7 @@ mod tests {
am.apply_commits();
assert_eq!(am.status(handle), LoadStatus::COMMITTED);
assert!(banks.tilebank_slot(0).is_some());
assert!(banks.tile_bank_slot(0).is_some());
}
#[test]

View File

@ -334,7 +334,7 @@ impl Gfx {
// Order: Layer 0 -> Sprites 1 -> Layer 1 -> Sprites 2 ...
for i in 0..self.layers.len() {
let bank_id = self.layers[i].bank_id as usize;
if let Some(bank) = self.tile_banks.tilebank_slot(bank_id) {
if let Some(bank) = self.tile_banks.tile_bank_slot(bank_id) {
Self::draw_tile_map(&mut self.back, self.w, self.h, &self.layers[i].map, &bank, self.layers[i].scroll_x, self.layers[i].scroll_y);
}
@ -360,7 +360,7 @@ impl Gfx {
let scroll_x = self.layers[layer_idx].scroll_x;
let scroll_y = self.layers[layer_idx].scroll_y;
let bank = match self.tile_banks.tilebank_slot(bank_id) {
let bank = match self.tile_banks.tile_bank_slot(bank_id) {
Some(b) => b,
_ => return,
};
@ -375,7 +375,7 @@ impl Gfx {
fn render_hud_with_pool(back: &mut [u16], w: usize, h: usize, hud: &HudTileLayer, tile_banks: &dyn GfxTileBankPoolAccess) {
let bank_id = hud.bank_id as usize;
let bank = match tile_banks.tilebank_slot(bank_id) {
let bank = match tile_banks.tile_bank_slot(bank_id) {
Some(b) => b,
_ => return,
};
@ -473,7 +473,7 @@ impl Gfx {
for &idx in bucket {
let s = &sprites[idx];
let bank_id = s.bank_id as usize;
if let Some(bank) = tile_banks.tilebank_slot(bank_id) {
if let Some(bank) = tile_banks.tile_bank_slot(bank_id) {
Self::draw_sprite_pixel_by_pixel(back, screen_w, screen_h, s, &bank);
}
}

View File

@ -4,49 +4,49 @@ use crate::model::TileBank;
/// Non-generic interface for peripherals to access graphical tile banks.
pub trait GfxTileBankPoolAccess: Send + Sync {
/// Returns a reference to the resident TileBank in the specified slot, if any.
fn tilebank_slot(&self, slot: usize) -> Option<Arc<TileBank>>;
fn tile_bank_slot(&self, slot: usize) -> Option<Arc<TileBank>>;
/// Returns the total number of slots available in this bank.
fn tilebank_slot_count(&self) -> usize;
fn tile_bank_slot_count(&self) -> usize;
}
/// Non-generic interface for the AssetManager to install graphical tile banks.
pub trait GfxTileBankPoolInstaller: Send + Sync {
/// Atomically swaps the resident TileBank in the specified slot.
fn install_tilebank(&self, slot: usize, bank: Arc<TileBank>);
fn install_tile_bank(&self, slot: usize, bank: Arc<TileBank>);
}
/// Centralized container for all hardware memory banks.
///
/// MemoryBanks represents the actual hardware slot state.
/// MemoryBanks represent the actual hardware slot state.
/// Peripherals consume this state via narrow, non-generic traits.
/// AssetManager coordinates residency and installs assets into these slots.
pub struct MemoryBanks {
gfx_tilebank_pool: Arc<RwLock<[Option<Arc<TileBank>>; 16]>>,
gfx_tile_bank_pool: Arc<RwLock<[Option<Arc<TileBank>>; 16]>>,
}
impl MemoryBanks {
/// Creates a new set of memory banks with empty slots.
pub fn new() -> Self {
Self {
gfx_tilebank_pool: Arc::new(RwLock::new(std::array::from_fn(|_| None))),
gfx_tile_bank_pool: Arc::new(RwLock::new(std::array::from_fn(|_| None))),
}
}
}
impl GfxTileBankPoolAccess for MemoryBanks {
fn tilebank_slot(&self, slot: usize) -> Option<Arc<TileBank>> {
let pool = self.gfx_tilebank_pool.read().unwrap();
fn tile_bank_slot(&self, slot: usize) -> Option<Arc<TileBank>> {
let pool = self.gfx_tile_bank_pool.read().unwrap();
pool.get(slot).and_then(|s| s.as_ref().map(Arc::clone))
}
fn tilebank_slot_count(&self) -> usize {
fn tile_bank_slot_count(&self) -> usize {
16
}
}
impl GfxTileBankPoolInstaller for MemoryBanks {
fn install_tilebank(&self, slot: usize, bank: Arc<TileBank>) {
let mut pool = self.gfx_tilebank_pool.write().unwrap();
fn install_tile_bank(&self, slot: usize, bank: Arc<TileBank>) {
let mut pool = self.gfx_tile_bank_pool.write().unwrap();
if slot < 16 {
pool[slot] = Some(bank);
}