diff --git a/agb/src/display/tiled/mod.rs b/agb/src/display/tiled/mod.rs index aadba54a..164ce3a6 100644 --- a/agb/src/display/tiled/mod.rs +++ b/agb/src/display/tiled/mod.rs @@ -210,15 +210,21 @@ pub(self) fn find_screenblock_gap(screenblocks: &Bitarray<1>, gap: usize) -> usi ); } -pub(self) trait TiledMode { - const REGULAR_BACKGROUNDS: usize; - const AFFINE_BACKGROUNDS: usize; +trait TiledMode { fn screenblocks(&self) -> &RefCell>; +} + +trait CreatableRegularTiledMode: TiledMode { + const REGULAR_BACKGROUNDS: usize; fn regular(&self) -> &RefCell>; +} + +trait CreatableAffineTiledMode: TiledMode { + const AFFINE_BACKGROUNDS: usize; fn affine(&self) -> &RefCell>; } -pub trait RegularTiledMode { +trait RegularTiledMode { fn regular_background( &self, priority: Priority, @@ -226,7 +232,7 @@ pub trait RegularTiledMode { ) -> MapLoan<'_, RegularMap>; } -pub trait AffineTiledMode { +trait AffineTiledMode { fn affine_background( &self, priority: Priority, @@ -234,15 +240,9 @@ pub trait AffineTiledMode { ) -> MapLoan<'_, AffineMap>; } -// withoutboats: https://internals.rust-lang.org/t/const-generics-where-restrictions/12742/6 -pub struct If; -pub trait True {} -impl True for If {} - impl RegularTiledMode for T where - T: TiledMode, - If<{ T::REGULAR_BACKGROUNDS > 0 }>: True, + T: CreatableRegularTiledMode, { fn regular_background( &self, @@ -283,8 +283,7 @@ where impl AffineTiledMode for T where - T: TiledMode, - If<{ T::AFFINE_BACKGROUNDS > 0 }>: True, + T: CreatableAffineTiledMode, { fn affine_background( &self, diff --git a/agb/src/display/tiled/tiled0.rs b/agb/src/display/tiled/tiled0.rs index e824a8e3..66ff0054 100644 --- a/agb/src/display/tiled/tiled0.rs +++ b/agb/src/display/tiled/tiled0.rs @@ -1,6 +1,9 @@ use core::cell::RefCell; -use super::{MapLoan, RegularBackgroundSize, RegularMap, RegularTiledMode, TiledMode}; +use super::{ + CreatableRegularTiledMode, MapLoan, RegularBackgroundSize, RegularMap, RegularTiledMode, + TiledMode, +}; use crate::{ bitarray::Bitarray, display::{set_graphics_mode, DisplayMode, Priority}, @@ -31,18 +34,15 @@ impl Tiled0 { } impl TiledMode for Tiled0 { - const REGULAR_BACKGROUNDS: usize = 4; - const AFFINE_BACKGROUNDS: usize = 0; - fn screenblocks(&self) -> &RefCell> { &self.screenblocks } +} + +impl CreatableRegularTiledMode for Tiled0 { + const REGULAR_BACKGROUNDS: usize = 4; fn regular(&self) -> &RefCell> { &self.regular } - - fn affine(&self) -> &RefCell> { - unimplemented!() - } } diff --git a/agb/src/display/tiled/tiled1.rs b/agb/src/display/tiled/tiled1.rs index 2b4af6ee..84903aa2 100644 --- a/agb/src/display/tiled/tiled1.rs +++ b/agb/src/display/tiled/tiled1.rs @@ -1,6 +1,6 @@ use core::cell::RefCell; -use super::TiledMode; +use super::{CreatableAffineTiledMode, CreatableRegularTiledMode, TiledMode}; use crate::{ bitarray::Bitarray, display::{set_graphics_mode, tiled::AFFINE_BG_ID_OFFSET, DisplayMode}, @@ -30,16 +30,21 @@ impl Tiled1 { } impl TiledMode for Tiled1 { - const REGULAR_BACKGROUNDS: usize = 2; - const AFFINE_BACKGROUNDS: usize = 1; - fn screenblocks(&self) -> &RefCell> { &self.screenblocks } +} + +impl CreatableRegularTiledMode for Tiled1 { + const REGULAR_BACKGROUNDS: usize = 2; fn regular(&self) -> &RefCell> { &self.regular } +} + +impl CreatableAffineTiledMode for Tiled1 { + const AFFINE_BACKGROUNDS: usize = 1; fn affine(&self) -> &RefCell> { &self.affine diff --git a/agb/src/display/tiled/tiled2.rs b/agb/src/display/tiled/tiled2.rs index 60a3c728..bcef9f31 100644 --- a/agb/src/display/tiled/tiled2.rs +++ b/agb/src/display/tiled/tiled2.rs @@ -1,6 +1,8 @@ use core::cell::RefCell; -use super::{AffineBackgroundSize, AffineMap, AffineTiledMode, MapLoan, TiledMode}; +use super::{ + AffineBackgroundSize, AffineMap, AffineTiledMode, CreatableAffineTiledMode, MapLoan, TiledMode, +}; use crate::{ bitarray::Bitarray, display::{set_graphics_mode, tiled::AFFINE_BG_ID_OFFSET, DisplayMode, Priority}, @@ -36,16 +38,13 @@ impl Tiled2 { } impl TiledMode for Tiled2 { - const REGULAR_BACKGROUNDS: usize = 0; - const AFFINE_BACKGROUNDS: usize = 2; - fn screenblocks(&self) -> &RefCell> { &self.screenblocks } +} - fn regular(&self) -> &RefCell> { - unimplemented!() - } +impl CreatableAffineTiledMode for Tiled2 { + const AFFINE_BACKGROUNDS: usize = 2; fn affine(&self) -> &RefCell> { &self.affine