From 06901b3543c5a7ff46771cdab1b3a7bf63423953 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Mon, 7 Feb 2022 22:17:57 +0000 Subject: [PATCH] Move post-work to pre-work --- agb/src/display/background.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/agb/src/display/background.rs b/agb/src/display/background.rs index bc675092..b94aa143 100644 --- a/agb/src/display/background.rs +++ b/agb/src/display/background.rs @@ -465,6 +465,16 @@ impl<'a> InfiniteScrolledMap<'a> { let x_end = div_ceil(self.current_pos.x + display::WIDTH, 8) + 1; let y_end = div_ceil(self.current_pos.y + display::HEIGHT, 8) + 1; + let offset = self.current_pos - (x_start * 8, y_start * 8).into(); + let offset_scroll = ( + offset.x.rem_euclid(32 * 8) as u16, + offset.y.rem_euclid(32 * 8) as u16, + ) + .into(); + + self.map.set_scroll_pos(offset_scroll); + self.offset = (x_start, y_start).into(); + for (y_idx, y) in (y_start..y_end).enumerate() { for (x_idx, x) in (x_start..x_end).enumerate() { let pos = (x, y).into(); @@ -478,16 +488,6 @@ impl<'a> InfiniteScrolledMap<'a> { ); } } - - let offset = self.current_pos - (x_start * 8, y_start * 8).into(); - let offset_scroll = ( - offset.x.rem_euclid(32 * 8) as u16, - offset.y.rem_euclid(32 * 8) as u16, - ) - .into(); - - self.map.set_scroll_pos(offset_scroll); - self.offset = (x_start, y_start).into(); } pub fn set_pos(&mut self, vram: &mut VRamManager, new_pos: Vector2D) {