From d4314213daebea97a97441b8227fe938b98148fe Mon Sep 17 00:00:00 2001 From: Corwin Date: Sat, 6 May 2023 22:45:26 +0100 Subject: [PATCH] use palette in no game to save on not useful aseprite file --- agb/gfx/pastel.png | Bin 0 -> 355 bytes agb/gfx/square.aseprite | Bin 4408 -> 0 bytes agb/src/no_game.rs | 65 +++++++++++++++++++++------------------- 3 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 agb/gfx/pastel.png delete mode 100644 agb/gfx/square.aseprite diff --git a/agb/gfx/pastel.png b/agb/gfx/pastel.png new file mode 100644 index 0000000000000000000000000000000000000000..7ece9c36c219e84510bc6ba43d2afc235e2cd61a GIT binary patch literal 355 zcmV-p0i6DcP)dGh6=nuNH~g39ZWsQ=x>c8!^Ygv7*o z>hhx3gt)YVqS2?3>-)&{e3g2H#H4xG>Y}gmqPT>D(TS1k)XC-gxTl1<%88Ndk;(k& zm3D^2l!WTudc*RfxP-6Kf{*LHk@xw;d3Kq!gv9E3yYi``gq66Rg3;=c>;K5qc9o5U zw8VLW>d~U|gt(1@(ZrFy>(a*hmYH^x#Dsb3sG{rgBBCS100009a7bBm000ie000ie z0hKEb8vpWis_P}wdE!qin$zMU0W)svOHbVzjJ35Gog+^`TG~#kXO*RGEU=BkQ z-WBLEO9@o=(Dxh0>3&;Nl+-0dO-cpS9QH%6h2l_G1C6))lH=5;rRW4*U7d$|s_3eE zlfJVzN`1QICa7Zi78>rP`|rj)P=n^nsr9KE+!%>A(*3f9eASq!PgUzvcxm<`%SpQG z)M`!Cr(&Z%WfzT`6dE^QAzvf?)aRLM;#{S1HmJnM7LE!Zve-=PCJQ+r1SA0bU=Q%1 z4&>ks*dPteU<|-S_l5^t0To1n6D$D|6oC-@01xDV4a@)xw15hn0LdIS0}t2$45$DJ zcmM`S00S5R0Nleme8V(3_WI!!Mhzwv7U2)(;0(6l35MVXRvsrOshc*eEm)LNqJbCTag2KdaYCWh7!8fXUjA zFS2@dyPD@kA9{6vf3=&_t2Nvex#~d@_Cz$k~XwBvn zx&wu(7Ul2*13FHxr7wNfC&sDQt5aT9lnLWquMkxE?%*5?Y+AS`)|J2cLrFgL1FJAE zHzV401cepF4pyQ5&6ujKft0*!yeOTwP z{u%d)3JPRb8}k7hTOJpusdDe+JS)n{=F1`R4O~_pcCqkG8qP0?Ar!XatmL`GF`~Kj zJ=3e>RO(}Mp`^?E&xcu&=%1@k9_$w^Z7e*cpEs$(4wt6`!>o0uU(HoSFD3HCmt#Dz ziepVnb119IG8*Q^6wjBC6ZWM@`^=r`J1}H0&9QD8tW>+ zCJ}#}V--%06wHb8SQcRbib2T zXq_yKh$)zS1jh(xi~2GB%hP-y}~>5+=UC{;#G2K`eZhn6Qwo1WkEQx?k?pwvRqo}Kc_0%mCOgM{a9;I WJJ`z>dsujKmgDOO`@^TE%l`sYq)pTS diff --git a/agb/src/no_game.rs b/agb/src/no_game.rs index d241bce4..77920640 100644 --- a/agb/src/no_game.rs +++ b/agb/src/no_game.rs @@ -1,19 +1,18 @@ //! The no game screen is what is displayed if there isn't a game made yet. use agb_fixnum::{num, Num, Vector2D}; -use alloc::vec; use alloc::vec::Vec; +use alloc::{boxed::Box, vec}; +use crate::display::object::{DynamicSprite, PaletteVram, Size, SpriteVram}; +use crate::display::palette16::Palette16; use crate::{ - display::{ - object::{OamIterator, ObjectUnmanaged, Sprite}, - HEIGHT, WIDTH, - }, - include_aseprite, + display::{object::ObjectUnmanaged, HEIGHT, WIDTH}, + include_palette, interrupt::VBlank, }; -const SQUARES: &[Sprite] = include_aseprite!("gfx/square.aseprite").sprites(); +const PALETTE: &[u16] = &include_palette!("gfx/pastel.png"); fn letters() -> Vec>>> { vec![ @@ -111,34 +110,44 @@ fn letters() -> Vec>>> { ] } -trait Renderable { - fn render(&self, slots: &mut OamIterator) -> Option<()>; -} +fn generate_sprites() -> Box<[SpriteVram]> { + let mut sprites = Vec::new(); -impl Renderable for ObjectUnmanaged { - fn render(&self, slots: &mut OamIterator) -> Option<()> { - slots.next()?.set(self); - Some(()) - } -} + // generate palettes -impl Renderable for &[T] { - fn render(&self, slots: &mut OamIterator) -> Option<()> { - for r in self.iter() { - r.render(slots)?; + let palettes: Vec = PALETTE + .chunks(15) + .map(|x| { + core::iter::once(0) + .chain(x.iter().copied()) + .chain(core::iter::repeat(0)) + .take(16) + .collect::>() + }) + .map(|palette| { + let palette = Palette16::new(palette.try_into().unwrap()); + PaletteVram::new(&palette).unwrap() + }) + .collect(); + + // generate sprites + let mut sprite = DynamicSprite::new(Size::S8x8); + for (palette, colour) in (0..PALETTE.len()).map(|x| (x / 15, x % 15)) { + for y in 0..8 { + for x in 0..8 { + sprite.set_pixel(x, y, colour + 1); + } } - - Some(()) + sprites.push(sprite.to_vram(palettes[palette].clone())); } + + sprites.into_boxed_slice() } pub fn no_game(mut gba: crate::Gba) -> ! { let (mut oam, mut loader) = gba.display.object.get_unmanaged(); - let squares: Vec<_> = SQUARES - .iter() - .map(|sprite| loader.get_vram_sprite(sprite)) - .collect(); + let squares = generate_sprites(); let mut letter_positons = Vec::new(); @@ -179,10 +188,6 @@ pub fn no_game(mut gba: crate::Gba) -> ! { let mut time: Num = num!(0.); let time_delta: Num = num!(0.025); - // let (_background, mut vram) = gba.display.video.tiled0(); - - // vram.set_background_palettes(&[Palette16::new([u16::MAX; 16])]); - let vblank = VBlank::get(); loop {