mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 00:01:34 +11:00
Generate the tileset directly
This commit is contained in:
parent
dc5bf9de98
commit
5cfa64030a
|
@ -114,6 +114,11 @@ pub(crate) fn generate_code(
|
|||
});
|
||||
|
||||
let data = ByteString(&tile_data);
|
||||
let tile_format = if assignment_offset.is_some() {
|
||||
quote! { #crate_prefix::display::tiled::TileFormat::FourBpp }
|
||||
} else {
|
||||
quote! { #crate_prefix::display::tiled::TileFormat::EightBpp }
|
||||
};
|
||||
|
||||
quote! {
|
||||
#[allow(non_upper_case_globals)]
|
||||
|
@ -134,11 +139,13 @@ pub(crate) fn generate_code(
|
|||
&ALIGNED.bytes
|
||||
};
|
||||
|
||||
const TILE_SET: #crate_prefix::display::tiled::TileSet = #crate_prefix::display::tiled::TileSet::new(TILE_DATA, #tile_format);
|
||||
|
||||
const TILE_SETTINGS: &[#crate_prefix::display::tiled::TileSetting] = &[
|
||||
#(#tile_settings),*
|
||||
];
|
||||
|
||||
#crate_prefix::display::tile_data::TileData::new(TILE_DATA, TILE_SETTINGS)
|
||||
#crate_prefix::display::tile_data::TileData::new(TILE_SET, TILE_SETTINGS)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use agb::{
|
||||
display::{
|
||||
affine::AffineMatrixBackground,
|
||||
tiled::{AffineBackgroundSize, TileFormat, TileSet, TiledMap},
|
||||
tiled::{AffineBackgroundSize, TiledMap},
|
||||
Priority,
|
||||
},
|
||||
fixnum::{num, Num},
|
||||
|
@ -18,7 +18,7 @@ fn main(mut gba: agb::Gba) -> ! {
|
|||
let (gfx, mut vram) = gba.display.video.tiled2();
|
||||
let vblank = agb::interrupt::VBlank::get();
|
||||
|
||||
let tileset = TileSet::new(affine_tiles::water_tiles.tiles, TileFormat::EightBpp);
|
||||
let tileset = affine_tiles::water_tiles.tiles;
|
||||
|
||||
vram.set_background_palettes(affine_tiles::PALETTES);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use agb::{
|
||||
display::{
|
||||
tiled::{RegularBackgroundSize, TileFormat, TileSet, TiledMap},
|
||||
tiled::{RegularBackgroundSize, TiledMap},
|
||||
Priority,
|
||||
},
|
||||
include_background_gfx,
|
||||
|
@ -16,14 +16,14 @@ fn main(mut gba: agb::Gba) -> ! {
|
|||
let (gfx, mut vram) = gba.display.video.tiled0();
|
||||
let vblank = agb::interrupt::VBlank::get();
|
||||
|
||||
let tileset = TileSet::new(water_tiles::water_tiles.tiles, TileFormat::FourBpp);
|
||||
let tileset = water_tiles::water_tiles.tiles;
|
||||
|
||||
vram.set_background_palettes(water_tiles::PALETTES);
|
||||
|
||||
let mut bg = gfx.background(
|
||||
Priority::P0,
|
||||
RegularBackgroundSize::Background32x32,
|
||||
TileFormat::FourBpp,
|
||||
tileset.format(),
|
||||
);
|
||||
|
||||
for y in 0..20u16 {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use super::tiled::{RegularMap, TileFormat, TileSet, TiledMap, VRamManager};
|
||||
use super::tiled::{RegularMap, TiledMap, VRamManager};
|
||||
|
||||
crate::include_background_gfx!(crate, agb_logo, test_logo => deduplicate "gfx/test_logo.png");
|
||||
|
||||
pub fn display_logo(map: &mut RegularMap, vram: &mut VRamManager) {
|
||||
vram.set_background_palettes(agb_logo::PALETTES);
|
||||
|
||||
let background_tilemap = TileSet::new(agb_logo::test_logo.tiles, TileFormat::FourBpp);
|
||||
let background_tilemap = agb_logo::test_logo.tiles;
|
||||
|
||||
for y in 0..20 {
|
||||
for x in 0..30 {
|
||||
|
@ -37,7 +37,7 @@ mod tests {
|
|||
let mut map = gfx.background(
|
||||
Priority::P0,
|
||||
RegularBackgroundSize::Background32x32,
|
||||
TileFormat::FourBpp,
|
||||
agb_logo::test_logo.tiles.format(),
|
||||
);
|
||||
|
||||
display_logo(&mut map, &mut vram);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
use super::tiled::TileSetting;
|
||||
use super::tiled::{TileSet, TileSetting};
|
||||
|
||||
#[non_exhaustive]
|
||||
pub struct TileData {
|
||||
pub tiles: &'static [u8],
|
||||
pub tiles: TileSet<'static>,
|
||||
pub tile_settings: &'static [TileSetting],
|
||||
}
|
||||
|
||||
impl TileData {
|
||||
#[must_use]
|
||||
pub const fn new(tiles: &'static [u8], tile_settings: &'static [TileSetting]) -> Self {
|
||||
pub const fn new(tiles: TileSet<'static>, tile_settings: &'static [TileSetting]) -> Self {
|
||||
TileData {
|
||||
tiles,
|
||||
tile_settings,
|
||||
|
|
|
@ -49,17 +49,18 @@ pub struct TileSet<'a> {
|
|||
|
||||
impl<'a> TileSet<'a> {
|
||||
#[must_use]
|
||||
pub fn new(tiles: &'a [u8], format: TileFormat) -> Self {
|
||||
pub const fn new(tiles: &'a [u8], format: TileFormat) -> Self {
|
||||
Self { tiles, format }
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn format(&self) -> TileFormat {
|
||||
self.format
|
||||
}
|
||||
|
||||
fn reference(&self) -> NonNull<[u8]> {
|
||||
self.tiles.into()
|
||||
}
|
||||
|
||||
pub(crate) fn format(&self) -> TileFormat {
|
||||
self.format
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
Loading…
Reference in a new issue