mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
30 lines
1013 B
Rust
30 lines
1013 B
Rust
use common::comp::{Player, Pos, Waypoint, WaypointArea};
|
|
use specs::{Entities, Join, ReadStorage, System, WriteStorage};
|
|
|
|
/// This system updates player waypoints
|
|
/// TODO: Make this faster by only considering local waypoints
|
|
pub struct Sys;
|
|
impl<'a> System<'a> for Sys {
|
|
type SystemData = (
|
|
Entities<'a>,
|
|
ReadStorage<'a, Pos>,
|
|
ReadStorage<'a, Player>,
|
|
ReadStorage<'a, WaypointArea>,
|
|
WriteStorage<'a, Waypoint>,
|
|
);
|
|
|
|
fn run(
|
|
&mut self,
|
|
(entities, positions, players, waypoint_areas, mut waypoints): Self::SystemData,
|
|
) {
|
|
for (entity, player_pos, _) in (&entities, &positions, &players).join() {
|
|
for (waypoint_pos, waypoint_area) in (&positions, &waypoint_areas).join() {
|
|
if player_pos.0.distance_squared(waypoint_pos.0) < waypoint_area.radius().powf(2.0)
|
|
{
|
|
let _ = waypoints.insert(entity, Waypoint::new(player_pos.0));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|