veloren/server/src/sys/persistence.rs

65 lines
1.8 KiB
Rust
Raw Normal View History

use crate::{
persistence::character_updater,
presence::Presence,
sys::{SysScheduler, SysTimer},
};
2020-08-29 06:39:16 +00:00
use common::{
comp::{Inventory, Stats, Waypoint},
vsystem::{Origin, Phase, VJob, VSystem},
2020-08-29 06:39:16 +00:00
};
use common_net::msg::PresenceKind;
use specs::{Join, ReadExpect, ReadStorage, Write};
#[derive(Default)]
pub struct Sys;
impl<'a> VSystem<'a> for Sys {
#[allow(clippy::type_complexity)] // TODO: Pending review in #587
type SystemData = (
ReadStorage<'a, Presence>,
ReadStorage<'a, Stats>,
ReadStorage<'a, Inventory>,
2020-11-03 00:12:49 +00:00
ReadStorage<'a, Waypoint>,
ReadExpect<'a, character_updater::CharacterUpdater>,
Write<'a, SysScheduler<Self>>,
Write<'a, SysTimer<Self>>,
);
const NAME: &'static str = "persistence";
const ORIGIN: Origin = Origin::Server;
const PHASE: Phase = Phase::Create;
fn run(
_job: &mut VJob<Self>,
(
presences,
player_stats,
player_inventories,
2020-11-03 00:12:49 +00:00
player_waypoint,
updater,
mut scheduler,
mut timer,
): Self::SystemData,
) {
if scheduler.should_run() {
timer.start();
2020-05-15 20:03:51 +00:00
updater.batch_update(
(
&presences,
&player_stats,
&player_inventories,
2020-11-03 00:12:49 +00:00
player_waypoint.maybe(),
)
.join()
.filter_map(
|(presence, stats, inventory, waypoint)| match presence.kind {
PresenceKind::Character(id) => Some((id, stats, inventory, waypoint)),
PresenceKind::Spectator => None,
},
),
);
timer.end();
}
}
}