Move the id storage to the window itself

This commit is contained in:
Gwilym Inzani 2024-02-21 12:13:00 +00:00
parent a3f772c7a3
commit a0700b3a51

View file

@ -32,7 +32,7 @@ pub enum WinIn {
impl<'gba> Windows<'gba> { impl<'gba> Windows<'gba> {
pub(crate) fn new() -> Self { pub(crate) fn new() -> Self {
let s = Self { let s = Self {
wins: [MovableWindow::new(), MovableWindow::new()], wins: [MovableWindow::new(0), MovableWindow::new(1)],
out: Window::new(), out: Window::new(),
obj: Window::new(), obj: Window::new(),
phantom: PhantomData, phantom: PhantomData,
@ -63,8 +63,8 @@ impl<'gba> Windows<'gba> {
/// modify them. This should be done during vblank shortly after the wait /// modify them. This should be done during vblank shortly after the wait
/// for next vblank call. /// for next vblank call.
pub fn commit(&self) { pub fn commit(&self) {
for (id, win) in self.wins.iter().enumerate() { for win in &self.wins {
win.commit(id); win.commit();
} }
self.out.commit(2); self.out.commit(2);
self.obj.commit(3); self.obj.commit(3);
@ -85,6 +85,7 @@ pub struct Window {
pub struct MovableWindow { pub struct MovableWindow {
inner: Window, inner: Window,
rect: Rect<u8>, rect: Rect<u8>,
id: usize,
} }
impl Window { impl Window {
@ -166,10 +167,11 @@ impl Window {
} }
impl MovableWindow { impl MovableWindow {
fn new() -> Self { fn new(id: usize) -> Self {
Self { Self {
inner: Window::new(), inner: Window::new(),
rect: Rect::new((0, 0).into(), (0, 0).into()), rect: Rect::new((0, 0).into(), (0, 0).into()),
id,
} }
} }
@ -201,7 +203,7 @@ impl MovableWindow {
/// nothing rendered and represents a 0x0 rectangle at (0, 0). /// nothing rendered and represents a 0x0 rectangle at (0, 0).
#[inline(always)] #[inline(always)]
pub fn reset(&mut self) -> &mut Self { pub fn reset(&mut self) -> &mut Self {
*self = Self::new(); *self = Self::new(self.id);
self self
} }
@ -227,8 +229,8 @@ impl MovableWindow {
self self
} }
fn commit(&self, id: usize) { fn commit(&self) {
self.inner.commit(id); self.inner.commit(self.id);
let left_right = let left_right =
(self.rect.position.x as u16) << 8 | (self.rect.position.x + self.rect.size.x) as u16; (self.rect.position.x as u16) << 8 | (self.rect.position.x + self.rect.size.x) as u16;
@ -236,8 +238,8 @@ impl MovableWindow {
let top_bottom = let top_bottom =
(self.rect.position.y as u16) << 8 | (self.rect.position.y + self.rect.size.y) as u16; (self.rect.position.y as u16) << 8 | (self.rect.position.y + self.rect.size.y) as u16;
unsafe { unsafe {
REG_HORIZONTAL_BASE.add(id).write_volatile(left_right); REG_HORIZONTAL_BASE.add(self.id).write_volatile(left_right);
REG_VERTICAL_BASE.add(id).write_volatile(top_bottom); REG_VERTICAL_BASE.add(self.id).write_volatile(top_bottom);
} }
} }