mirror of
https://github.com/italicsjenga/agb.git
synced 2025-02-04 21:46:39 +11:00
Track the generation along with the tile data
This commit is contained in:
parent
7d870163c3
commit
666867e933
1 changed files with 6 additions and 4 deletions
|
@ -95,7 +95,7 @@ pub struct VRamManager<'a> {
|
||||||
generation: u16,
|
generation: u16,
|
||||||
free_pointer: Option<usize>,
|
free_pointer: Option<usize>,
|
||||||
|
|
||||||
tile_set_to_vram: HashMap<TileReference, u16>,
|
tile_set_to_vram: HashMap<TileReference, (u16, u16)>,
|
||||||
references: Vec<VRamState>,
|
references: Vec<VRamState>,
|
||||||
vram_free_pointer: Option<usize>,
|
vram_free_pointer: Option<usize>,
|
||||||
}
|
}
|
||||||
|
@ -167,8 +167,10 @@ impl<'a> VRamManager<'a> {
|
||||||
fn add_tile(&mut self, tile_set_ref: TileSetReference, tile: u16) -> TileIndex {
|
fn add_tile(&mut self, tile_set_ref: TileSetReference, tile: u16) -> TileIndex {
|
||||||
let tile_ref = TileReference(tile_set_ref.id, tile);
|
let tile_ref = TileReference(tile_set_ref.id, tile);
|
||||||
if let Some(&reference) = self.tile_set_to_vram.get(&tile_ref) {
|
if let Some(&reference) = self.tile_set_to_vram.get(&tile_ref) {
|
||||||
self.references[reference as usize].increase_reference();
|
if reference.1 == tile_set_ref.generation {
|
||||||
return TileIndex(reference as u16);
|
self.references[reference.0 as usize].increase_reference();
|
||||||
|
return TileIndex(reference.0 as u16);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let index_to_copy_into = if let Some(ptr) = self.vram_free_pointer.take() {
|
let index_to_copy_into = if let Some(ptr) = self.vram_free_pointer.take() {
|
||||||
|
@ -211,7 +213,7 @@ impl<'a> VRamManager<'a> {
|
||||||
|
|
||||||
self.tile_set_to_vram.insert(
|
self.tile_set_to_vram.insert(
|
||||||
TileReference(tile_set_ref.id, tile),
|
TileReference(tile_set_ref.id, tile),
|
||||||
index_to_copy_into as u16,
|
(index_to_copy_into as u16, tile_set_ref.generation),
|
||||||
);
|
);
|
||||||
|
|
||||||
TileIndex(index_to_copy_into as u16)
|
TileIndex(index_to_copy_into as u16)
|
||||||
|
|
Loading…
Add table
Reference in a new issue