veloren/server/src/sys/persistence/stats.rs
Shane Handley e852e0cfab - Update the stats of characters individually, reverting the change with
big combined updates.
- Add a timer to the stats persistence system and change the frequency
that it runs to 10s
- Seperate the loading of character data for the character list during
selection, and the full data we will grab during state creation. Ideally
additional persisted bits can get returned at the same point and added
to the ecs within the same block.
2020-05-13 09:14:09 +10:00

32 lines
783 B
Rust

use crate::{
persistence::stats,
sys::{SysScheduler, SysTimer},
};
use common::comp::{Player, Stats};
use specs::{Join, ReadStorage, System, Write};
pub struct Sys;
impl<'a> System<'a> for Sys {
type SystemData = (
ReadStorage<'a, Player>,
ReadStorage<'a, Stats>,
Write<'a, SysScheduler<Self>>,
Write<'a, SysTimer<Self>>,
);
fn run(&mut self, (players, player_stats, mut scheduler, mut timer): Self::SystemData) {
if scheduler.should_run() {
timer.start();
stats::update(
(&players, &player_stats)
.join()
.filter_map(|(player, stats)| player.character_id.map(|id| (id, stats))),
);
timer.end();
}
}
}