veloren/server/src/sys/persistence.rs

61 lines
1.6 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, Loadout, Stats},
msg::PresenceKind,
2020-08-29 06:39:16 +00:00
span,
};
use specs::{Join, ReadExpect, ReadStorage, System, Write};
pub struct Sys;
impl<'a> System<'a> for Sys {
#[allow(clippy::type_complexity)] // TODO: Pending review in #587
type SystemData = (
ReadStorage<'a, Presence>,
ReadStorage<'a, Stats>,
ReadStorage<'a, Inventory>,
ReadStorage<'a, Loadout>,
ReadExpect<'a, character_updater::CharacterUpdater>,
Write<'a, SysScheduler<Self>>,
Write<'a, SysTimer<Self>>,
);
fn run(
&mut self,
(
presences,
player_stats,
player_inventories,
player_loadouts,
updater,
mut scheduler,
mut timer,
): Self::SystemData,
) {
span!(_guard, "run", "persistence::Sys::run");
if scheduler.should_run() {
timer.start();
2020-05-15 20:03:51 +00:00
updater.batch_update(
(
&presences,
&player_stats,
&player_inventories,
&player_loadouts,
)
.join()
.filter_map(
|(presence, stats, inventory, loadout)| match presence.kind {
PresenceKind::Character(id) => Some((id, stats, inventory, loadout)),
PresenceKind::Spectator => None,
},
),
);
timer.end();
}
}
}