2020-05-11 10:06:53 +00:00
|
|
|
use crate::{
|
2020-06-01 21:34:52 +00:00
|
|
|
persistence::character,
|
2020-05-11 10:06:53 +00:00
|
|
|
sys::{SysScheduler, SysTimer},
|
|
|
|
};
|
2020-06-01 21:34:52 +00:00
|
|
|
use common::comp::{Inventory, Player, Stats};
|
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 {
|
|
|
|
type SystemData = (
|
|
|
|
ReadStorage<'a, Player>,
|
|
|
|
ReadStorage<'a, Stats>,
|
2020-06-01 21:34:52 +00:00
|
|
|
ReadStorage<'a, Inventory>,
|
|
|
|
ReadExpect<'a, character::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-01 21:34:52 +00:00
|
|
|
(players, player_stats, player_inventories, updater, mut scheduler, mut timer): Self::SystemData,
|
2020-05-12 23:58:15 +00:00
|
|
|
) {
|
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-01 21:34:52 +00:00
|
|
|
(&players, &player_stats, &player_inventories)
|
2020-05-11 10:06:53 +00:00
|
|
|
.join()
|
2020-06-01 21:34:52 +00:00
|
|
|
.filter_map(|(player, stats, inventory)| {
|
|
|
|
player.character_id.map(|id| (id, stats, inventory))
|
|
|
|
}),
|
2020-05-11 10:06:53 +00:00
|
|
|
);
|
|
|
|
timer.end();
|
2020-04-25 13:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|