From 22b3497bb3301c9ae24db5a541ee8a564e728adb Mon Sep 17 00:00:00 2001 From: Corwin Date: Tue, 27 Jun 2023 21:56:26 +0100 Subject: [PATCH] fix --- agb/examples/font/pixelated.ttf | Bin 0 -> 12656 bytes agb/examples/object_text_render.rs | 28 +++++++++++++++++++++------- agb/src/display/object/font.rs | 19 ++++++++----------- 3 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 agb/examples/font/pixelated.ttf diff --git a/agb/examples/font/pixelated.ttf b/agb/examples/font/pixelated.ttf new file mode 100644 index 0000000000000000000000000000000000000000..29c265a11d8c6873b4b44daf632b6959aed15a5e GIT binary patch literal 12656 zcmeHOO>A6O6+ZLhIE|geP12;HN&A{cRa;t5{z#>&NJ%55DQanyl=7pBcI=GpNjx5R zW?b79KX<``MHgKns8AOmfz(ASBEf=65vl};u27)}SQLT;iz0PXgizz*`_8@R&7C)I zY?lQK#EZ^5_nv$H&$;)#8Be4jBHP4CNs=coR*seSZuz{(*sGvEH{GZ%-u`Ox2aI16 zDc(OjzdG~tt2c@wOUujfV7GdOD(?f<#xRh4}W`0>c^-+gxH!ylrjbnTZ|Vpx0!729-a0wnf_aZyI)P#BkR&fFWuWw}{C9mXRvCZ7%CEs*_U z7>~-sG8M*Kn z@v6_bZ7uu|VHe7b_E_PKFfPch!u2pN%8tT^VO)}Xils0v%c0^Y!+1pY7M}>?EwZaP z9mb=wQd|n-t#V)S?_qqC>?!RF<8AVI$@GlLWNA6j$K|=w_rrL*oG*`r@eX;W{JAjR zEf>ncXT&lwQaaOITy527=Q_!wty*oNQ9X9#XaYETzP?hMuXbveF4Sh1=Bur<&4tdz zPHSnplcY=OAPG!Q*IMm*b0Il8c_dwn1ncdjnsi##OSML|btP%eBxf%^mMFtqb1`{r zp;K!uR6Ed6olhQZOr4wSbQT|~RAykit+pqpn~k2M2T~&kljUkVnOdsPcar6LXU;2C zk!?ZA^78VeDuOAh$<-a1f*0*dd#<@$IdSad$>R^6Y1QD`3$^4-v(dm>a=O!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BI~ z_ypi3zy~;zuZry01HgO-bnmmV4b?7Sqj^D@smpIS=Gx2Xms2~Oa literal 0 HcmV?d00001 diff --git a/agb/examples/object_text_render.rs b/agb/examples/object_text_render.rs index 0a226f70..a5f8f5bf 100644 --- a/agb/examples/object_text_render.rs +++ b/agb/examples/object_text_render.rs @@ -17,7 +17,7 @@ use agb_fixnum::Rect; use core::fmt::Write; -const FONT: Font = include_font!("examples/font/yoster.ttf", 12); +const FONT: Font = include_font!("examples/font/pixelated.ttf", 8); #[agb::entry] fn entry(gba: agb::Gba) -> ! { main(gba); @@ -32,12 +32,14 @@ fn main(mut gba: agb::Gba) -> ! { let palette = Palette16::new(palette); let palette = PaletteVram::new(&palette).unwrap(); - let config = Configuration::new(Size::S16x16, palette); + let config = Configuration::new(Size::S16x8, palette); let mut wr = BufferedWordRender::new(&FONT, config); let _ = writeln!( wr, - "Hello there!\nI spent this weekend writing this text system! Is it any good?\n\nOh, by the way, you can press A to restart!" + "{}", + "counts for three shoot dice for damage calculation\nmalfunctions all dice after use" + .to_ascii_uppercase() ); let vblank = agb::interrupt::VBlank::get(); @@ -59,7 +61,10 @@ fn main(mut gba: agb::Gba) -> ! { wr.commit(oam); let start = timer.value(); - wr.update(Rect::new((0, 0).into(), (WIDTH, 100).into()), num_letters); + wr.update( + Rect::new((WIDTH / 8, 0).into(), (80, 100).into()), + num_letters, + ); wr.process(); let end = timer.value(); @@ -67,13 +72,22 @@ fn main(mut gba: agb::Gba) -> ! { frame += 1; - if frame % 4 == 0 { - num_letters += 1; - } + // if frame % 2 == 0 { + num_letters += 1; + // } if input.is_just_pressed(Button::A) { break; } } + let start = timer.value(); + drop(wr); + let oam = unmanaged.iter(); + drop(oam); + let end = timer.value(); + agb::println!( + "Drop took {} cycles", + 256 * (end.wrapping_sub(start) as u32) + ); } } diff --git a/agb/src/display/object/font.rs b/agb/src/display/object/font.rs index 5501cda0..7eaf45b2 100644 --- a/agb/src/display/object/font.rs +++ b/agb/src/display/object/font.rs @@ -151,7 +151,7 @@ impl WordRenderCache { && prospective_x > position.position.x + position.size.x { self.state.head_position.x = position.position.x; - self.state.head_position.y += 15; + self.state.head_position.y += 9; } for letter in word.letters.iter().skip(self.state.depth_in_word) { @@ -175,10 +175,10 @@ impl WordRenderCache { } TextElementReference::WhiteSpace(space) => { match space { - WhiteSpace::Space => self.state.head_position.x += 10, + WhiteSpace::Space => self.state.head_position.x += 2, WhiteSpace::NewLine => { self.state.head_position.x = position.position.x; - self.state.head_position.y += 15; + self.state.head_position.y += 14; } } self.state.depth_in_elements += 1; @@ -244,7 +244,6 @@ impl WorkingLetter { fn reset(&mut self) { self.x_position = 0; self.x_offset = 0; - self.dynamic.clear(0); } } @@ -382,11 +381,10 @@ impl WordRender<'_> { return None; } - let sprite = self - .working - .letter - .dynamic - .to_vram(self.config.palette.clone()); + let mut new_sprite = DynamicSprite::new(self.config.sprite_size); + core::mem::swap(&mut self.working.letter.dynamic, &mut new_sprite); + let sprite = new_sprite.to_vram(self.config.palette.clone()); + let group = LetterGroup { sprite, width: self.working.letter.x_offset as u16, @@ -416,8 +414,7 @@ impl WordRender<'_> { self.working.letter.x_offset += font_letter.xmin as i32; } - let y_position = - self.font.ascent() - font_letter.height as i32 - font_letter.ymin as i32 + 4; + let y_position = self.font.ascent() - font_letter.height as i32 - font_letter.ymin as i32; for y in 0..font_letter.height as usize { for x in 0..font_letter.width as usize {