From ef5eaa68e96874c763420636b0de35215a9600e0 Mon Sep 17 00:00:00 2001 From: DanielMowitz <53856770+DanielMowitz@users.noreply.github.com> Date: Thu, 19 Sep 2019 13:26:40 +0200 Subject: [PATCH 1/3] Update mod.rs disp can now drop all refs --- src/dispatcher/mod.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/dispatcher/mod.rs b/src/dispatcher/mod.rs index af2bec1..1df853e 100644 --- a/src/dispatcher/mod.rs +++ b/src/dispatcher/mod.rs @@ -43,7 +43,7 @@ impl<'a> Dispatcher<'a> { max_stack_time, current_stack_start_time: Instant::now(), dt: 0.0, - }; + } } /// Works through the two stacks and dispatches the topmost @@ -222,18 +222,23 @@ impl<'a> Dispatcher<'a> { match self.store_refs.take() { Some(x) => { local_store_refs = x; - for reference in references { - local_store_refs.push(Some(reference)); - } } _ => { local_store_refs = vec![]; - for reference in references { - local_store_refs.push(Some(reference)); - } } } + for reference in references { + local_store_refs.push(Some(reference)); + } + self.store_refs = Some(local_store_refs); } + + ///Used to drop all Store references before ending the game loop + pub fn drop_refs(&mut self) { + match self.store_refs.take(){ + _ => {} + } + } } From 9ca9d834d9f3aaa0e6bcb026849d1fcae9bf3d93 Mon Sep 17 00:00:00 2001 From: DanielMowitz <53856770+DanielMowitz@users.noreply.github.com> Date: Thu, 19 Sep 2019 13:27:52 +0200 Subject: [PATCH 2/3] Update lib.rs --- src/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cc12cbe..fb239b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,8 @@ extern crate rand; extern crate sdl2; +use dispatcher::Dispatcher; + pub mod dispatcher; pub mod action; pub mod store; @@ -18,8 +20,12 @@ pub mod scene_manager; mod tests; /// "Front-end"-function of the dispatcher -pub fn game_loop<'a>(disp: &'a mut dispatcher::Dispatcher<'a>, store_refs: Vec<&'a mut store::Store<'a>>) { - disp.enter_refs(store_refs); +pub fn game_loop<'a>(mut disp: & mut dispatcher::Dispatcher<'a>, store_refs: Vec<&'a mut store::Store<'a>>) { //todo: HMM + + disp.enter_refs(store_refs); + + while disp.dispatch() {}; + + disp.drop_refs(); - while disp.dispatch() {}; } From 8d2b43adf933dd63a94ed66289283e9926da2d03 Mon Sep 17 00:00:00 2001 From: DanielMowitz <53856770+DanielMowitz@users.noreply.github.com> Date: Thu, 19 Sep 2019 13:33:30 +0200 Subject: [PATCH 3/3] Update lib.rs Removed some superfluous things --- src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fb239b2..ee31eff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,6 @@ extern crate rand; extern crate sdl2; -use dispatcher::Dispatcher; - pub mod dispatcher; pub mod action; pub mod store; @@ -20,7 +18,7 @@ pub mod scene_manager; mod tests; /// "Front-end"-function of the dispatcher -pub fn game_loop<'a>(mut disp: & mut dispatcher::Dispatcher<'a>, store_refs: Vec<&'a mut store::Store<'a>>) { //todo: HMM +pub fn game_loop<'a>(mut disp: & mut dispatcher::Dispatcher<'a>, store_refs: Vec<&'a mut store::Store<'a>>) { disp.enter_refs(store_refs);