diff --git a/common/sys/src/aura.rs b/common/sys/src/aura.rs index b00e3c5868..54f6d3d8b8 100644 --- a/common/sys/src/aura.rs +++ b/common/sys/src/aura.rs @@ -16,7 +16,7 @@ use specs::{ use std::time::Duration; #[derive(SystemData)] -pub struct ImmutableData<'a> { +pub struct ReadData<'a> { entities: Entities<'a>, dt: Read<'a, DeltaTime>, server_bus: Read<'a, EventBus>, @@ -30,21 +30,17 @@ pub struct ImmutableData<'a> { pub struct Sys; impl<'a> System<'a> for Sys { - type SystemData = (ImmutableData<'a>, WriteStorage<'a, Auras>); + type SystemData = (ReadData<'a>, WriteStorage<'a, Auras>); - fn run(&mut self, (immutable_data, mut auras): Self::SystemData) { - let mut server_emitter = immutable_data.server_bus.emitter(); - let dt = immutable_data.dt.0; + fn run(&mut self, (read_data, mut auras): Self::SystemData) { + let mut server_emitter = read_data.server_bus.emitter(); + let dt = read_data.dt.0; auras.set_event_emission(false); // Iterate through all entities with an aura - for (entity, pos, mut auras_comp) in ( - &immutable_data.entities, - &immutable_data.positions, - &mut auras, - ) - .join() + for (entity, pos, mut auras_comp) in + (&read_data.entities, &read_data.positions, &mut auras).join() { let mut expired_auras = Vec::::new(); // Iterate through the auras attached to this entity @@ -61,22 +57,22 @@ impl<'a> System<'a> for Sys { } } for (target, target_pos, target_buffs, health) in ( - &immutable_data.entities, - &immutable_data.positions, - &immutable_data.buffs, - &immutable_data.healths, + &read_data.entities, + &read_data.positions, + &read_data.buffs, + &read_data.healths, ) .join() { // Ensure entity is within the aura radius if target_pos.0.distance_squared(pos.0) < aura.radius.powi(2) { if let AuraTarget::GroupOf(uid) = aura.target { - let same_group = immutable_data + let same_group = read_data .uid_allocator .retrieve_entity_internal(uid.into()) - .and_then(|e| immutable_data.groups.get(e)) + .and_then(|e| read_data.groups.get(e)) .map_or(false, |owner_group| { - Some(owner_group) == immutable_data.groups.get(target) + Some(owner_group) == read_data.groups.get(target) }); if !same_group { @@ -103,7 +99,7 @@ impl<'a> System<'a> for Sys { let apply_buff = match kind { BuffKind::CampfireHeal => { matches!( - immutable_data.char_states.get(target), + read_data.char_states.get(target), Some(CharacterState::Sit) ) && health.current() < health.maximum() }, diff --git a/common/sys/src/beam.rs b/common/sys/src/beam.rs index 00fe705c04..c4c2b863ea 100644 --- a/common/sys/src/beam.rs +++ b/common/sys/src/beam.rs @@ -17,7 +17,7 @@ use std::time::Duration; use vek::*; #[derive(SystemData)] -pub struct ImmutableData<'a> { +pub struct ReadData<'a> { entities: Entities<'a>, server_bus: Read<'a, EventBus>, time: Read<'a, Time>, @@ -39,22 +39,22 @@ pub struct ImmutableData<'a> { pub struct Sys; impl<'a> System<'a> for Sys { type SystemData = ( - ImmutableData<'a>, + ReadData<'a>, WriteStorage<'a, BeamSegment>, WriteStorage<'a, Beam>, ); - fn run(&mut self, (immutable_data, mut beam_segments, mut beams): Self::SystemData) { - let mut server_emitter = immutable_data.server_bus.emitter(); + fn run(&mut self, (read_data, mut beam_segments, mut beams): Self::SystemData) { + let mut server_emitter = read_data.server_bus.emitter(); - let time = immutable_data.time.0; - let dt = immutable_data.dt.0; + let time = read_data.time.0; + let dt = read_data.dt.0; // Beams for (entity, pos, ori, beam_segment) in ( - &immutable_data.entities, - &immutable_data.positions, - &immutable_data.orientations, + &read_data.entities, + &read_data.positions, + &read_data.orientations, &beam_segments, ) .join() @@ -89,15 +89,13 @@ impl<'a> System<'a> for Sys { (beam_segment.speed * (time_since_creation - frame_time)).max(0.0); let frame_end_dist = (beam_segment.speed * time_since_creation).max(frame_start_dist); - let beam_owner = beam_segment.owner.and_then(|uid| { - immutable_data - .uid_allocator - .retrieve_entity_internal(uid.into()) - }); + let beam_owner = beam_segment + .owner + .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())); // Group to ignore collisions with // Might make this more nuanced if beams are used for non damage effects - let group = beam_owner.and_then(|e| immutable_data.groups.get(e)); + let group = beam_owner.and_then(|e| read_data.groups.get(e)); let hit_entities = if let Some(beam) = beam_owner.and_then(|e| beams.get_mut(e)) { &mut beam.hit_entities @@ -107,11 +105,11 @@ impl<'a> System<'a> for Sys { // Go through all other effectable entities for (target, uid_b, pos_b, health_b, body_b) in ( - &immutable_data.entities, - &immutable_data.uids, - &immutable_data.positions, - &immutable_data.healths, - &immutable_data.bodies, + &read_data.entities, + &read_data.uids, + &read_data.positions, + &read_data.healths, + &read_data.bodies, ) .join() { @@ -121,8 +119,8 @@ impl<'a> System<'a> for Sys { } // Scales - let scale_b = immutable_data.scales.get(target).map_or(1.0, |s| s.0); - let last_pos_b_maybe = immutable_data.last_positions.get(target); + let scale_b = read_data.scales.get(target).map_or(1.0, |s| s.0); + let last_pos_b_maybe = read_data.last_positions.get(target); let rad_b = body_b.radius() * scale_b; let height_b = body_b.height() * scale_b; @@ -136,7 +134,7 @@ impl<'a> System<'a> for Sys { if hit { // See if entities are in the same group let same_group = group - .map(|group_a| Some(group_a) == immutable_data.groups.get(target)) + .map(|group_a| Some(group_a) == read_data.groups.get(target)) .unwrap_or(Some(*uid_b) == beam_segment.owner); let target_group = if same_group { @@ -156,14 +154,14 @@ impl<'a> System<'a> for Sys { .map(|(entity, uid)| AttackerInfo { entity, uid, - energy: immutable_data.energies.get(entity), + energy: read_data.energies.get(entity), }); beam_segment.properties.attack.apply_attack( target_group, attacker_info, target, - immutable_data.inventories.get(target), + read_data.inventories.get(target), ori.look_dir(), false, 1.0, diff --git a/common/sys/src/buff.rs b/common/sys/src/buff.rs index 31753857a3..dc14f4127b 100644 --- a/common/sys/src/buff.rs +++ b/common/sys/src/buff.rs @@ -13,7 +13,7 @@ use specs::{ use std::time::Duration; #[derive(SystemData)] -pub struct ImmutableData<'a> { +pub struct ReadData<'a> { entities: Entities<'a>, dt: Read<'a, DeltaTime>, server_bus: Read<'a, EventBus>, @@ -23,26 +23,21 @@ pub struct ImmutableData<'a> { pub struct Sys; impl<'a> System<'a> for Sys { type SystemData = ( - ImmutableData<'a>, + ReadData<'a>, WriteStorage<'a, Health>, WriteStorage<'a, Energy>, WriteStorage<'a, Buffs>, ); - fn run(&mut self, (immutable_data, mut healths, mut energies, mut buffs): Self::SystemData) { - let mut server_emitter = immutable_data.server_bus.emitter(); - let dt = immutable_data.dt.0; + fn run(&mut self, (read_data, mut healths, mut energies, mut buffs): Self::SystemData) { + let mut server_emitter = read_data.server_bus.emitter(); + let dt = read_data.dt.0; // Set to false to avoid spamming server buffs.set_event_emission(false); healths.set_event_emission(false); energies.set_event_emission(false); - for (entity, mut buff_comp, mut health, mut energy) in ( - &immutable_data.entities, - &mut buffs, - &mut healths, - &mut energies, - ) - .join() + for (entity, mut buff_comp, mut health, mut energy) in + (&read_data.entities, &mut buffs, &mut healths, &mut energies).join() { let (buff_comp_kinds, buff_comp_buffs) = buff_comp.parts(); let mut expired_buffs = Vec::::new(); @@ -66,7 +61,7 @@ impl<'a> System<'a> for Sys { } } - if let Some(inventory) = immutable_data.inventories.get(entity) { + if let Some(inventory) = read_data.inventories.get(entity) { let damage_reduction = Damage::compute_damage_reduction(inventory); if (damage_reduction - 1.0).abs() < f32::EPSILON { for (id, buff) in buff_comp.buffs.iter() { diff --git a/common/sys/src/character_behavior.rs b/common/sys/src/character_behavior.rs index 56a2d91b10..f35023857e 100644 --- a/common/sys/src/character_behavior.rs +++ b/common/sys/src/character_behavior.rs @@ -47,7 +47,7 @@ fn incorporate_update(join: &mut JoinStruct, state_update: StateUpdate) { } #[derive(SystemData)] -pub struct ImmutableData<'a> { +pub struct ReadData<'a> { entities: Entities<'a>, server_bus: Read<'a, EventBus>, local_bus: Read<'a, EventBus>, @@ -72,7 +72,7 @@ pub struct Sys; impl<'a> System<'a> for Sys { #[allow(clippy::type_complexity)] type SystemData = ( - ImmutableData<'a>, + ReadData<'a>, WriteStorage<'a, CharacterState>, WriteStorage<'a, Pos>, WriteStorage<'a, Vel>, @@ -87,7 +87,7 @@ impl<'a> System<'a> for Sys { fn run( &mut self, ( - immutable_data, + read_data, mut character_states, mut positions, mut velocities, @@ -100,8 +100,8 @@ impl<'a> System<'a> for Sys { ) { let start_time = std::time::Instant::now(); span!(_guard, "run", "character_behavior::Sys::run"); - let mut server_emitter = immutable_data.server_bus.emitter(); - let mut local_emitter = immutable_data.local_bus.emitter(); + let mut server_emitter = read_data.server_bus.emitter(); + let mut local_emitter = read_data.local_bus.emitter(); for ( entity, @@ -118,8 +118,8 @@ impl<'a> System<'a> for Sys { physics, stat, ) in ( - &immutable_data.entities, - &immutable_data.uids, + &read_data.entities, + &read_data.uids, &mut character_states.restrict_mut(), &mut positions, &mut velocities, @@ -127,10 +127,10 @@ impl<'a> System<'a> for Sys { &mut energies.restrict_mut(), &mut inventories.restrict_mut(), &mut controllers, - &immutable_data.healths, - &immutable_data.bodies, - &immutable_data.physics_states, - &immutable_data.stats, + &read_data.healths, + &read_data.bodies, + &read_data.physics_states, + &read_data.stats, ) .join() { @@ -141,7 +141,7 @@ impl<'a> System<'a> for Sys { } // If mounted, character state is controlled by mount // TODO: Make mounting a state - if let Some(Mounting(_)) = immutable_data.mountings.get(entity) { + if let Some(Mounting(_)) = read_data.mountings.get(entity) { let sit_state = CharacterState::Sit {}; if char_state.get_unchecked() != &sit_state { *char_state.get_mut_unchecked() = sit_state; @@ -246,17 +246,13 @@ impl<'a> System<'a> for Sys { health: &health, body: &body, physics: &physics, - melee_attack: immutable_data.melee_attacks.get(entity), - beam: immutable_data.beams.get(entity), + melee_attack: read_data.melee_attacks.get(entity), + beam: read_data.beams.get(entity), stat: &stat, }; for action in actions { - let j = JoinData::new( - &join_struct, - &immutable_data.lazy_update, - &immutable_data.dt, - ); + let j = JoinData::new(&join_struct, &read_data.lazy_update, &read_data.dt); let mut state_update = match j.character { CharacterState::Idle => states::idle::Data.handle_event(&j, action), CharacterState::Talk => states::talk::Data.handle_event(&j, action), @@ -299,11 +295,7 @@ impl<'a> System<'a> for Sys { incorporate_update(&mut join_struct, state_update); } - let j = JoinData::new( - &join_struct, - &immutable_data.lazy_update, - &immutable_data.dt, - ); + let j = JoinData::new(&join_struct, &read_data.lazy_update, &read_data.dt); let mut state_update = match j.character { CharacterState::Idle => states::idle::Data.behavior(&j), @@ -337,7 +329,7 @@ impl<'a> System<'a> for Sys { server_emitter.append(&mut state_update.server_events); incorporate_update(&mut join_struct, state_update); } - immutable_data.metrics.character_behavior_ns.store( + read_data.metrics.character_behavior_ns.store( start_time.elapsed().as_nanos() as u64, std::sync::atomic::Ordering::Relaxed, ); diff --git a/common/sys/src/controller.rs b/common/sys/src/controller.rs index 9ff65f4d14..9289c5d497 100644 --- a/common/sys/src/controller.rs +++ b/common/sys/src/controller.rs @@ -13,7 +13,7 @@ use specs::{ use vek::*; #[derive(SystemData)] -pub struct ImmutableData<'a> { +pub struct ReadData<'a> { entities: Entities<'a>, uid_allocator: Read<'a, UidAllocator>, server_bus: Read<'a, EventBus>, @@ -23,14 +23,14 @@ pub struct ImmutableData<'a> { pub struct Sys; impl<'a> System<'a> for Sys { - type SystemData = (ImmutableData<'a>, WriteStorage<'a, Controller>); + type SystemData = (ReadData<'a>, WriteStorage<'a, Controller>); - fn run(&mut self, (immutable_data, mut controllers): Self::SystemData) { + fn run(&mut self, (read_data, mut controllers): Self::SystemData) { let start_time = std::time::Instant::now(); span!(_guard, "run", "controller::Sys::run"); - let mut server_emitter = immutable_data.server_bus.emitter(); + let mut server_emitter = read_data.server_bus.emitter(); - for (entity, controller) in (&immutable_data.entities, &mut controllers).join() { + for (entity, controller) in (&read_data.entities, &mut controllers).join() { let mut inputs = &mut controller.inputs; // Note(imbris): I avoided incrementing the duration with inputs.tick() because @@ -55,7 +55,7 @@ impl<'a> System<'a> for Sys { for event in controller.events.drain(..) { match event { ControlEvent::Mount(mountee_uid) => { - if let Some(mountee_entity) = immutable_data + if let Some(mountee_entity) = read_data .uid_allocator .retrieve_entity_internal(mountee_uid.id()) { @@ -76,7 +76,7 @@ impl<'a> System<'a> for Sys { server_emitter.emit(ServerEvent::DisableLantern(entity)) }, ControlEvent::Interact(npc_uid) => { - if let Some(npc_entity) = immutable_data + if let Some(npc_entity) = read_data .uid_allocator .retrieve_entity_internal(npc_uid.id()) { @@ -103,7 +103,7 @@ impl<'a> System<'a> for Sys { } } } - immutable_data.metrics.controller_ns.store( + read_data.metrics.controller_ns.store( start_time.elapsed().as_nanos() as u64, std::sync::atomic::Ordering::Relaxed, ); diff --git a/common/sys/src/melee.rs b/common/sys/src/melee.rs index 81d147512c..d9e248c720 100644 --- a/common/sys/src/melee.rs +++ b/common/sys/src/melee.rs @@ -15,7 +15,7 @@ use specs::{ use vek::*; #[derive(SystemData)] -pub struct ImmutableData<'a> { +pub struct ReadData<'a> { entities: Entities<'a>, uids: ReadStorage<'a, Uid>, positions: ReadStorage<'a, Pos>, @@ -36,20 +36,20 @@ pub struct ImmutableData<'a> { pub struct Sys; impl<'a> System<'a> for Sys { - type SystemData = (ImmutableData<'a>, WriteStorage<'a, Melee>); + type SystemData = (ReadData<'a>, WriteStorage<'a, Melee>); - fn run(&mut self, (immutable_data, mut melee_attacks): Self::SystemData) { + fn run(&mut self, (read_data, mut melee_attacks): Self::SystemData) { let start_time = std::time::Instant::now(); span!(_guard, "run", "melee::Sys::run"); - let mut server_emitter = immutable_data.server_bus.emitter(); + let mut server_emitter = read_data.server_bus.emitter(); // Attacks for (attacker, uid, pos, ori, melee_attack, body) in ( - &immutable_data.entities, - &immutable_data.uids, - &immutable_data.positions, - &immutable_data.orientations, + &read_data.entities, + &read_data.uids, + &read_data.positions, + &read_data.orientations, &mut melee_attacks, - &immutable_data.bodies, + &read_data.bodies, ) .join() { @@ -60,10 +60,10 @@ impl<'a> System<'a> for Sys { // Go through all other entities for (target, pos_b, health_b, body_b) in ( - &immutable_data.entities, - &immutable_data.positions, - &immutable_data.healths, - &immutable_data.bodies, + &read_data.entities, + &read_data.positions, + &read_data.healths, + &read_data.bodies, ) .join() { @@ -75,13 +75,13 @@ impl<'a> System<'a> for Sys { let ori2 = Vec2::from(look_dir); // Scales - let scale = immutable_data.scales.get(attacker).map_or(1.0, |s| s.0); - let scale_b = immutable_data.scales.get(target).map_or(1.0, |s| s.0); + let scale = read_data.scales.get(attacker).map_or(1.0, |s| s.0); + let scale_b = read_data.scales.get(target).map_or(1.0, |s| s.0); let rad = body.radius() * scale; let rad_b = body_b.radius() * scale_b; // Check if entity is dodging - let is_dodge = immutable_data + let is_dodge = read_data .char_states .get(target) .map_or(false, |c_s| c_s.is_melee_dodge()); @@ -94,10 +94,10 @@ impl<'a> System<'a> for Sys { && ori2.angle_between(pos_b2 - pos2) < melee_attack.max_angle + (rad_b / pos2.distance(pos_b2)).atan() { // See if entities are in the same group - let same_group = immutable_data + let same_group = read_data .groups .get(attacker) - .map(|group_a| Some(group_a) == immutable_data.groups.get(target)) + .map(|group_a| Some(group_a) == read_data.groups.get(target)) .unwrap_or(false); let target_group = if same_group { @@ -111,14 +111,14 @@ impl<'a> System<'a> for Sys { let attacker_info = Some(AttackerInfo { entity: attacker, uid: *uid, - energy: immutable_data.energies.get(attacker), + energy: read_data.energies.get(attacker), }); melee_attack.attack.apply_attack( target_group, attacker_info, target, - immutable_data.inventories.get(target), + read_data.inventories.get(target), dir, is_dodge, 1.0, @@ -129,7 +129,7 @@ impl<'a> System<'a> for Sys { } } } - immutable_data.metrics.melee_ns.store( + read_data.metrics.melee_ns.store( start_time.elapsed().as_nanos() as u64, std::sync::atomic::Ordering::Relaxed, ); diff --git a/common/sys/src/projectile.rs b/common/sys/src/projectile.rs index 78941e51ca..fa7dfa4476 100644 --- a/common/sys/src/projectile.rs +++ b/common/sys/src/projectile.rs @@ -18,7 +18,7 @@ use specs::{ use std::time::Duration; #[derive(SystemData)] -pub struct ImmutableData<'a> { +pub struct ReadData<'a> { entities: Entities<'a>, dt: Read<'a, DeltaTime>, uid_allocator: Read<'a, UidAllocator>, @@ -36,21 +36,21 @@ pub struct ImmutableData<'a> { pub struct Sys; impl<'a> System<'a> for Sys { type SystemData = ( - ImmutableData<'a>, + ReadData<'a>, WriteStorage<'a, Ori>, WriteStorage<'a, Projectile>, ); - fn run(&mut self, (immutable_data, mut orientations, mut projectiles): Self::SystemData) { + fn run(&mut self, (read_data, mut orientations, mut projectiles): Self::SystemData) { let start_time = std::time::Instant::now(); span!(_guard, "run", "projectile::Sys::run"); - let mut server_emitter = immutable_data.server_bus.emitter(); + let mut server_emitter = read_data.server_bus.emitter(); // Attacks 'projectile_loop: for (entity, pos, physics, ori, mut projectile) in ( - &immutable_data.entities, - &immutable_data.positions, - &immutable_data.physics_states, + &read_data.entities, + &read_data.positions, + &read_data.physics_states, &mut orientations, &mut projectiles, ) @@ -64,12 +64,12 @@ impl<'a> System<'a> for Sys { // Note: somewhat inefficient since we do the lookup for every touching // entity, but if we pull this out of the loop we would want to do it only // if there is at least one touching entity - .and_then(|uid| immutable_data.uid_allocator.retrieve_entity_internal(uid.into())) - .and_then(|e| immutable_data.groups.get(e)) + .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())) + .and_then(|e| read_data.groups.get(e)) .map_or(false, |owner_group| - Some(owner_group) == immutable_data.uid_allocator + Some(owner_group) == read_data.uid_allocator .retrieve_entity_internal(other.into()) - .and_then(|e| immutable_data.groups.get(e)) + .and_then(|e| read_data.groups.get(e)) ); let target_group = if same_group { @@ -93,14 +93,12 @@ impl<'a> System<'a> for Sys { for effect in projectile.hit_entity.drain(..) { match effect { projectile::Effect::Attack(attack) => { - if let Some(target_entity) = immutable_data + if let Some(target_entity) = read_data .uid_allocator .retrieve_entity_internal(other.into()) { let owner_entity = projectile.owner.and_then(|u| { - immutable_data - .uid_allocator - .retrieve_entity_internal(u.into()) + read_data.uid_allocator.retrieve_entity_internal(u.into()) }); let attacker_info = @@ -108,7 +106,7 @@ impl<'a> System<'a> for Sys { AttackerInfo { entity, uid, - energy: immutable_data.energies.get(entity), + energy: read_data.energies.get(entity), } }); @@ -116,7 +114,7 @@ impl<'a> System<'a> for Sys { target_group, attacker_info, target_entity, - immutable_data.inventories.get(target_entity), + read_data.inventories.get(target_entity), ori.look_dir(), false, 1.0, @@ -182,7 +180,7 @@ impl<'a> System<'a> for Sys { if projectile_vanished { continue 'projectile_loop; } - } else if let Some(dir) = immutable_data + } else if let Some(dir) = read_data .velocities .get(entity) .and_then(|vel| Dir::from_unnormalized(vel.0)) @@ -198,10 +196,10 @@ impl<'a> System<'a> for Sys { } projectile.time_left = projectile .time_left - .checked_sub(Duration::from_secs_f32(immutable_data.dt.0)) + .checked_sub(Duration::from_secs_f32(read_data.dt.0)) .unwrap_or_default(); } - immutable_data.metrics.projectile_ns.store( + read_data.metrics.projectile_ns.store( start_time.elapsed().as_nanos() as u64, std::sync::atomic::Ordering::Relaxed, ); diff --git a/common/sys/src/shockwave.rs b/common/sys/src/shockwave.rs index d1e88eb9a6..0085125f75 100644 --- a/common/sys/src/shockwave.rs +++ b/common/sys/src/shockwave.rs @@ -17,7 +17,7 @@ use specs::{ use vek::*; #[derive(SystemData)] -pub struct ImmutableData<'a> { +pub struct ReadData<'a> { entities: Entities<'a>, server_bus: Read<'a, EventBus>, time: Read<'a, Time>, @@ -41,22 +41,22 @@ pub struct ImmutableData<'a> { pub struct Sys; impl<'a> System<'a> for Sys { type SystemData = ( - ImmutableData<'a>, + ReadData<'a>, WriteStorage<'a, Shockwave>, WriteStorage<'a, ShockwaveHitEntities>, ); - fn run(&mut self, (immutable_data, mut shockwaves, mut shockwave_hit_lists): Self::SystemData) { - let mut server_emitter = immutable_data.server_bus.emitter(); + fn run(&mut self, (read_data, mut shockwaves, mut shockwave_hit_lists): Self::SystemData) { + let mut server_emitter = read_data.server_bus.emitter(); - let time = immutable_data.time.0; - let dt = immutable_data.dt.0; + let time = read_data.time.0; + let dt = read_data.dt.0; // Shockwaves for (entity, pos, ori, shockwave, shockwave_hit_list) in ( - &immutable_data.entities, - &immutable_data.positions, - &immutable_data.orientations, + &read_data.entities, + &read_data.positions, + &read_data.orientations, &shockwaves, &mut shockwave_hit_lists, ) @@ -99,24 +99,22 @@ impl<'a> System<'a> for Sys { end: frame_end_dist, }; - let shockwave_owner = shockwave.owner.and_then(|uid| { - immutable_data - .uid_allocator - .retrieve_entity_internal(uid.into()) - }); + let shockwave_owner = shockwave + .owner + .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())); // Group to ignore collisions with // Might make this more nuanced if shockwaves are used for non damage effects - let group = shockwave_owner.and_then(|e| immutable_data.groups.get(e)); + let group = shockwave_owner.and_then(|e| read_data.groups.get(e)); // Go through all other effectable entities for (target, uid_b, pos_b, health_b, body_b, physics_state_b) in ( - &immutable_data.entities, - &immutable_data.uids, - &immutable_data.positions, - &immutable_data.healths, - &immutable_data.bodies, - &immutable_data.physics_states, + &read_data.entities, + &read_data.uids, + &read_data.positions, + &read_data.healths, + &read_data.bodies, + &read_data.physics_states, ) .join() { @@ -131,13 +129,10 @@ impl<'a> System<'a> for Sys { // 2D versions let pos_b2 = pos_b.0.xy(); - let last_pos_b2_maybe = immutable_data - .last_positions - .get(target) - .map(|p| (p.0).0.xy()); + let last_pos_b2_maybe = read_data.last_positions.get(target).map(|p| (p.0).0.xy()); // Scales - let scale_b = immutable_data.scales.get(target).map_or(1.0, |s| s.0); + let scale_b = read_data.scales.get(target).map_or(1.0, |s| s.0); let rad_b = body_b.radius() * scale_b; // Angle checks @@ -146,7 +141,7 @@ impl<'a> System<'a> for Sys { // See if entities are in the same group let same_group = group - .map(|group_a| Some(group_a) == immutable_data.groups.get(target)) + .map(|group_a| Some(group_a) == read_data.groups.get(target)) .unwrap_or(Some(*uid_b) == shockwave.owner); let target_group = if same_group { @@ -178,14 +173,14 @@ impl<'a> System<'a> for Sys { .map(|(entity, uid)| AttackerInfo { entity, uid, - energy: immutable_data.energies.get(entity), + energy: read_data.energies.get(entity), }); shockwave.properties.attack.apply_attack( target_group, attacker_info, target, - immutable_data.inventories.get(target), + read_data.inventories.get(target), dir, false, 1.0, diff --git a/common/sys/src/stats.rs b/common/sys/src/stats.rs index 840e0f742b..51f85e6184 100644 --- a/common/sys/src/stats.rs +++ b/common/sys/src/stats.rs @@ -22,7 +22,7 @@ const ENERGY_REGEN_ACCEL: f32 = 10.0; const POISE_REGEN_ACCEL: f32 = 2.0; #[derive(SystemData)] -pub struct ImmutableData<'a> { +pub struct ReadData<'a> { entities: Entities<'a>, dt: Read<'a, DeltaTime>, server_bus: Read<'a, EventBus>, @@ -38,7 +38,7 @@ pub struct Sys; impl<'a> System<'a> for Sys { #[allow(clippy::type_complexity)] type SystemData = ( - ImmutableData<'a>, + ReadData<'a>, WriteStorage<'a, Stats>, WriteStorage<'a, Health>, WriteStorage<'a, Poise>, @@ -49,7 +49,7 @@ impl<'a> System<'a> for Sys { fn run( &mut self, ( - immutable_data, + read_data, mut stats, mut healths, mut poises, @@ -59,8 +59,8 @@ impl<'a> System<'a> for Sys { ) { let start_time = std::time::Instant::now(); span!(_guard, "run", "stats::Sys::run"); - let mut server_event_emitter = immutable_data.server_bus.emitter(); - let dt = immutable_data.dt.0; + let mut server_event_emitter = read_data.server_bus.emitter(); + let dt = read_data.dt.0; // Increment last change timer healths.set_event_emission(false); // avoid unnecessary syncing @@ -76,11 +76,11 @@ impl<'a> System<'a> for Sys { // Update stats for (entity, uid, mut stats, mut health, pos) in ( - &immutable_data.entities, - &immutable_data.uids, + &read_data.entities, + &read_data.uids, &mut stats.restrict_mut(), &mut healths.restrict_mut(), - &immutable_data.positions, + &read_data.positions, ) .join() { @@ -129,7 +129,7 @@ impl<'a> System<'a> for Sys { &mut stats.restrict_mut(), &mut healths.restrict_mut(), &mut energies.restrict_mut(), - &immutable_data.bodies, + &read_data.bodies, ) .join() { @@ -161,7 +161,7 @@ impl<'a> System<'a> for Sys { // Update energies and poises for (character_state, mut energy, mut poise) in ( - &immutable_data.char_states, + &read_data.char_states, &mut energies.restrict_mut(), &mut poises.restrict_mut(), ) @@ -256,7 +256,7 @@ impl<'a> System<'a> for Sys { } } - immutable_data.metrics.stats_ns.store( + read_data.metrics.stats_ns.store( start_time.elapsed().as_nanos() as u64, std::sync::atomic::Ordering::Relaxed, );