summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/character.rs2
-rw-r--r--src/list.rs27
-rw-r--r--src/main.rs4
3 files changed, 15 insertions, 18 deletions
diff --git a/src/character.rs b/src/character.rs
index 0d19193..6a71d4c 100644
--- a/src/character.rs
+++ b/src/character.rs
@@ -109,7 +109,6 @@ impl Character {
fn move_along_path(&mut self, free_spaces : Vec<(Location, usize)>) {
let mut moved = false;
match self.path {
- None => (),
Some(ref mut calculated_path) => {
if calculated_path.len() > 0 {
let next_location = calculated_path.pop().unwrap();
@@ -125,6 +124,7 @@ impl Character {
self.order = Orders::Wait as u8;
}
}
+ _ => (),
}
if !moved {
self.path = None;
diff --git a/src/list.rs b/src/list.rs
index cba5c16..1383394 100644
--- a/src/list.rs
+++ b/src/list.rs
@@ -1,4 +1,4 @@
-use std::thread::spawn;
+use std::thread::{spawn, JoinHandle};
extern crate pancurses;
@@ -9,10 +9,10 @@ use location::Location;
use character::Character;
use constants::Colors;
-#[derive(Clone)]
pub struct List{
pub men : Vec<Character>,
impassable_locations : Vec<Location>,
+ threads : Vec<JoinHandle<(usize, Option<Vec<Location>>)>>
}
impl List {
@@ -25,6 +25,7 @@ impl List {
List {
men : men,
impassable_locations : impassable_locations,
+ threads : Vec::new(),
}
}
@@ -35,28 +36,24 @@ impl List {
self.men[i].action(free_locations);
}
- let mut threads = vec!();
+ while !self.threads.is_empty() {
+ let thread = self.threads.pop().unwrap();
+ let (i, path) = thread.join().unwrap();
+ self.men[i].give_path(path);
+ }
+
let impassable = self.get_all_impassable();
for i in 0..self.men.len() {
if self.men[i].needs_path() {
let man = self.men[i].clone();
let impassable_clone = impassable.clone();
- threads.push(spawn(move || {
+ self.threads.push(spawn(move || {
(i, calculate_path(man, impassable_clone))
}));
}
}
-
- for thread in threads {
- let data = thread.join();
- match data {
- Ok(data) => self.men[data.0].give_path(data.1),
- _ => (),
- }
- }
}
-
pub fn give_destination(&mut self, destination : Location) {
for i in 0..self.men.len() {
self.men[i].give_destination(destination)
@@ -147,9 +144,9 @@ fn calculate_path(man : Character, impassable : Vec<(Location, usize)>) -> Optio
result.0.pop();
Some(result.0)
}
- None => None,
+ _ => None,
}
}
- None => None,
+ _ => None,
}
}
diff --git a/src/main.rs b/src/main.rs
index 81ce270..3175477 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -79,7 +79,7 @@ fn main() {
None => (),
}
},
- None => (),
+ _ => (),
}
if !paused {
@@ -91,7 +91,7 @@ fn main() {
if draw_box {
match first_location {
Some(first_location) => map.draw_box(first_location, cursor.get_location()),
- None => (),
+ _ => (),
}
}