Browse Source

Extract draw_world

main
Adrian Heine 3 years ago
parent
commit
2ec11dfd6c
  1. 24
      src/lib.rs
  2. 23
      src/main.rs

24
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<bool, Box<dyn Error>> {
(*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::<Vec<_>>()
.as_ref(),
)
}

23
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::<Vec<_>>()
.as_ref(),
)
.unwrap();
let resized = draw_world(&world, gen, view).unwrap();
if resized {
return;
};

Loading…
Cancel
Save