mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Dynamic tile can also return the setting directly
This commit is contained in:
parent
5cfa64030a
commit
6853d36a9c
|
@ -3,7 +3,7 @@
|
|||
|
||||
use agb::display::{
|
||||
palette16::Palette16,
|
||||
tiled::{RegularBackgroundSize, TileFormat, TileSetting, TiledMap},
|
||||
tiled::{RegularBackgroundSize, TileFormat, TiledMap},
|
||||
Priority,
|
||||
};
|
||||
|
||||
|
@ -42,7 +42,7 @@ fn main(mut gba: agb::Gba) -> ! {
|
|||
&mut vram,
|
||||
(x as u16, y as u16).into(),
|
||||
&dynamic_tile.tile_set(),
|
||||
TileSetting::from_raw(dynamic_tile.tile_index()),
|
||||
dynamic_tile.tile_setting(),
|
||||
);
|
||||
|
||||
vram.remove_dynamic_tile(dynamic_tile);
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
|
||||
use agb::{
|
||||
display::{
|
||||
tiled::{
|
||||
RegularBackgroundSize, RegularMap, TileFormat, TileSetting, TiledMap, VRamManager,
|
||||
},
|
||||
tiled::{RegularBackgroundSize, RegularMap, TileFormat, TiledMap, VRamManager},
|
||||
Font, Priority,
|
||||
},
|
||||
include_font, include_wav,
|
||||
|
@ -110,7 +108,7 @@ fn init_background(bg: &mut RegularMap, vram: &mut VRamManager) {
|
|||
vram,
|
||||
(x, y).into(),
|
||||
&background_tile.tile_set(),
|
||||
TileSetting::from_raw(background_tile.tile_index()),
|
||||
background_tile.tile_setting(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
|
||||
use agb::{
|
||||
display::{
|
||||
tiled::{
|
||||
RegularBackgroundSize, RegularMap, TileFormat, TileSetting, TiledMap, VRamManager,
|
||||
},
|
||||
tiled::{RegularBackgroundSize, RegularMap, TileFormat, TiledMap, VRamManager},
|
||||
Font, Priority,
|
||||
},
|
||||
include_font, include_wav,
|
||||
|
@ -98,7 +96,7 @@ fn init_background(bg: &mut RegularMap, vram: &mut VRamManager) {
|
|||
vram,
|
||||
(x, y).into(),
|
||||
&background_tile.tile_set(),
|
||||
TileSetting::from_raw(background_tile.tile_index()),
|
||||
background_tile.tile_setting(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use agb::{
|
||||
display::{
|
||||
tiled::{RegularBackgroundSize, TileFormat, TileSetting, TiledMap},
|
||||
tiled::{RegularBackgroundSize, TileFormat, TiledMap},
|
||||
Font, Priority,
|
||||
},
|
||||
include_font,
|
||||
|
@ -37,7 +37,7 @@ fn main(mut gba: agb::Gba) -> ! {
|
|||
&mut vram,
|
||||
(x, y).into(),
|
||||
&background_tile.tile_set(),
|
||||
TileSetting::from_raw(background_tile.tile_index()),
|
||||
background_tile.tile_setting(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use core::fmt::{Error, Write};
|
|||
use crate::fixnum::Vector2D;
|
||||
use crate::hash_map::HashMap;
|
||||
|
||||
use super::tiled::{DynamicTile, RegularMap, TileSetting, VRamManager};
|
||||
use super::tiled::{DynamicTile, RegularMap, VRamManager};
|
||||
|
||||
/// The text renderer renders a variable width fixed size
|
||||
/// bitmap font using dynamic tiles as a rendering surface.
|
||||
|
@ -230,7 +230,7 @@ impl<'a, 'b> TextRenderer<'b> {
|
|||
vram_manager,
|
||||
(self.tile_pos.x + *x as u16, self.tile_pos.y + *y as u16).into(),
|
||||
&tile.tile_set(),
|
||||
TileSetting::from_raw(tile.tile_index()),
|
||||
tile.tile_setting(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ mod tests {
|
|||
&mut vram,
|
||||
(x, y).into(),
|
||||
&background_tile.tile_set(),
|
||||
TileSetting::from_raw(background_tile.tile_index()),
|
||||
background_tile.tile_setting(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ use crate::{
|
|||
memory_mapped::MemoryMapped1DArray,
|
||||
};
|
||||
|
||||
use super::TileSetting;
|
||||
|
||||
const TILE_RAM_START: usize = 0x0600_0000;
|
||||
|
||||
const PALETTE_BACKGROUND: MemoryMapped1DArray<u16, 256> =
|
||||
|
@ -189,9 +191,11 @@ impl DynamicTile<'_> {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn tile_index(&self) -> u16 {
|
||||
pub fn tile_setting(&self) -> TileSetting {
|
||||
let difference = self.tile_data.as_ptr() as usize - TILE_RAM_START;
|
||||
(difference / TileFormat::FourBpp.tile_size()) as u16
|
||||
let tile_id = (difference / TileFormat::FourBpp.tile_size()) as u16;
|
||||
|
||||
TileSetting::new(tile_id, false, false, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue