using par_join.for_each as if I know what I'm doing

This commit is contained in:
Bryant Deters 2021-10-01 18:05:52 -05:00
parent 396604f6d8
commit 8b557f0e2e

View File

@ -16,7 +16,8 @@ use common::{
use common_ecs::{Job, Origin, Phase, System}; use common_ecs::{Job, Origin, Phase, System};
use common_net::{msg::ServerGeneral, sync::CompSyncPackage}; use common_net::{msg::ServerGeneral, sync::CompSyncPackage};
use itertools::Either; use itertools::Either;
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, Write, WriteStorage}; use rayon::iter::ParallelIterator;
use specs::{Entities, Join, ParJoin, Read, ReadExpect, ReadStorage, Write, WriteStorage};
use vek::*; use vek::*;
/// This system will send physics updates to the client /// This system will send physics updates to the client
@ -114,7 +115,7 @@ impl<'a> System<'a> for Sys {
&subscriptions, &subscriptions,
&positions, &positions,
) )
.join() .par_join()
.filter_map(|(client, entity, presence, subscription, pos)| { .filter_map(|(client, entity, presence, subscription, pos)| {
if presence.is_some() && subscription.regions.contains(&key) { if presence.is_some() && subscription.regions.contains(&key) {
Some((client, &subscription.regions, entity, *pos)) Some((client, &subscription.regions, entity, *pos))
@ -321,15 +322,19 @@ impl<'a> System<'a> for Sys {
// TODO: Sync clients that don't have a position? // TODO: Sync clients that don't have a position?
// Sync inventories // Sync inventories
for (inventory, update, client) in (&inventories, &inventory_updates, &clients).join() { (&inventories, &inventory_updates, &clients)
.par_join()
.for_each(|(inventory, update, client)| {
client.send_fallible(ServerGeneral::InventoryUpdate( client.send_fallible(ServerGeneral::InventoryUpdate(
inventory.clone(), inventory.clone(),
update.event(), update.event(),
)); ));
} });
// Sync outcomes // Sync outcomes
for (presence, pos, client) in (presences.maybe(), positions.maybe(), &clients).join() { (presences.maybe(), positions.maybe(), &clients)
.par_join()
.for_each(|(presence, pos, client)| {
let is_near = |o_pos: Vec3<f32>| { let is_near = |o_pos: Vec3<f32>| {
pos.zip_with(presence, |pos, presence| { pos.zip_with(presence, |pos, presence| {
pos.0.xy().distance_squared(o_pos.xy()) pos.0.xy().distance_squared(o_pos.xy())
@ -346,7 +351,7 @@ impl<'a> System<'a> for Sys {
if !outcomes.is_empty() { if !outcomes.is_empty() {
client.send_fallible(ServerGeneral::Outcomes(outcomes)); client.send_fallible(ServerGeneral::Outcomes(outcomes));
} }
} });
outcomes.clear(); outcomes.clear();
// Remove all force flags. // Remove all force flags.