mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-04 06:01:35 +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 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! {
|
quote! {
|
||||||
#[allow(non_upper_case_globals)]
|
#[allow(non_upper_case_globals)]
|
||||||
|
@ -134,11 +139,13 @@ pub(crate) fn generate_code(
|
||||||
&ALIGNED.bytes
|
&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] = &[
|
const TILE_SETTINGS: &[#crate_prefix::display::tiled::TileSetting] = &[
|
||||||
#(#tile_settings),*
|
#(#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::{
|
use agb::{
|
||||||
display::{
|
display::{
|
||||||
affine::AffineMatrixBackground,
|
affine::AffineMatrixBackground,
|
||||||
tiled::{AffineBackgroundSize, TileFormat, TileSet, TiledMap},
|
tiled::{AffineBackgroundSize, TiledMap},
|
||||||
Priority,
|
Priority,
|
||||||
},
|
},
|
||||||
fixnum::{num, Num},
|
fixnum::{num, Num},
|
||||||
|
@ -18,7 +18,7 @@ fn main(mut gba: agb::Gba) -> ! {
|
||||||
let (gfx, mut vram) = gba.display.video.tiled2();
|
let (gfx, mut vram) = gba.display.video.tiled2();
|
||||||
let vblank = agb::interrupt::VBlank::get();
|
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);
|
vram.set_background_palettes(affine_tiles::PALETTES);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use agb::{
|
use agb::{
|
||||||
display::{
|
display::{
|
||||||
tiled::{RegularBackgroundSize, TileFormat, TileSet, TiledMap},
|
tiled::{RegularBackgroundSize, TiledMap},
|
||||||
Priority,
|
Priority,
|
||||||
},
|
},
|
||||||
include_background_gfx,
|
include_background_gfx,
|
||||||
|
@ -16,14 +16,14 @@ fn main(mut gba: agb::Gba) -> ! {
|
||||||
let (gfx, mut vram) = gba.display.video.tiled0();
|
let (gfx, mut vram) = gba.display.video.tiled0();
|
||||||
let vblank = agb::interrupt::VBlank::get();
|
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);
|
vram.set_background_palettes(water_tiles::PALETTES);
|
||||||
|
|
||||||
let mut bg = gfx.background(
|
let mut bg = gfx.background(
|
||||||
Priority::P0,
|
Priority::P0,
|
||||||
RegularBackgroundSize::Background32x32,
|
RegularBackgroundSize::Background32x32,
|
||||||
TileFormat::FourBpp,
|
tileset.format(),
|
||||||
);
|
);
|
||||||
|
|
||||||
for y in 0..20u16 {
|
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");
|
crate::include_background_gfx!(crate, agb_logo, test_logo => deduplicate "gfx/test_logo.png");
|
||||||
|
|
||||||
pub fn display_logo(map: &mut RegularMap, vram: &mut VRamManager) {
|
pub fn display_logo(map: &mut RegularMap, vram: &mut VRamManager) {
|
||||||
vram.set_background_palettes(agb_logo::PALETTES);
|
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 y in 0..20 {
|
||||||
for x in 0..30 {
|
for x in 0..30 {
|
||||||
|
@ -37,7 +37,7 @@ mod tests {
|
||||||
let mut map = gfx.background(
|
let mut map = gfx.background(
|
||||||
Priority::P0,
|
Priority::P0,
|
||||||
RegularBackgroundSize::Background32x32,
|
RegularBackgroundSize::Background32x32,
|
||||||
TileFormat::FourBpp,
|
agb_logo::test_logo.tiles.format(),
|
||||||
);
|
);
|
||||||
|
|
||||||
display_logo(&mut map, &mut vram);
|
display_logo(&mut map, &mut vram);
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use super::tiled::TileSetting;
|
use super::tiled::{TileSet, TileSetting};
|
||||||
|
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct TileData {
|
pub struct TileData {
|
||||||
pub tiles: &'static [u8],
|
pub tiles: TileSet<'static>,
|
||||||
pub tile_settings: &'static [TileSetting],
|
pub tile_settings: &'static [TileSetting],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TileData {
|
impl TileData {
|
||||||
#[must_use]
|
#[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 {
|
TileData {
|
||||||
tiles,
|
tiles,
|
||||||
tile_settings,
|
tile_settings,
|
||||||
|
|
|
@ -49,17 +49,18 @@ pub struct TileSet<'a> {
|
||||||
|
|
||||||
impl<'a> TileSet<'a> {
|
impl<'a> TileSet<'a> {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(tiles: &'a [u8], format: TileFormat) -> Self {
|
pub const fn new(tiles: &'a [u8], format: TileFormat) -> Self {
|
||||||
Self { tiles, format }
|
Self { tiles, format }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub const fn format(&self) -> TileFormat {
|
||||||
|
self.format
|
||||||
|
}
|
||||||
|
|
||||||
fn reference(&self) -> NonNull<[u8]> {
|
fn reference(&self) -> NonNull<[u8]> {
|
||||||
self.tiles.into()
|
self.tiles.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn format(&self) -> TileFormat {
|
|
||||||
self.format
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
|
Loading…
Reference in a new issue