mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Simplify tiled0-2
This commit is contained in:
parent
d59e2672c0
commit
31f85cf6b9
|
@ -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<Bitarray<1>>;
|
||||
}
|
||||
|
||||
trait CreatableRegularTiledMode: TiledMode {
|
||||
const REGULAR_BACKGROUNDS: usize;
|
||||
fn regular(&self) -> &RefCell<Bitarray<1>>;
|
||||
}
|
||||
|
||||
trait CreatableAffineTiledMode: TiledMode {
|
||||
const AFFINE_BACKGROUNDS: usize;
|
||||
fn affine(&self) -> &RefCell<Bitarray<1>>;
|
||||
}
|
||||
|
||||
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<const B: bool>;
|
||||
pub trait True {}
|
||||
impl True for If<true> {}
|
||||
|
||||
impl<T> RegularTiledMode for T
|
||||
where
|
||||
T: TiledMode,
|
||||
If<{ T::REGULAR_BACKGROUNDS > 0 }>: True,
|
||||
T: CreatableRegularTiledMode,
|
||||
{
|
||||
fn regular_background(
|
||||
&self,
|
||||
|
@ -283,8 +283,7 @@ where
|
|||
|
||||
impl<T> AffineTiledMode for T
|
||||
where
|
||||
T: TiledMode,
|
||||
If<{ T::AFFINE_BACKGROUNDS > 0 }>: True,
|
||||
T: CreatableAffineTiledMode,
|
||||
{
|
||||
fn affine_background(
|
||||
&self,
|
||||
|
|
|
@ -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<Bitarray<1>> {
|
||||
&self.screenblocks
|
||||
}
|
||||
}
|
||||
|
||||
impl CreatableRegularTiledMode for Tiled0 {
|
||||
const REGULAR_BACKGROUNDS: usize = 4;
|
||||
|
||||
fn regular(&self) -> &RefCell<Bitarray<1>> {
|
||||
&self.regular
|
||||
}
|
||||
|
||||
fn affine(&self) -> &RefCell<Bitarray<1>> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Bitarray<1>> {
|
||||
&self.screenblocks
|
||||
}
|
||||
}
|
||||
|
||||
impl CreatableRegularTiledMode for Tiled1 {
|
||||
const REGULAR_BACKGROUNDS: usize = 2;
|
||||
|
||||
fn regular(&self) -> &RefCell<Bitarray<1>> {
|
||||
&self.regular
|
||||
}
|
||||
}
|
||||
|
||||
impl CreatableAffineTiledMode for Tiled1 {
|
||||
const AFFINE_BACKGROUNDS: usize = 1;
|
||||
|
||||
fn affine(&self) -> &RefCell<Bitarray<1>> {
|
||||
&self.affine
|
||||
|
|
|
@ -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,17 +38,14 @@ impl Tiled2 {
|
|||
}
|
||||
|
||||
impl TiledMode for Tiled2 {
|
||||
const REGULAR_BACKGROUNDS: usize = 0;
|
||||
const AFFINE_BACKGROUNDS: usize = 2;
|
||||
|
||||
fn screenblocks(&self) -> &RefCell<Bitarray<1>> {
|
||||
&self.screenblocks
|
||||
}
|
||||
|
||||
fn regular(&self) -> &RefCell<Bitarray<1>> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
impl CreatableAffineTiledMode for Tiled2 {
|
||||
const AFFINE_BACKGROUNDS: usize = 2;
|
||||
|
||||
fn affine(&self) -> &RefCell<Bitarray<1>> {
|
||||
&self.affine
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue