From 0eec7e366cbc6148033eb62e3b6366377922f0f7 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 23 Feb 2023 20:36:00 +0000 Subject: [PATCH] Add lifetimes to ObjectController --- agb/src/display/mod.rs | 2 +- agb/src/display/object.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/agb/src/display/mod.rs b/agb/src/display/mod.rs index fba3aaa5..90f78727 100644 --- a/agb/src/display/mod.rs +++ b/agb/src/display/mod.rs @@ -79,7 +79,7 @@ pub struct Display { pub struct ObjectDistribution; impl ObjectDistribution { - pub fn get(&mut self) -> ObjectController { + pub fn get(&mut self) -> ObjectController<'_> { ObjectController::new() } } diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 6e617127..d0c70aed 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -694,11 +694,12 @@ impl ObjectControllerStatic { /// A controller that distributes objects and sprites. This controls sprites and /// objects being copied to vram when it needs to be. -pub struct ObjectController { +pub struct ObjectController<'a> { + phantom: PhantomData<&'a ()>, inner: ObjectControllerReference<'static>, } -impl Drop for ObjectController { +impl<'a> Drop for ObjectController<'a> { fn drop(&mut self) { unsafe { ObjectControllerReference::uninit(); @@ -708,7 +709,7 @@ impl Drop for ObjectController { const HIDDEN_VALUE: u16 = 0b10 << 8; -impl ObjectController { +impl<'object> ObjectController<'object> { /// Commits the objects to vram and delete sprites where possible. This /// should be called shortly after having waited for the next vblank to /// ensure what is displayed on screen doesn't change part way through. @@ -759,6 +760,7 @@ impl ObjectController { } Self { + phantom: PhantomData, inner: unsafe { ObjectControllerReference::init() }, } }