Make image converter produce tile sets (#480)

Removes loads of duplicated code. There's no reason why this couldn't
create regular tile sets.

- [x] Changelog updated
This commit is contained in:
Gwilym Inzani 2023-09-06 09:40:17 +01:00 committed by GitHub
commit 9350027fa2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 186 additions and 215 deletions

View file

@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Sound channel panning and volume options are now `Num<i16, 8>` rather than `Num<i16, 4>` for improved precision and sound quality.
- Due to dependency changes, agb-gbafix is now released under MPL rather than GPL.
- `include_background_gfx!` now produces tile settings directly rather than palette assigments.
- `include_background_gfx!` now produces tile sets and tile settings directly.
### Fixed

View file

@ -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)]
@ -126,7 +131,7 @@ pub(crate) fn generate_code(
pub bytes: Bytes,
}
const ALIGNED: &AlignedAs<u16, [u8]> = &AlignedAs {
const ALIGNED: &AlignedAs<u32, [u8]> = &AlignedAs {
_align: [],
bytes: *#data,
};
@ -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)
};
}
}

View file

@ -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);

View file

@ -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 {

View file

@ -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);

View file

@ -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(),
);
}
}

View file

@ -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(),
);
}
}

View file

@ -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(),
);
}
}

View file

@ -1,5 +0,0 @@
version = "1.0"
[image.water_tiles]
filename = "water_tiles.png"
tile_size = "8x8"

View file

@ -1,24 +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);
for y in 0..20 {
for x in 0..30 {
let tile_id = y * 30 + x;
map.set_tile(
vram,
(x as u16, y as u16).into(),
&background_tilemap,
agb_logo::test_logo.tile_settings[tile_id],
);
}
}
map.fill_with(vram, &agb_logo::test_logo);
map.commit(vram);
map.show();
@ -37,7 +24,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);

View file

@ -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(),
);
}
}

View file

@ -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,

View file

@ -40,29 +40,27 @@ use crate::{
/// use agb::display::Priority;
///
/// mod tilemap {
/// pub const BACKGROUND_MAP: &[u16] = &[ // Probably load this from a file
/// pub const BACKGROUND_MAP: &[usize] = &[ // Probably load this from a file
/// # 0, 1, 2];
/// pub const WIDTH: i32 = // set it to some width
/// # 12;
/// pub const MAP_TILES: &[u8] = &[ // probably load this from a file
/// # 0];
/// }
///
/// agb::include_background_gfx!(water_tiles, tiles => "examples/water_tiles.png");
///
/// # fn foo(mut gba: agb::Gba) {
/// let (gfx, mut vram) = gba.display.video.tiled0();
///
/// let tileset = TileSet::new(&tilemap::MAP_TILES, TileFormat::FourBpp);
/// let tile_data = water_tiles::tiles;
///
/// let mut backdrop = InfiniteScrolledMap::new(
/// gfx.background(Priority::P2, RegularBackgroundSize::Background32x32, TileFormat::FourBpp),
/// Box::new(|pos| {
/// (
/// &tileset,
/// TileSetting::from_raw(
/// *tilemap::BACKGROUND_MAP
/// &tile_data.tiles,
/// tile_data.tile_settings[*tilemap::BACKGROUND_MAP
/// .get((pos.x + tilemap::WIDTH * pos.y) as usize)
/// .unwrap_or(&0),
/// ),
/// .unwrap_or(&0)]
/// )
/// }),
/// );
@ -135,26 +133,27 @@ impl<'a> InfiniteScrolledMap<'a> {
/// # use agb::display::Priority;
/// #
/// # mod tilemap {
/// # pub const BACKGROUND_MAP: &[u16] = &[0, 1, 2];
/// # pub const BACKGROUND_MAP: &[usize] = &[0, 1, 2];
/// # pub const WIDTH: i32 = 12;
/// # pub const MAP_TILES: &[u8] = &[0];
/// # }
/// #
/// # agb::include_background_gfx!(water_tiles, tiles => "examples/water_tiles.png");
/// #
/// # fn foo(mut gba: agb::Gba) {
/// # let (gfx, mut vram) = gba.display.video.tiled0();
/// #
/// # let tileset = TileSet::new(&tilemap::MAP_TILES, TileFormat::FourBpp);
/// # let tile_data = water_tiles::tiles;
/// #
/// # let mut backdrop = InfiniteScrolledMap::new(
/// # gfx.background(Priority::P2, RegularBackgroundSize::Background32x32, TileFormat::FourBpp),
/// # Box::new(|pos| {
/// # (
/// # &tileset,
/// # TileSetting::from_raw(
/// # &tile_data.tiles,
/// # tile_data.tile_settings[
/// # *tilemap::BACKGROUND_MAP
/// # .get((pos.x + tilemap::WIDTH * pos.y) as usize)
/// # .unwrap_or(&0),
/// # ),
/// # .unwrap_or(&0)]
/// # )
/// # }),
/// # );
@ -210,26 +209,27 @@ impl<'a> InfiniteScrolledMap<'a> {
/// # use agb::display::Priority;
/// #
/// # mod tilemap {
/// # pub const BACKGROUND_MAP: &[u16] = &[0, 1, 2];
/// # pub const BACKGROUND_MAP: &[usize] = &[0, 1, 2];
/// # pub const WIDTH: i32 = 12;
/// # pub const MAP_TILES: &[u8] = &[0];
/// # }
/// #
/// # agb::include_background_gfx!(water_tiles, tiles => "examples/water_tiles.png");
/// #
/// # fn foo(mut gba: agb::Gba) {
/// # let (gfx, mut vram) = gba.display.video.tiled0();
/// #
/// # let tileset = TileSet::new(&tilemap::MAP_TILES, TileFormat::FourBpp);
/// # let tile_data = water_tiles::tiles;
/// #
/// # let mut backdrop = InfiniteScrolledMap::new(
/// # gfx.background(Priority::P2, RegularBackgroundSize::Background32x32, TileFormat::FourBpp),
/// # Box::new(|pos| {
/// # (
/// # &tileset,
/// # TileSetting::from_raw(
/// # &tile_data.tiles,
/// # tile_data.tile_settings[
/// # *tilemap::BACKGROUND_MAP
/// # .get((pos.x + tilemap::WIDTH * pos.y) as usize)
/// # .unwrap_or(&0),
/// # ),
/// # .unwrap_or(&0)]
/// # )
/// # }),
/// # );

View file

@ -3,6 +3,7 @@ use core::ops::{Deref, DerefMut};
use crate::bitarray::Bitarray;
use crate::display::affine::AffineMatrixBackground;
use crate::display::tile_data::TileData;
use crate::display::{Priority, DISPLAY_CONTROL};
use crate::dma::dma_copy16;
use crate::fixnum::Vector2D;
@ -128,7 +129,7 @@ pub struct RegularMap {
tiles_dirty: bool,
}
pub const TRANSPARENT_TILE_INDEX: u16 = (1 << 10) - 1;
pub(crate) const TRANSPARENT_TILE_INDEX: u16 = (1 << 10) - 1;
impl TiledMapTypes for RegularMap {
type Size = RegularBackgroundSize;
@ -188,6 +189,34 @@ impl RegularMap {
}
}
pub fn fill_with(&mut self, vram: &mut VRamManager, tile_data: &TileData) {
assert!(
tile_data.tile_settings.len() >= 20 * 30,
"Don't have a full screen's worth of tile data"
);
assert_eq!(
tile_data.tiles.format(),
self.colours(),
"Cannot set a {:?} colour tile on a {:?} colour background",
tile_data.tiles.format(),
self.colours()
);
for y in 0..20 {
for x in 0..30 {
let tile_id = y * 30 + x;
let tile_pos = y * 32 + x;
self.set_tile_at_pos(
vram,
tile_pos,
&tile_data.tiles,
tile_data.tile_settings[tile_id],
);
}
}
}
pub fn set_tile(
&mut self,
vram: &mut VRamManager,
@ -195,20 +224,28 @@ impl RegularMap {
tileset: &TileSet<'_>,
tile_setting: TileSetting,
) {
let colours = self.colours();
if tileset.format() != colours {
panic!(
"Cannot set a {:?} colour tile on a {:?} colour background",
tileset.format(),
colours
);
}
assert_eq!(
tileset.format(),
self.colours(),
"Cannot set a {:?} colour tile on a {:?} colour background",
tileset.format(),
self.colours()
);
let pos = self.map_size().gba_offset(pos);
self.set_tile_at_pos(vram, pos, tileset, tile_setting);
}
fn set_tile_at_pos(
&mut self,
vram: &mut VRamManager,
pos: usize,
tileset: &TileSet<'_>,
tile_setting: TileSetting,
) {
let old_tile = self.tiles_mut()[pos];
if old_tile != Tile::default() {
vram.remove_tile(old_tile.tile_index(colours));
vram.remove_tile(old_tile.tile_index(self.colours()));
}
let tile_index = tile_setting.index();

View file

@ -16,6 +16,8 @@ pub use tiled1::Tiled1;
pub use tiled2::Tiled2;
pub use vram_manager::{DynamicTile, TileFormat, TileIndex, TileSet, VRamManager};
use map::TRANSPARENT_TILE_INDEX;
// affine layers start at BG2
pub(crate) const AFFINE_BG_ID_OFFSET: usize = 2;
@ -165,7 +167,7 @@ impl Tile {
pub struct TileSetting(u16);
impl TileSetting {
pub const BLANK: Self = TileSetting::new(1023, false, false, 0);
pub const BLANK: Self = TileSetting::new(TRANSPARENT_TILE_INDEX, false, false, 0);
#[must_use]
pub const fn new(tile_id: u16, hflip: bool, vflip: bool, palette_id: u8) -> Self {

View file

@ -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> =
@ -28,17 +30,14 @@ const fn layout_of(format: TileFormat) -> Layout {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TileFormat {
FourBpp,
EightBpp,
FourBpp = 5,
EightBpp = 6,
}
impl TileFormat {
/// Returns the size of the tile in bytes
pub(crate) const fn tile_size(self) -> usize {
match self {
TileFormat::FourBpp => 8 * 8 / 2,
TileFormat::EightBpp => 8 * 8,
}
1 << self as usize
}
}
@ -49,17 +48,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)]
@ -188,9 +188,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)
}
}
@ -371,21 +373,41 @@ impl VRamManager {
tile_id: u16,
tile_reference: TileReference,
) {
let tile_size = tile_set.format.tile_size();
let tile_format = tile_set.format;
let tile_size = tile_format.tile_size();
let tile_offset = (tile_id as usize) * tile_size;
let tile_slice = &tile_set.tiles[tile_offset..(tile_offset + tile_size)];
let tile_size_in_half_words = tile_slice.len() / 2;
let tile_data_start = unsafe { tile_set.tiles.as_ptr().add(tile_offset) };
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,
);
};
match tile_format {
TileFormat::FourBpp => core::arch::asm!(
".rept 2",
"ldmia {src}!, {{{tmp1},{tmp2},{tmp3},{tmp4}}}",
"stmia {dest}!, {{{tmp1},{tmp2},{tmp3},{tmp4}}}",
".endr",
src = inout(reg) tile_data_start => _,
dest = inout(reg) target_location => _,
tmp1 = out(reg) _,
tmp2 = out(reg) _,
tmp3 = out(reg) _,
tmp4 = out(reg) _,
),
TileFormat::EightBpp => core::arch::asm!(
".rept 4",
"ldmia {src}!, {{{tmp1},{tmp2},{tmp3},{tmp4}}}",
"stmia {dest}!, {{{tmp1},{tmp2},{tmp3},{tmp4}}}",
".endr",
src = inout(reg) tile_data_start => _,
dest = inout(reg) target_location => _,
tmp1 = out(reg) _,
tmp2 = out(reg) _,
tmp3 = out(reg) _,
tmp4 = out(reg) _,
),
}
}
}
/// Copies raw palettes to the background palette without any checks.

View file

@ -77,11 +77,11 @@
/// agb::include_background_gfx!(water_tiles, tiles => "examples/water_tiles.png");
///
/// # fn load_tileset(mut gfx: Tiled0, mut vram: VRamManager) {
/// let tileset = TileSet::new(water_tiles::tiles.tiles, TileFormat::FourBpp);
/// let tileset = water_tiles::tiles.tiles;
///
/// vram.set_background_palettes(water_tiles::PALETTES);
///
/// let mut bg = gfx.background(Priority::P0, RegularBackgroundSize::Background32x32, TileFormat::FourBpp);
/// let mut bg = gfx.background(Priority::P0, RegularBackgroundSize::Background32x32, tileset.format());
///
/// for y in 0..20u16 {
/// for x in 0..30u16 {

View file

@ -8,7 +8,7 @@ use alloc::boxed::Box;
use agb::{
display::{
tiled::{InfiniteScrolledMap, RegularBackgroundSize, TileFormat, TileSet},
tiled::{InfiniteScrolledMap, RegularBackgroundSize, TileFormat},
Priority,
},
fixnum::{Num, Vector2D},
@ -63,20 +63,12 @@ fn get_game(gba: &mut agb::Gba) -> Game {
let (tile, mut vram) = gba.display.video.tiled0();
let hat = TileSet::new(games::hat.tiles, TileFormat::EightBpp);
let purple = TileSet::new(games::purple.tiles, TileFormat::EightBpp);
let hyperspace = TileSet::new(games::hyperspace.tiles, TileFormat::EightBpp);
let dungeon_puzzler = TileSet::new(games::dungeon_puzzler.tiles, TileFormat::EightBpp);
let amplitude = TileSet::new(games::amplitude.tiles, TileFormat::EightBpp);
let tiles = [hat, purple, hyperspace, dungeon_puzzler, amplitude];
let tile_settings = &[
games::hat.tile_settings,
games::purple.tile_settings,
games::hyperspace.tile_settings,
games::dungeon_puzzler.tile_settings,
games::amplitude.tile_settings,
let tiles = [
games::hat,
games::purple,
games::hyperspace,
games::dungeon_puzzler,
games::amplitude,
];
vram.set_background_palettes(games::PALETTES);
@ -93,7 +85,7 @@ fn get_game(gba: &mut agb::Gba) -> Game {
let game = (pos.x).rem_euclid(tiles.len() as i32 * 30) as usize / 30;
let tile_id = (y * 30 + x) as usize;
(&tiles[game], tile_settings[game][tile_id])
(&tiles[game].tiles, tiles[game].tile_settings[tile_id])
}),
);

View file

@ -1,5 +1,5 @@
use agb::{
display::tiled::{RegularMap, TileFormat, TileSet, TileSetting, TiledMap, VRamManager},
display::tiled::{RegularMap, TileSet, TileSetting, TiledMap, VRamManager},
include_background_gfx, rng,
};
@ -23,10 +23,7 @@ pub(crate) fn load_help_text(
help_text_line: u16,
at_tile: (u16, u16),
) {
let help_tileset = TileSet::new(
backgrounds::help.tiles,
agb::display::tiled::TileFormat::FourBpp,
);
let help_tiledata = backgrounds::help;
for x in 0..16 {
let tile_id = help_text_line * 16 + x;
@ -34,8 +31,8 @@ pub(crate) fn load_help_text(
background.set_tile(
vram,
(x + at_tile.0, at_tile.1).into(),
&help_tileset,
backgrounds::help.tile_settings[tile_id as usize],
&help_tiledata.tiles,
help_tiledata.tile_settings[tile_id as usize],
)
}
}
@ -45,22 +42,10 @@ pub(crate) fn load_description(
descriptions_map: &mut RegularMap,
vram: &mut VRamManager,
) {
let (tileset, tile_settings) = if face_id < 10 {
(
TileSet::new(
backgrounds::descriptions1.tiles,
agb::display::tiled::TileFormat::FourBpp,
),
backgrounds::descriptions1.tile_settings,
)
let description_data = if face_id < 10 {
backgrounds::descriptions1
} else {
(
TileSet::new(
backgrounds::descriptions2.tiles,
agb::display::tiled::TileFormat::FourBpp,
),
backgrounds::descriptions2.tile_settings,
)
backgrounds::descriptions2
};
for y in 0..11 {
@ -69,8 +54,8 @@ pub(crate) fn load_description(
descriptions_map.set_tile(
vram,
(x, y).into(),
&tileset,
tile_settings[tile_id as usize],
&description_data.tiles,
description_data.tile_settings[tile_id as usize],
)
}
}
@ -83,7 +68,7 @@ fn create_background_map(map: &mut RegularMap, vram: &mut VRamManager, stars_til
let blank = rng::gen().rem_euclid(32) < 30;
let tile_setting = if blank {
TileSetting::new((1 << 10) - 1, false, false, 0)
TileSetting::BLANK
} else {
let tile_id = rng::gen().rem_euclid(64) as u16;
backgrounds::stars.tile_settings[tile_id as usize]
@ -99,26 +84,10 @@ fn create_background_map(map: &mut RegularMap, vram: &mut VRamManager, stars_til
pub fn show_title_screen(background: &mut RegularMap, vram: &mut VRamManager, sfx: &mut Sfx) {
background.set_scroll_pos((0i16, 0).into());
vram.set_background_palettes(backgrounds::PALETTES);
let tile_set = TileSet::new(
backgrounds::title.tiles,
agb::display::tiled::TileFormat::FourBpp,
);
background.hide();
for x in 0..30u16 {
for y in 0..20u16 {
let tile_id = y * 30 + x;
background.set_tile(
vram,
(x, y).into(),
&tile_set,
backgrounds::title.tile_settings[tile_id as usize],
);
}
sfx.frame();
}
background.fill_with(vram, &backgrounds::title);
background.commit(vram);
sfx.frame();
background.show();
@ -138,9 +107,8 @@ impl<'a> StarBackground<'a> {
background2: &'a mut RegularMap,
vram: &'_ mut VRamManager,
) -> Self {
let stars_tileset = TileSet::new(backgrounds::stars.tiles, TileFormat::FourBpp);
create_background_map(background1, vram, &stars_tileset);
create_background_map(background2, vram, &stars_tileset);
create_background_map(background1, vram, &backgrounds::stars.tiles);
create_background_map(background2, vram, &backgrounds::stars.tiles);
Self {
background1,

View file

@ -1,5 +1,5 @@
use agb::{
display::tiled::{RegularMap, TileFormat, TileSet, VRamManager},
display::tiled::{RegularMap, VRamManager},
include_background_gfx,
};
@ -19,7 +19,7 @@ pub fn load_palettes(vram_manager: &mut VRamManager) {
}
pub fn load_ui(map: &mut RegularMap, vram_manager: &mut VRamManager) {
let ui_tileset = TileSet::new(backgrounds::ui.tiles, TileFormat::FourBpp);
let ui_tileset = backgrounds::ui.tiles;
for y in 0..20u16 {
for x in 0..30u16 {
@ -38,7 +38,7 @@ pub fn load_level_background(
) {
let level_map = &tilemaps::LEVELS_MAP[level_number];
let level_tileset = TileSet::new(backgrounds::level.tiles, TileFormat::FourBpp);
let level_tileset = backgrounds::level.tiles;
for y in 0..20u16 {
for x in 0..22u16 {
@ -51,18 +51,5 @@ pub fn load_level_background(
}
pub fn load_ending_page(map: &mut RegularMap, vram_manager: &mut VRamManager) {
let ending_tileset = TileSet::new(backgrounds::ending.tiles, TileFormat::FourBpp);
for y in 0..20u16 {
for x in 0..30u16 {
let tile_pos = y * 30 + x;
map.set_tile(
vram_manager,
(x, y).into(),
&ending_tileset,
backgrounds::ending.tile_settings[tile_pos as usize],
);
}
}
map.fill_with(vram_manager, &backgrounds::ending);
}

View file

@ -10,8 +10,8 @@ use agb::{
display::{
object::{Graphics, OamManaged, Object, Tag, TagMap},
tiled::{
InfiniteScrolledMap, PartialUpdateStatus, RegularBackgroundSize, TileFormat, TileSet,
TiledMap, VRamManager,
InfiniteScrolledMap, PartialUpdateStatus, RegularBackgroundSize, TileFormat, TiledMap,
VRamManager,
},
Priority, HEIGHT, WIDTH,
},
@ -793,7 +793,7 @@ pub fn main(mut agb: agb::Gba) -> ! {
TileFormat::FourBpp,
);
let tileset = TileSet::new(tile_sheet::background.tiles, TileFormat::FourBpp);
let tileset = tile_sheet::background.tiles;
for y in 0..32u16 {
for x in 0..32u16 {

View file

@ -1,5 +1,5 @@
use super::sfx::SfxPlayer;
use agb::display::tiled::{RegularMap, TileFormat, TileSet, TiledMap, VRamManager};
use agb::display::tiled::{RegularMap, TiledMap, VRamManager};
agb::include_background_gfx!(splash_screens,
splash => deduplicate "gfx/splash.png",
@ -18,19 +18,9 @@ pub fn show_splash_screen(
vram: &mut VRamManager,
) {
map.set_scroll_pos((0i16, 0i16).into());
let (tileset, settings) = match which {
SplashScreen::Start => (
TileSet::new(splash_screens::splash.tiles, TileFormat::FourBpp),
splash_screens::splash.tile_settings,
),
SplashScreen::End => (
TileSet::new(
splash_screens::thanks_for_playing.tiles,
TileFormat::FourBpp,
),
splash_screens::thanks_for_playing.tile_settings,
),
let tile_data = match which {
SplashScreen::Start => splash_screens::splash,
SplashScreen::End => splash_screens::thanks_for_playing,
};
let vblank = agb::interrupt::VBlank::get();
@ -40,19 +30,7 @@ pub fn show_splash_screen(
sfx.frame();
vblank.wait_for_vblank();
for y in 0..20u16 {
for x in 0..30u16 {
map.set_tile(
vram,
(x, y).into(),
&tileset,
settings[(y * 30 + x) as usize],
);
}
sfx.frame();
vblank.wait_for_vblank();
}
map.fill_with(vram, &tile_data);
map.commit(vram);
vram.set_background_palettes(splash_screens::PALETTES);

View file

@ -15,7 +15,7 @@ use alloc::{boxed::Box, vec::Vec};
use agb::{
display::{
object::{Graphics, OamManaged, Object, Sprite, Tag, TagMap},
tiled::{InfiniteScrolledMap, RegularBackgroundSize, TileFormat, TileSet, VRamManager},
tiled::{InfiniteScrolledMap, RegularBackgroundSize, TileFormat, VRamManager},
Priority, HEIGHT, WIDTH,
},
fixnum::{num, FixedNum, Rect, Vector2D},
@ -2191,7 +2191,7 @@ fn game_with_level(gba: &mut agb::Gba) {
let (background, mut vram) = gba.display.video.tiled0();
vram.set_background_palettes(background::PALETTES);
let tileset = TileSet::new(background::background.tiles, TileFormat::FourBpp);
let tileset = background::background.tiles;
let object = gba.display.object.get_managed();
loop {