Skip to content

Commit

Permalink
movement
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMascolo committed May 27, 2024
1 parent d4f0d54 commit 2fe57d3
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 30 deletions.
2 changes: 0 additions & 2 deletions gis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ readme = "README.md"

[dependencies]
krabmaga = {path="/home/tirocinio/krABMaga"}
tinyfiledialogs = "3.9.1"
ndarray = "0.15.6"

[features]
visualization = ["krabmaga/visualization"]
Expand Down
1 change: 1 addition & 0 deletions gis/maps/map.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@
"type": "LineString"
}
}

]
}
28 changes: 18 additions & 10 deletions gis/src/model/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use krabmaga::engine::fields::dense_number_grid_2d::DenseNumberGrid2D;
use krabmaga::engine::fields::field::Field;
use krabmaga::engine::fields::field_2d::Field2D;
use krabmaga::engine::location::{Int2D, Real2D};
use krabmaga::{
engine::{schedule::Schedule, state::State},
rand::{self, Rng},
};
use krabmaga::engine::{schedule::Schedule, state::State};

pub struct Map {
pub step: u64,
Expand All @@ -28,6 +25,16 @@ impl Map {
people: Vec::new(),
}
}

pub fn gis_value(&self, loc: Real2D) -> i32 {
return self
.gis_field
.get_value(&Int2D {
x: loc.x as i32,
y: loc.y as i32,
})
.unwrap();
}
}

impl State for Map {
Expand All @@ -40,7 +47,7 @@ impl State for Map {
//self.field = DenseNumberGrid2D::new(self.dim.0, self.dim.1);
}

fn init(&mut self, schedule: &mut Schedule) {
fn init(&mut self, _schedule: &mut Schedule) {
self.step = 0;
}

Expand All @@ -65,22 +72,22 @@ impl State for Map {
}

fn set_gis(&mut self, vec: Vec<i32>, schedule: &mut Schedule) {
let last_d = Real2D { x: 5., y: 5. };
let loc = Real2D { x: 5., y: 5. };
let loc = Real2D { x: 15., y: 25. };
let agent = Person {
id: 0 as u32,
loc,
last_d,
dir_x: 1.0,
dir_y: 1.0,
direction: None,
};
self.people.push(agent.clone());
self.field.set_object_location(agent, loc);
schedule.schedule_repeating(Box::new(agent), 0., 0);

for (index, i) in vec.iter().enumerate() {
let x = (index as f32 / 30 as f32).floor();
let y = index as f32 % 30 as f32;
let x = (index as f32 / 30.).floor();
let y = index as f32 % 30.;

self.gis_field.set_value_location(
*i,
&Int2D {
Expand All @@ -89,5 +96,6 @@ impl State for Map {
},
);
}
self.gis_field.lazy_update();
}
}
Loading

0 comments on commit 2fe57d3

Please sign in to comment.