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-04 11:44:33 +00:00
|
|
|
use common::comp::{Inventory, Loadout, 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>,
|
2020-06-04 11:44:33 +00:00
|
|
|
ReadStorage<'a, Loadout>,
|
2020-06-01 21:34:52 +00:00
|
|
|
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-04 11:44:33 +00:00
|
|
|
(
|
|
|
|
players,
|
|
|
|
player_stats,
|
|
|
|
player_inventories,
|
|
|
|
player_loadouts,
|
|
|
|
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-04 11:44:33 +00:00
|
|
|
(
|
|
|
|
&players,
|
|
|
|
&player_stats,
|
|
|
|
&player_inventories,
|
|
|
|
&player_loadouts,
|
|
|
|
)
|
2020-05-11 10:06:53 +00:00
|
|
|
.join()
|
2020-06-04 11:44:33 +00:00
|
|
|
.filter_map(|(player, stats, inventory, loadout)| {
|
|
|
|
player
|
|
|
|
.character_id
|
|
|
|
.map(|id| (id, stats, inventory, loadout))
|
2020-06-01 21:34:52 +00:00
|
|
|
}),
|
2020-05-11 10:06:53 +00:00
|
|
|
);
|
|
|
|
timer.end();
|
2020-04-25 13:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|