2020-05-11 10:06:53 +00:00
|
|
|
use crate::{
|
2020-09-17 23:02:14 +00:00
|
|
|
persistence::character_updater,
|
2020-10-30 16:39:53 +00:00
|
|
|
presence::Presence,
|
2020-05-11 10:06:53 +00:00
|
|
|
sys::{SysScheduler, SysTimer},
|
|
|
|
};
|
2020-08-29 06:39:16 +00:00
|
|
|
use common::{
|
2020-11-03 00:12:49 +00:00
|
|
|
comp::{Inventory, Loadout, Stats, Waypoint},
|
2020-10-30 16:39:53 +00:00
|
|
|
msg::PresenceKind,
|
2020-08-29 06:39:16 +00:00
|
|
|
span,
|
|
|
|
};
|
2020-05-12 23:58:15 +00:00
|
|
|
use specs::{Join, ReadExpect, ReadStorage, System, Write};
|
2020-04-25 13:41:27 +00:00
|
|
|
|
|
|
|
pub struct Sys;
|
|
|
|
|
|
|
|
impl<'a> System<'a> for Sys {
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::type_complexity)] // TODO: Pending review in #587
|
2020-04-25 13:41:27 +00:00
|
|
|
type SystemData = (
|
2020-10-30 16:39:53 +00:00
|
|
|
ReadStorage<'a, Presence>,
|
2020-04-25 13:41:27 +00:00
|
|
|
ReadStorage<'a, Stats>,
|
2020-06-01 21:34:52 +00:00
|
|
|
ReadStorage<'a, Inventory>,
|
2020-06-04 11:44:33 +00:00
|
|
|
ReadStorage<'a, Loadout>,
|
2020-11-03 00:12:49 +00:00
|
|
|
ReadStorage<'a, Waypoint>,
|
2020-09-17 23:02:14 +00:00
|
|
|
ReadExpect<'a, character_updater::CharacterUpdater>,
|
2020-04-25 13:41:27 +00:00
|
|
|
Write<'a, SysScheduler<Self>>,
|
2020-05-11 10:06:53 +00:00
|
|
|
Write<'a, SysTimer<Self>>,
|
2020-04-25 13:41:27 +00:00
|
|
|
);
|
|
|
|
|
2020-05-12 23:58:15 +00:00
|
|
|
fn run(
|
|
|
|
&mut self,
|
2020-06-04 11:44:33 +00:00
|
|
|
(
|
2020-10-30 16:39:53 +00:00
|
|
|
presences,
|
2020-06-04 11:44:33 +00:00
|
|
|
player_stats,
|
|
|
|
player_inventories,
|
|
|
|
player_loadouts,
|
2020-11-03 00:12:49 +00:00
|
|
|
player_waypoint,
|
2020-06-04 11:44:33 +00:00
|
|
|
updater,
|
|
|
|
mut scheduler,
|
|
|
|
mut timer,
|
|
|
|
): Self::SystemData,
|
2020-05-12 23:58:15 +00:00
|
|
|
) {
|
2020-09-07 04:59:16 +00:00
|
|
|
span!(_guard, "run", "persistence::Sys::run");
|
2020-04-25 13:41:27 +00:00
|
|
|
if scheduler.should_run() {
|
2020-05-11 10:06:53 +00:00
|
|
|
timer.start();
|
2020-05-15 20:03:51 +00:00
|
|
|
updater.batch_update(
|
2020-06-04 11:44:33 +00:00
|
|
|
(
|
2020-10-30 16:39:53 +00:00
|
|
|
&presences,
|
2020-06-04 11:44:33 +00:00
|
|
|
&player_stats,
|
|
|
|
&player_inventories,
|
|
|
|
&player_loadouts,
|
2020-11-03 00:12:49 +00:00
|
|
|
player_waypoint.maybe(),
|
2020-06-04 11:44:33 +00:00
|
|
|
)
|
2020-05-11 10:06:53 +00:00
|
|
|
.join()
|
2020-10-30 16:39:53 +00:00
|
|
|
.filter_map(
|
2020-11-03 00:12:49 +00:00
|
|
|
|(presence, stats, inventory, loadout, waypoint)| match presence.kind {
|
|
|
|
PresenceKind::Character(id) => {
|
|
|
|
Some((id, stats, inventory, loadout, waypoint))
|
|
|
|
},
|
2020-10-30 16:39:53 +00:00
|
|
|
PresenceKind::Spectator => None,
|
|
|
|
},
|
|
|
|
),
|
2020-05-11 10:06:53 +00:00
|
|
|
);
|
|
|
|
timer.end();
|
2020-04-25 13:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|