mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Rework the settings a little to allow for raw tile ids
This commit is contained in:
parent
cf72a9331a
commit
38e57489a3
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use agb::{
|
use agb::{
|
||||||
display::{
|
display::{
|
||||||
background::{RegularMap, TileFormat, TileSet, TileSetting},
|
background::{TileFormat, TileSet, TileSetting},
|
||||||
object::ObjectStandard,
|
object::ObjectStandard,
|
||||||
HEIGHT, WIDTH,
|
HEIGHT, WIDTH,
|
||||||
},
|
},
|
||||||
|
@ -62,7 +62,6 @@ fn main(mut gba: agb::Gba) -> ! {
|
||||||
&mut gfx.vram,
|
&mut gfx.vram,
|
||||||
(i % 32, i / 32).into(),
|
(i % 32, i / 32).into(),
|
||||||
tileset_ref,
|
tileset_ref,
|
||||||
tile & ((1 << 10) - 1),
|
|
||||||
TileSetting::from_raw(tile),
|
TileSetting::from_raw(tile),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,8 +219,8 @@ impl<'a> VRamManager<'a> {
|
||||||
struct Tile(u16);
|
struct Tile(u16);
|
||||||
|
|
||||||
impl Tile {
|
impl Tile {
|
||||||
fn new(tid: TileIndex, setting: TileSetting) -> Self {
|
fn new(idx: TileIndex, setting: TileSetting) -> Self {
|
||||||
Self(tid.0 | setting.as_raw())
|
Self(idx.0 | setting.setting())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tile_index(self) -> TileIndex {
|
fn tile_index(self) -> TileIndex {
|
||||||
|
@ -229,35 +229,28 @@ impl Tile {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
pub struct TileSetting {
|
pub struct TileSetting(u16);
|
||||||
hflip: bool,
|
|
||||||
vflip: bool,
|
|
||||||
palette_id: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TileSetting {
|
impl TileSetting {
|
||||||
pub fn new(hflip: bool, vflip: bool, palette_id: u8) -> Self {
|
pub const fn new(tile_id: u16, hflip: bool, vflip: bool, palette_id: u8) -> Self {
|
||||||
Self {
|
Self(
|
||||||
hflip,
|
(tile_id & ((1 << 10) - 1))
|
||||||
vflip,
|
| ((hflip as u16) << 10)
|
||||||
palette_id,
|
| ((vflip as u16) << 11)
|
||||||
}
|
| ((palette_id as u16) << 12),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_raw(raw: u16) -> Self {
|
pub const fn from_raw(raw: u16) -> Self {
|
||||||
let hflip = raw & (1 << 10) != 0;
|
Self(raw)
|
||||||
let vflip = raw & (1 << 11) != 0;
|
|
||||||
let palette_id = raw >> 12;
|
|
||||||
|
|
||||||
Self {
|
|
||||||
hflip,
|
|
||||||
vflip,
|
|
||||||
palette_id: palette_id as u8,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_raw(self) -> u16 {
|
fn index(self) -> u16 {
|
||||||
((self.hflip as u16) << 10) | ((self.vflip as u16) << 11) | ((self.palette_id as u16) << 12)
|
self.0 & ((1 << 10) - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setting(self) -> u16 {
|
||||||
|
self.0 & !((1 << 10) - 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +286,6 @@ impl RegularMap {
|
||||||
vram: &mut VRamManager,
|
vram: &mut VRamManager,
|
||||||
pos: Vector2D<u16>,
|
pos: Vector2D<u16>,
|
||||||
tileset_ref: TileSetReference,
|
tileset_ref: TileSetReference,
|
||||||
tile_index: u16,
|
|
||||||
tile_setting: TileSetting,
|
tile_setting: TileSetting,
|
||||||
) {
|
) {
|
||||||
let pos = (pos.x + pos.y * 32) as usize;
|
let pos = (pos.x + pos.y * 32) as usize;
|
||||||
|
@ -303,6 +295,7 @@ impl RegularMap {
|
||||||
vram.remove_tile(old_tile.tile_index());
|
vram.remove_tile(old_tile.tile_index());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tile_index = tile_setting.index();
|
||||||
let new_tile_idx = vram.add_tile(tileset_ref, tile_index);
|
let new_tile_idx = vram.add_tile(tileset_ref, tile_index);
|
||||||
let new_tile = Tile::new(new_tile_idx, tile_setting);
|
let new_tile = Tile::new(new_tile_idx, tile_setting);
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,12 @@ pub fn display_logo(map: &mut RegularMap, vram: &mut VRamManager) {
|
||||||
let tile_id = y * 30 + x;
|
let tile_id = y * 30 + x;
|
||||||
|
|
||||||
let palette_entry = agb_logo::test_logo.palette_assignments[tile_id as usize];
|
let palette_entry = agb_logo::test_logo.palette_assignments[tile_id as usize];
|
||||||
let tile_setting = TileSetting::new(false, false, palette_entry);
|
let tile_setting = TileSetting::new(tile_id, false, false, palette_entry);
|
||||||
|
|
||||||
map.set_tile(
|
map.set_tile(
|
||||||
vram,
|
vram,
|
||||||
(x, y).into(),
|
(x, y).into(),
|
||||||
background_tilemap_reference,
|
background_tilemap_reference,
|
||||||
tile_id,
|
|
||||||
tile_setting,
|
tile_setting,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue