mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +11:00
add garbage collection using hashmap retain
This commit is contained in:
parent
7143621407
commit
5e0795ae14
|
@ -46,9 +46,8 @@ fn all_sprites(gfx: &ObjectController) {
|
|||
if count % 5 == 0 {
|
||||
image += 1;
|
||||
image %= SPRITES.len();
|
||||
let objs_len = objs.len();
|
||||
for (i, obj) in objs.iter_mut().enumerate() {
|
||||
let this_image = (image + i * SPRITES.len() / objs_len) % SPRITES.len();
|
||||
let this_image = (image + i) % SPRITES.len();
|
||||
obj.set_sprite(gfx.sprite(&SPRITES[this_image]));
|
||||
}
|
||||
gfx.commit();
|
||||
|
|
|
@ -741,6 +741,8 @@ impl ObjectController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
s.sprite_controller.gc();
|
||||
}
|
||||
|
||||
pub(crate) fn new() -> Self {
|
||||
|
@ -1186,6 +1188,12 @@ impl SpriteControllerInner {
|
|||
Some(SpriteBorrow { sprite })
|
||||
}
|
||||
|
||||
/// Cleans up weak references to sprites and palettes no longer in vram
|
||||
fn gc(&mut self) {
|
||||
self.static_palette_map.retain(|_, v| v.strong_count() != 0);
|
||||
self.static_sprite_map.retain(|_, v| v.strong_count() != 0);
|
||||
}
|
||||
|
||||
fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue