From a0700b3a51aba444c45cec7c576159348e928487 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Wed, 21 Feb 2024 12:13:00 +0000 Subject: [PATCH] Move the id storage to the window itself --- agb/src/display/window.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/agb/src/display/window.rs b/agb/src/display/window.rs index 5a454b44..1901d193 100644 --- a/agb/src/display/window.rs +++ b/agb/src/display/window.rs @@ -32,7 +32,7 @@ pub enum WinIn { impl<'gba> Windows<'gba> { pub(crate) fn new() -> Self { let s = Self { - wins: [MovableWindow::new(), MovableWindow::new()], + wins: [MovableWindow::new(0), MovableWindow::new(1)], out: Window::new(), obj: Window::new(), phantom: PhantomData, @@ -63,8 +63,8 @@ impl<'gba> Windows<'gba> { /// modify them. This should be done during vblank shortly after the wait /// for next vblank call. pub fn commit(&self) { - for (id, win) in self.wins.iter().enumerate() { - win.commit(id); + for win in &self.wins { + win.commit(); } self.out.commit(2); self.obj.commit(3); @@ -85,6 +85,7 @@ pub struct Window { pub struct MovableWindow { inner: Window, rect: Rect, + id: usize, } impl Window { @@ -166,10 +167,11 @@ impl Window { } impl MovableWindow { - fn new() -> Self { + fn new(id: usize) -> Self { Self { inner: Window::new(), 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). #[inline(always)] pub fn reset(&mut self) -> &mut Self { - *self = Self::new(); + *self = Self::new(self.id); self } @@ -227,8 +229,8 @@ impl MovableWindow { self } - fn commit(&self, id: usize) { - self.inner.commit(id); + fn commit(&self) { + self.inner.commit(self.id); let left_right = (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 = (self.rect.position.y as u16) << 8 | (self.rect.position.y + self.rect.size.y) as u16; unsafe { - REG_HORIZONTAL_BASE.add(id).write_volatile(left_right); - REG_VERTICAL_BASE.add(id).write_volatile(top_bottom); + REG_HORIZONTAL_BASE.add(self.id).write_volatile(left_right); + REG_VERTICAL_BASE.add(self.id).write_volatile(top_bottom); } }