2020-03-09 03:32:34 +00:00
|
|
|
use super::SysTimer;
|
2020-05-14 16:56:10 +00:00
|
|
|
use crate::client::Client;
|
|
|
|
use common::{
|
|
|
|
comp::{Player, Pos, Waypoint, WaypointArea},
|
|
|
|
msg::{Notification, ServerMsg},
|
|
|
|
};
|
2020-03-09 03:32:34 +00:00
|
|
|
use specs::{Entities, Join, ReadStorage, System, Write, WriteStorage};
|
2020-01-25 12:27:36 +00:00
|
|
|
|
2020-05-14 16:56:10 +00:00
|
|
|
const NOTIFY_DISTANCE: f32 = 10.0;
|
|
|
|
|
2020-01-26 12:47:41 +00:00
|
|
|
/// This system updates player waypoints
|
|
|
|
/// TODO: Make this faster by only considering local waypoints
|
2020-01-25 12:27:36 +00:00
|
|
|
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>,
|
2020-05-14 16:56:10 +00:00
|
|
|
WriteStorage<'a, Client>,
|
2020-03-09 03:32:34 +00:00
|
|
|
Write<'a, SysTimer<Self>>,
|
2020-01-25 12:27:36 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
fn run(
|
|
|
|
&mut self,
|
2020-05-14 16:56:10 +00:00
|
|
|
(entities, positions, players, waypoint_areas, mut waypoints, mut clients, mut timer): Self::SystemData,
|
2020-01-25 12:27:36 +00:00
|
|
|
) {
|
2020-03-09 03:32:34 +00:00
|
|
|
timer.start();
|
|
|
|
|
2020-05-14 16:56:10 +00:00
|
|
|
for (entity, player_pos, _, client) in
|
|
|
|
(&entities, &positions, &players, &mut clients).join()
|
|
|
|
{
|
2020-01-25 12:27:36 +00:00
|
|
|
for (waypoint_pos, waypoint_area) in (&positions, &waypoint_areas).join() {
|
2020-05-14 16:56:10 +00:00
|
|
|
if player_pos.0.distance_squared(waypoint_pos.0) < waypoint_area.radius().powi(2) {
|
|
|
|
if let Some(wp) = waypoints.get(entity) {
|
|
|
|
if player_pos.0.distance_squared(wp.get_pos()) > NOTIFY_DISTANCE.powi(2) {
|
|
|
|
client
|
|
|
|
.postbox
|
|
|
|
.send_message(ServerMsg::Notification(Notification::WaypointSaved));
|
|
|
|
}
|
|
|
|
}
|
2020-01-25 12:27:36 +00:00
|
|
|
let _ = waypoints.insert(entity, Waypoint::new(player_pos.0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-09 03:32:34 +00:00
|
|
|
|
|
|
|
timer.end();
|
2020-01-25 12:27:36 +00:00
|
|
|
}
|
|
|
|
}
|