From c867fb78804d0f7ae1d421f5fead91fd25ed08f0 Mon Sep 17 00:00:00 2001 From: Corwin Date: Wed, 19 Jul 2023 20:33:27 +0100 Subject: [PATCH] finish early if oam slots are full --- agb/src/display/object/unmanaged/object.rs | 29 ++++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/agb/src/display/object/unmanaged/object.rs b/agb/src/display/object/unmanaged/object.rs index 35cfecd9b..01b170a2c 100644 --- a/agb/src/display/object/unmanaged/object.rs +++ b/agb/src/display/object/unmanaged/object.rs @@ -153,9 +153,12 @@ impl<'oam> Iterator for OamIterator<'oam> { } impl OamIterator<'_> { - fn set_inner(&mut self, object: &ObjectUnmanaged) { + fn set_inner(&mut self, object: &ObjectUnmanaged) -> bool { if let Some(slot) = self.next() { slot.set(object); + true + } else { + false } } @@ -388,25 +391,25 @@ mod tests { /// Something (or multiple things) that can be written to oam slots pub trait OamDisplay { - /// Write it to oam slots. - fn set_in(self, oam: &mut OamIterator); + /// Write it to oam slots, returns whether all the writes could succeed. + fn set_in(self, oam: &mut OamIterator) -> bool; } impl OamDisplay for ObjectUnmanaged { - fn set_in(self, oam: &mut OamIterator) { - oam.set_inner(&self); + fn set_in(self, oam: &mut OamIterator) -> bool { + oam.set_inner(&self) } } impl OamDisplay for &ObjectUnmanaged { - fn set_in(self, oam: &mut OamIterator) { - oam.set_inner(self); + fn set_in(self, oam: &mut OamIterator) -> bool { + oam.set_inner(self) } } impl OamDisplay for &mut ObjectUnmanaged { - fn set_in(self, oam: &mut OamIterator) { - oam.set_inner(self); + fn set_in(self, oam: &mut OamIterator) -> bool { + oam.set_inner(self) } } @@ -415,9 +418,13 @@ where T: IntoIterator, O: OamDisplay, { - fn set_in(self, oam: &mut OamIterator) { + fn set_in(self, oam: &mut OamIterator) -> bool { for object in self.into_iter() { - object.set_in(oam); + if !object.set_in(oam) { + return false; + } } + + true } }