mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 16:51:33 +11:00
Rearrange methods to make a bit more sense
This commit is contained in:
parent
c1cbb442a1
commit
9e8318cdf9
|
@ -177,54 +177,6 @@ impl<'a> VRamManager<'a> {
|
||||||
TileReference(NonNull::new(ptr as *mut _).unwrap())
|
TileReference(NonNull::new(ptr as *mut _).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_tile_to_location(
|
|
||||||
&self,
|
|
||||||
tile_set_ref: TileSetReference,
|
|
||||||
tile_id: u16,
|
|
||||||
tile_reference: TileReference,
|
|
||||||
) {
|
|
||||||
let tile_slice = if let ArenaStorageItem::Data(data, generation) =
|
|
||||||
&self.tilesets[tile_set_ref.id as usize]
|
|
||||||
{
|
|
||||||
debug_assert_eq!(
|
|
||||||
*generation, tile_set_ref.generation,
|
|
||||||
"Stale tile data requested"
|
|
||||||
);
|
|
||||||
|
|
||||||
let tile_offset = (tile_id as usize) * data.format.tile_size();
|
|
||||||
&data.tiles[tile_offset..(tile_offset + data.format.tile_size())]
|
|
||||||
} else {
|
|
||||||
panic!("Target tile set ref must point to an existing tile set reference")
|
|
||||||
};
|
|
||||||
|
|
||||||
let tile_size_in_half_words = tile_slice.len() / 2;
|
|
||||||
|
|
||||||
let target_location = tile_reference.0.as_ptr() as *mut _;
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
dma_copy16(
|
|
||||||
tile_slice.as_ptr() as *const u16,
|
|
||||||
target_location,
|
|
||||||
tile_size_in_half_words,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn replace_tile(
|
|
||||||
&mut self,
|
|
||||||
source_tile_set_ref: TileSetReference,
|
|
||||||
source_tile: u16,
|
|
||||||
target_tile_set_ref: TileSetReference,
|
|
||||||
target_tile: u16,
|
|
||||||
) {
|
|
||||||
if let Some(&reference) = self
|
|
||||||
.tile_set_to_vram
|
|
||||||
.get(&(source_tile_set_ref.id, source_tile))
|
|
||||||
{
|
|
||||||
self.copy_tile_to_location(target_tile_set_ref, target_tile, reference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn add_tile(&mut self, tile_set_ref: TileSetReference, tile: u16) -> TileIndex {
|
pub(crate) fn add_tile(&mut self, tile_set_ref: TileSetReference, tile: u16) -> TileIndex {
|
||||||
let reference = self.tile_set_to_vram.get(&(tile_set_ref.id, tile));
|
let reference = self.tile_set_to_vram.get(&(tile_set_ref.id, tile));
|
||||||
|
|
||||||
|
@ -277,6 +229,54 @@ impl<'a> VRamManager<'a> {
|
||||||
self.reference_counts[index].1 = None;
|
self.reference_counts[index].1 = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn replace_tile(
|
||||||
|
&mut self,
|
||||||
|
source_tile_set_ref: TileSetReference,
|
||||||
|
source_tile: u16,
|
||||||
|
target_tile_set_ref: TileSetReference,
|
||||||
|
target_tile: u16,
|
||||||
|
) {
|
||||||
|
if let Some(&reference) = self
|
||||||
|
.tile_set_to_vram
|
||||||
|
.get(&(source_tile_set_ref.id, source_tile))
|
||||||
|
{
|
||||||
|
self.copy_tile_to_location(target_tile_set_ref, target_tile, reference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn copy_tile_to_location(
|
||||||
|
&self,
|
||||||
|
tile_set_ref: TileSetReference,
|
||||||
|
tile_id: u16,
|
||||||
|
tile_reference: TileReference,
|
||||||
|
) {
|
||||||
|
let tile_slice = if let ArenaStorageItem::Data(data, generation) =
|
||||||
|
&self.tilesets[tile_set_ref.id as usize]
|
||||||
|
{
|
||||||
|
debug_assert_eq!(
|
||||||
|
*generation, tile_set_ref.generation,
|
||||||
|
"Stale tile data requested"
|
||||||
|
);
|
||||||
|
|
||||||
|
let tile_offset = (tile_id as usize) * data.format.tile_size();
|
||||||
|
&data.tiles[tile_offset..(tile_offset + data.format.tile_size())]
|
||||||
|
} else {
|
||||||
|
panic!("Target tile set ref must point to an existing tile set reference")
|
||||||
|
};
|
||||||
|
|
||||||
|
let tile_size_in_half_words = tile_slice.len() / 2;
|
||||||
|
|
||||||
|
let target_location = tile_reference.0.as_ptr() as *mut _;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
dma_copy16(
|
||||||
|
tile_slice.as_ptr() as *const u16,
|
||||||
|
target_location,
|
||||||
|
tile_size_in_half_words,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Copies raw palettes to the background palette without any checks.
|
/// Copies raw palettes to the background palette without any checks.
|
||||||
pub fn set_background_palette_raw(&mut self, palette: &[u16]) {
|
pub fn set_background_palette_raw(&mut self, palette: &[u16]) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in a new issue