Add gc step for tiles

This commit is contained in:
Gwilym Kuiper 2022-04-23 23:03:02 +01:00
parent 7688316034
commit 178db91072
4 changed files with 18 additions and 11 deletions

View file

@ -116,6 +116,10 @@ impl TileReferenceCount {
self.reference_count = 0;
self.tile_in_tile_set = None;
}
fn current_count(&self) -> u16 {
self.reference_count
}
}
#[non_exhaustive]
@ -279,6 +283,9 @@ impl VRamManager {
pub(crate) fn gc(&mut self) {
for tile_index in self.indices_to_gc.drain(..) {
let index = tile_index.index() as usize;
if self.reference_counts[index].current_count() > 0 {
continue; // it has since been added back
}
let tile_reference = Self::reference_from_index(tile_index);
unsafe {

View file

@ -273,8 +273,8 @@ impl<'a, 'b> Map<'a, 'b> {
self.background.set_pos(vram, self.position.floor());
self.foreground.set_pos(vram, self.position.floor());
self.background.commit();
self.foreground.commit();
self.background.commit(vram);
self.foreground.commit(vram);
}
pub fn init_background(&mut self, vram: &mut VRamManager) -> PartialUpdateStatus {
@ -793,7 +793,7 @@ fn main(mut agb: agb::Gba) -> ! {
}
}
world_display.commit();
world_display.commit(&mut vram);
world_display.show();
splash_screen::show_splash_screen(
@ -835,7 +835,7 @@ fn main(mut agb: agb::Gba) -> ! {
&mut vram,
);
world_display.commit();
world_display.commit(&mut vram);
world_display.show();
music_box.before_frame(&mut mixer);

View file

@ -76,7 +76,7 @@ pub fn show_splash_screen(
}
}
map.commit();
map.commit(vram);
vram.set_background_palettes(palette);
map.show();

View file

@ -85,9 +85,9 @@ impl<'a> Level<'a> {
foreground.init(vram, start_pos, &mut between_updates);
clouds.init(vram, start_pos / 4, &mut between_updates);
backdrop.commit();
foreground.commit();
clouds.commit();
backdrop.commit(vram);
foreground.commit(vram);
clouds.commit(vram);
backdrop.show();
foreground.show();
@ -2081,9 +2081,9 @@ impl<'a> Game<'a> {
.commit_with_fudge(this_frame_offset, (0, 0).into());
}
self.level.background.commit();
self.level.foreground.commit();
self.level.clouds.commit();
self.level.background.commit(vram);
self.level.foreground.commit(vram);
self.level.clouds.commit(vram);
for i in remove {
self.particles.remove(i);