diff --git a/agb/examples/chicken.rs b/agb/examples/chicken.rs index 55a7f089..704a0460 100644 --- a/agb/examples/chicken.rs +++ b/agb/examples/chicken.rs @@ -53,7 +53,7 @@ pub fn main() -> ! { let mut background = gfx.get_background().unwrap(); background.set_map(agb::display::tiled0::Map { - store: &MAP_MAP, + store: MAP_MAP.as_ref(), dimensions: (32_u32, 32_u32).into(), default: 0, }); diff --git a/agb/examples/test_logo.rs b/agb/examples/test_logo.rs index a307db4c..6eddc02b 100644 --- a/agb/examples/test_logo.rs +++ b/agb/examples/test_logo.rs @@ -4,7 +4,6 @@ extern crate agb; use agb::display::example_logo; -use agb::display::tiled0::Map; #[no_mangle] pub fn main() -> ! { diff --git a/agb/src/display/example_logo.rs b/agb/src/display/example_logo.rs index ec56af38..85e64bf4 100644 --- a/agb/src/display/example_logo.rs +++ b/agb/src/display/example_logo.rs @@ -17,7 +17,7 @@ pub fn display_logo(gfx: &mut Tiled0) { } back.set_map(Map { - store: &entries, + store: entries.as_ref(), dimensions: (30_u32, 20_u32).into(), default: 0, }); diff --git a/agb/src/display/tiled0.rs b/agb/src/display/tiled0.rs index 0811a68c..782a7693 100644 --- a/agb/src/display/tiled0.rs +++ b/agb/src/display/tiled0.rs @@ -30,29 +30,30 @@ pub enum BackgroundSize { S64x64 = 3, } +pub trait MapStorage: Deref {} +impl MapStorage for &[u16] {} +impl MapStorage for &mut [u16] {} + /// The map background is the method of drawing game maps to the screen. It /// automatically handles copying the correct portion of a provided map to the /// assigned block depending on given coordinates. -pub struct Background + ?Sized, D: Deref> { +pub struct Background { background: u8, block: u8, commited_position: Vector2D, shadowed_position: Vector2D, poisoned: bool, shadowed_register: u16, - map: Option>, + map: Option>, } -pub struct Map> -where - S: Index + ?Sized, -{ - pub store: D, +pub struct Map { + pub store: S, pub dimensions: Vector2D, pub default: u16, } -impl<'a, S: Index + ?Sized, D: Deref> Map { +impl<'a, S: MapStorage> Map { fn get_position(&self, x: i32, y: i32) -> u16 { if x < 0 || x as u32 >= self.dimensions.x { self.default @@ -64,8 +65,8 @@ impl<'a, S: Index + ?Sized, D: Deref> Map } } -impl<'a, S: Index + ?Sized, D: Deref> Background { - unsafe fn new(background: u8, block: u8) -> Background { +impl<'a, S: MapStorage> Background { + unsafe fn new(background: u8, block: u8) -> Background { let mut b = Background { background, block, @@ -134,12 +135,12 @@ impl<'a, S: Index + ?Sized, D: Deref> Backgroun self.shadowed_position = position; } - pub fn get_map(&mut self) -> Option<&mut Map> { + pub fn get_map(&mut self) -> Option<&mut Map> { self.poisoned = true; self.map.as_mut() } - pub fn set_map(&mut self, map: Map) { + pub fn set_map(&mut self, map: Map) { self.poisoned = true; self.map = Some(map); } @@ -265,9 +266,7 @@ impl Tiled0 { } /// Gets a map background if possible and assigns an unused block to it. - pub fn get_background + ?Sized, D: Deref>( - &mut self, - ) -> Result, &'static str> { + pub fn get_background(&mut self) -> Result, &'static str> { if self.num_backgrounds >= 4 { return Err("too many backgrounds created, maximum is 4"); }