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> {
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<u8>,
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);
}
}