From 409798c3bf1d3cb7134a480f7daba0db309325e7 Mon Sep 17 00:00:00 2001 From: Corwin Date: Tue, 25 Apr 2023 21:07:31 +0100 Subject: [PATCH] use fancy way of getting and setting slots --- examples/amplitude/src/lib.rs | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/examples/amplitude/src/lib.rs b/examples/amplitude/src/lib.rs index cf5b8c6a..8c145abb 100644 --- a/examples/amplitude/src/lib.rs +++ b/examples/amplitude/src/lib.rs @@ -63,7 +63,7 @@ fn draw_number( oam: &mut OamIterator, direction: DrawDirection, sprite_cache: &SpriteCache, -) { +) -> Option<()> { let mut digits = Vec::new(); if number == 0 { digits.push(0); @@ -84,12 +84,12 @@ fn draw_number( let mut obj = ObjectUnmanaged::new(sprite_cache.numbers[digit as usize].clone()); obj.show().set_position(current_position); - if let Some(slot) = oam.next() { - slot.set(&obj); - } + oam.next()?.set(&obj); current_position -= (4, 0).into(); } + + Some(()) } impl SpriteCache { @@ -259,27 +259,25 @@ impl Game { } } - fn render(&self, oam: &mut OamIterator, sprite_cache: &SpriteCache) { + fn render(&self, oam: &mut OamIterator, sprite_cache: &SpriteCache) -> Option<()> { for saw in self.saws.iter() { - if let Some(slot) = oam.next() { - slot.set(&saw.object); - } + oam.next()?.set(&saw.object); } for circle in self.circles.iter() { - if let Some(slot) = oam.next() { - let mut object = ObjectUnmanaged::new(match circle.colour { - Colour::Red => sprite_cache.red.clone(), - Colour::Blue => sprite_cache.blue.clone(), - }); + let mut object = ObjectUnmanaged::new(match circle.colour { + Colour::Red => sprite_cache.red.clone(), + Colour::Blue => sprite_cache.blue.clone(), + }); - object - .show() - .set_position(circle.position.floor() - (4, 4).into()); + object + .show() + .set_position(circle.position.floor() - (4, 4).into()); - slot.set(&object); - } + oam.next()?.set(&object); } + + Some(()) } }