From 643891a9de57ff337ed4da7d28218845758d1ba8 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Tue, 12 Jul 2022 14:37:32 +0100 Subject: [PATCH] Make the doctests work for infinite_scrolled_map --- .../display/tiled/infinite_scrolled_map.rs | 101 +++++++++++++++++- 1 file changed, 97 insertions(+), 4 deletions(-) diff --git a/agb/src/display/tiled/infinite_scrolled_map.rs b/agb/src/display/tiled/infinite_scrolled_map.rs index 715a6220..decdd4db 100644 --- a/agb/src/display/tiled/infinite_scrolled_map.rs +++ b/agb/src/display/tiled/infinite_scrolled_map.rs @@ -113,11 +113,57 @@ impl<'a> InfiniteScrolledMap<'a> { /// /// # Example /// - /// ``` - /// background.init(&mut vram, start_position, || { + /// ```rust,no_run + /// # #![no_std] + /// # #![no_main] + /// # #![no_std] + /// # #![no_main] + /// # extern crate alloc; + /// # + /// # use alloc::boxed::Box; + /// # + /// # use agb::display::tiled::{ + /// # InfiniteScrolledMap, + /// # TileSetting, + /// # RegularBackgroundSize, + /// # TileSet, + /// # TileFormat, + /// # }; + /// # use agb::display::Priority; + /// # + /// # mod tilemap { + /// # pub const BACKGROUND_MAP: &[u16] = &[0, 1, 2]; + /// # pub const WIDTH: i32 = 12; + /// # pub const MAP_TILES: &[u8] = &[0]; + /// # } + /// # + /// # fn foo(mut gba: agb::Gba) { + /// # let (gfx, mut vram) = gba.display.video.tiled0(); + /// # + /// # let tileset = TileSet::new(&tilemap::MAP_TILES, TileFormat::FourBpp); + /// # + /// # let mut backdrop = InfiniteScrolledMap::new( + /// # gfx.background(Priority::P2, RegularBackgroundSize::Background32x32), + /// # Box::new(|pos| { + /// # ( + /// # &tileset, + /// # TileSetting::from_raw( + /// # *tilemap::BACKGROUND_MAP + /// # .get((pos.x + tilemap::WIDTH * pos.y) as usize) + /// # .unwrap_or(&0), + /// # ), + /// # ) + /// # }), + /// # ); + /// # + /// # let vblank = agb::interrupt::VBlank::get(); + /// # let mut mixer = gba.mixer.mixer(); + /// let start_position = agb::fixnum::Vector2D::new(10, 10); + /// backdrop.init(&mut vram, start_position, &mut || { /// vblank.wait_for_vblank(); /// mixer.frame(); /// }); + /// # } /// ``` pub fn init( &mut self, @@ -141,11 +187,58 @@ impl<'a> InfiniteScrolledMap<'a> { /// /// # Example /// - /// ``` - /// while background.init_partial(&mut vram, start_position) == PartialUpdateStatus::Continue { + /// ```rust,no_run + /// # #![no_std] + /// # #![no_main] + /// # #![no_std] + /// # #![no_main] + /// # extern crate alloc; + /// # + /// # use alloc::boxed::Box; + /// # + /// # use agb::display::tiled::{ + /// # InfiniteScrolledMap, + /// # TileSetting, + /// # RegularBackgroundSize, + /// # TileSet, + /// # TileFormat, + /// # PartialUpdateStatus, + /// # }; + /// # use agb::display::Priority; + /// # + /// # mod tilemap { + /// # pub const BACKGROUND_MAP: &[u16] = &[0, 1, 2]; + /// # pub const WIDTH: i32 = 12; + /// # pub const MAP_TILES: &[u8] = &[0]; + /// # } + /// # + /// # fn foo(mut gba: agb::Gba) { + /// # let (gfx, mut vram) = gba.display.video.tiled0(); + /// # + /// # let tileset = TileSet::new(&tilemap::MAP_TILES, TileFormat::FourBpp); + /// # + /// # let mut backdrop = InfiniteScrolledMap::new( + /// # gfx.background(Priority::P2, RegularBackgroundSize::Background32x32), + /// # Box::new(|pos| { + /// # ( + /// # &tileset, + /// # TileSetting::from_raw( + /// # *tilemap::BACKGROUND_MAP + /// # .get((pos.x + tilemap::WIDTH * pos.y) as usize) + /// # .unwrap_or(&0), + /// # ), + /// # ) + /// # }), + /// # ); + /// # + /// # let vblank = agb::interrupt::VBlank::get(); + /// # let mut mixer = gba.mixer.mixer(); + /// let start_position = agb::fixnum::Vector2D::new(10, 10); + /// while backdrop.init_partial(&mut vram, start_position) == PartialUpdateStatus::Continue { /// vblank.wait_for_vblank(); /// mixer.frame(); /// } + /// # } /// ``` pub fn init_partial( &mut self,