diff --git a/src/lib.rs b/src/lib.rs index c9f7445..6e4f78e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ pub mod view; pub mod world; use agent::{Agent, SimpleAgent}; +use std::error::Error; use std::io; use std::io::Read; use std::process::exit; @@ -41,3 +42,26 @@ pub fn get_view() -> DefaultView { }); view } + +pub fn draw_world( + world: &ActualWorld, + gen: usize, + view: &DefaultView, +) -> Result> { + (*view.lock().unwrap()).as_mut().unwrap().draw( + gen, + world + .state + .agent_positions + .get(&world.state.tagged) + .map(|pos| (pos.x, pos.y)) + .unwrap(), + world + .state + .agent_positions + .iter() + .map(|(_id, pos)| (pos.x, pos.y)) + .collect::>() + .as_ref(), + ) +} diff --git a/src/main.rs b/src/main.rs index 84c9d82..777bc82 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use gntag::{get_view, get_world, DefaultView}; +use gntag::{draw_world, get_view, get_world, DefaultView}; fn main() { let view = get_view(); @@ -18,26 +18,7 @@ fn run_simulation(view: &DefaultView) { let mut gen = 0; loop { - let resized = (*view.lock().unwrap()) - .as_mut() - .unwrap() - .draw( - gen, - world - .state - .agent_positions - .get(&world.state.tagged) - .map(|pos| (pos.x, pos.y)) - .unwrap(), - world - .state - .agent_positions - .iter() - .map(|(_id, pos)| (pos.x, pos.y)) - .collect::>() - .as_ref(), - ) - .unwrap(); + let resized = draw_world(&world, gen, view).unwrap(); if resized { return; };