mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 17:41:33 +11:00
Use a concrete type for the TileReference
This commit is contained in:
parent
5793d6b6ab
commit
cd05fee360
|
@ -53,22 +53,24 @@ pub struct TileSetReference {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TileIndex(u16);
|
pub struct TileIndex(u16);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
struct TileReference(u16, u16);
|
||||||
|
|
||||||
enum VRamState {
|
enum VRamState {
|
||||||
ReferenceCounted(u16, (u16, u16)),
|
ReferenceCounted(u16, TileReference),
|
||||||
Free(u16),
|
Free(u16),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VRamState {
|
impl VRamState {
|
||||||
fn increase_reference(&mut self) -> u16 {
|
fn increase_reference(&mut self) {
|
||||||
if let VRamState::ReferenceCounted(count, _) = self {
|
if let VRamState::ReferenceCounted(count, _) = self {
|
||||||
*count += 1;
|
*count += 1;
|
||||||
*count
|
|
||||||
} else {
|
} else {
|
||||||
panic!("Corrupted vram state");
|
panic!("Corrupted vram state");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decrease_reference(&mut self) -> (u16, (u16, u16)) {
|
fn decrease_reference(&mut self) -> (u16, TileReference) {
|
||||||
if let VRamState::ReferenceCounted(count, tile_ref) = self {
|
if let VRamState::ReferenceCounted(count, tile_ref) = self {
|
||||||
*count -= 1;
|
*count -= 1;
|
||||||
(*count, *tile_ref)
|
(*count, *tile_ref)
|
||||||
|
@ -89,7 +91,7 @@ pub struct VRamManager<'a> {
|
||||||
generation: u16,
|
generation: u16,
|
||||||
free_pointer: Option<usize>,
|
free_pointer: Option<usize>,
|
||||||
|
|
||||||
tile_set_to_vram: HashMap<(u16, u16), u16>,
|
tile_set_to_vram: HashMap<TileReference, u16>,
|
||||||
references: Vec<VRamState>,
|
references: Vec<VRamState>,
|
||||||
vram_free_pointer: Option<usize>,
|
vram_free_pointer: Option<usize>,
|
||||||
}
|
}
|
||||||
|
@ -159,7 +161,7 @@ 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 = (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();
|
self.references[reference as usize].increase_reference();
|
||||||
return TileIndex(reference as u16);
|
return TileIndex(reference as u16);
|
||||||
|
@ -203,8 +205,10 @@ impl<'a> VRamManager<'a> {
|
||||||
TILE_BACKGROUND.set(index_to_copy_into * tile_size_in_words + i, word);
|
TILE_BACKGROUND.set(index_to_copy_into * tile_size_in_words + i, word);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.tile_set_to_vram
|
self.tile_set_to_vram.insert(
|
||||||
.insert((tile_set_ref.id, tile), index_to_copy_into as u16);
|
TileReference(tile_set_ref.id, tile),
|
||||||
|
index_to_copy_into as u16,
|
||||||
|
);
|
||||||
|
|
||||||
TileIndex(index_to_copy_into as u16)
|
TileIndex(index_to_copy_into as u16)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue