Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions agb-image-converter/src/sprite/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl ToTokens for Output {
let y = sprite.size.1 as usize;

quote! {
unsafe { Sprite::new_multi(&PALETTE, align_bytes!(u16, #data), Size::from_width_height(#x, #y)) }
unsafe { Sprite::new_multi(&PALETTE, align_bytes!(u32, #data), Size::from_width_height(#x, #y)) }
}
});

Expand All @@ -202,8 +202,6 @@ impl ToTokens for Output {
}
});

let start = (16 - self.palette.len() / 16) as u32;

let input_files = self.input_files.iter().map(|file| {
quote! {
const _: &[u8] = include_bytes!(#file);
Expand All @@ -213,7 +211,7 @@ impl ToTokens for Output {
tokens.extend(quote! {
#(#input_files)*

static PALETTE: PaletteMulti = PaletteMulti::new(#start, &[#(#palettes),*] );
static PALETTE: PaletteMulti = PaletteMulti::new(&[#(#palettes),*] );
static SPRITES: &[Sprite] = &[#(#sprites),*];

#(#tags)*
Expand Down
2 changes: 1 addition & 1 deletion agb-image-converter/src/sprite/regular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl ToTokens for Output {
let palette_idx = sprite.palette as usize;

quote! {
unsafe { Sprite::new(&PALETTES[#palette_idx], align_bytes!(u16, #data), Size::from_width_height(#x, #y)) }
unsafe { Sprite::new(&PALETTES[#palette_idx], align_bytes!(u32, #data), Size::from_width_height(#x, #y)) }
}
});

Expand Down
Binary file added agb/gfx/test_output/object/dynamic_sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added agb/gfx/test_output/object/dynamic_sprite_256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion agb/src/display/font/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl ObjectTextRenderer {
let pal_index = group.palette_index();

for pixel in group.pixels() {
sprite.set_pixel(pixel.x as usize, pixel.y as usize, pal_index as usize);
sprite.set_pixel(pixel.x as usize, pixel.y as usize, pal_index);
}

let mut object = Object::new(sprite.to_vram(self.palette.clone()));
Expand Down
2 changes: 1 addition & 1 deletion agb/src/display/object/sprites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod sprite;
mod sprite_allocator;

const BYTES_PER_TILE_4BPP: usize = 32;
const BYTES_PER_TILE_8BPP: usize = 16;
const BYTES_PER_TILE_8BPP: usize = 64;

pub use sprite::{PaletteMulti, Size, Sprite, Tag, include_aseprite};
pub use sprite_allocator::{
Expand Down
11 changes: 8 additions & 3 deletions agb/src/display/object/sprites/sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ pub struct PaletteMulti {
impl PaletteMulti {
#[must_use]
/// Create a new palette. The first index is the index where the palette starts.
pub const fn new(first_index: u32, palettes: &'static [Palette16]) -> Self {
pub const fn new(palettes: &'static [Palette16]) -> Self {
assert!(palettes.len() <= 16);
assert!(!palettes.is_empty());
assert!(16 - palettes.len() >= first_index as usize);

Self {
first_index,
first_index: (16 - palettes.len()) as u32,
palettes,
}
}
Expand All @@ -54,6 +53,12 @@ impl PaletteMulti {
pub const fn first_index(&self) -> u32 {
self.first_index
}

#[must_use]
/// Gets the first colour from this palette
pub const fn first_colour_index(&self) -> u8 {
(self.first_index * 16) as u8
}
}

impl Sprite {
Expand Down
6 changes: 6 additions & 0 deletions agb/src/display/object/sprites/sprite_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ impl TryFrom<PaletteVram> for PaletteVramSingle {
}
}

impl From<&'static PaletteMulti> for PaletteVramMulti {
fn from(value: &'static PaletteMulti) -> Self {
PaletteVramMulti::new(value)
}
}

impl TryFrom<PaletteVram> for PaletteVramMulti {
type Error = PaletteVram;

Expand Down
Loading