Generation makes more sense to be a u16 for better data storage

This commit is contained in:
Gwilym Kuiper 2022-01-23 19:04:09 +00:00
parent 0ebd2c2e40
commit 2044cbf379

View file

@ -42,7 +42,7 @@ impl<'a> TileSet<'a> {
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub struct TileSetReference { pub struct TileSetReference {
id: u16, id: u16,
generation: u32, generation: u16,
} }
#[derive(Debug)] #[derive(Debug)]
@ -51,12 +51,12 @@ pub struct TileIndex(u16);
enum ArenaStorageItem<T> { enum ArenaStorageItem<T> {
EndOfFreeList, EndOfFreeList,
NextFree(usize), NextFree(usize),
Data(T, u32), Data(T, u16),
} }
pub struct VRamManager<'a> { pub struct VRamManager<'a> {
tilesets: Vec<ArenaStorageItem<TileSet<'a>>>, tilesets: Vec<ArenaStorageItem<TileSet<'a>>>,
generation: u32, generation: u16,
free_pointer: Option<usize>, free_pointer: Option<usize>,
tile_set_to_vram: HashMap<(u16, u16), u16>, tile_set_to_vram: HashMap<(u16, u16), u16>,
@ -81,7 +81,7 @@ impl<'a> VRamManager<'a> {
pub fn add_tileset(&mut self, tileset: TileSet<'a>) -> TileSetReference { pub fn add_tileset(&mut self, tileset: TileSet<'a>) -> TileSetReference {
let generation = self.generation; let generation = self.generation;
self.generation += 1; self.generation = self.generation.wrapping_add(1);
let tileset = ArenaStorageItem::Data(tileset, generation); let tileset = ArenaStorageItem::Data(tileset, generation);
@ -332,7 +332,7 @@ impl Tiled0<'_> {
} }
impl TileSetReference { impl TileSetReference {
fn new(id: u16, generation: u32) -> Self { fn new(id: u16, generation: u16) -> Self {
Self { id, generation } Self { id, generation }
} }
} }