diff --git a/common/src/combat.rs b/common/src/combat.rs index 08f022aeb6..4f72e7ffa8 100644 --- a/common/src/combat.rs +++ b/common/src/combat.rs @@ -23,17 +23,16 @@ use crate::{ util::Dir, }; -#[cfg(not(target_arch = "wasm32"))] -use rand::{thread_rng, Rng}; - use serde::{Deserialize, Serialize}; use crate::{comp::Group, resources::Time}; #[cfg(not(target_arch = "wasm32"))] -use specs::{saveload::MarkerAllocator, Entity as EcsEntity, ReadStorage}; -#[cfg(not(target_arch = "wasm32"))] -use std::ops::{Mul, MulAssign}; -#[cfg(not(target_arch = "wasm32"))] use vek::*; +use { + rand::Rng, + specs::{saveload::MarkerAllocator, Entity as EcsEntity, ReadStorage}, + std::ops::{Mul, MulAssign}, + vek::*, +}; #[cfg(not(target_arch = "wasm32"))] #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] @@ -199,10 +198,10 @@ impl Attack { time: Time, mut emit: impl FnMut(ServerEvent), mut emit_outcome: impl FnMut(Outcome), + rng: &mut rand::rngs::ThreadRng, ) -> bool { // TODO: Maybe move this higher and pass it as argument into this function? let msm = &MaterialStatManifest::load().read(); - let mut rng = thread_rng(); let AttackOptions { target_dodging, diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index a97227defc..44a166a420 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -2792,6 +2792,9 @@ impl From<(&CharacterAbility, AbilityInfo, &JoinData<'_>)> for CharacterState { ability_info, }, timer: Duration::default(), + // TODO: is this supposed to match the change in `requirements_paid` to just check + // `on_ground.is_non()` instead of checking vertical speed? Or is difference + // intended? stage_section: if data.vel.0.z < -*vertical_speed || buildup_duration.is_none() { StageSection::Movement } else { diff --git a/common/src/comp/melee.rs b/common/src/comp/melee.rs index 4ad05321ec..6152e9e122 100644 --- a/common/src/comp/melee.rs +++ b/common/src/comp/melee.rs @@ -53,7 +53,9 @@ impl Component for Melee { #[serde(deny_unknown_fields)] pub struct MeleeConstructor { pub kind: MeleeConstructorKind, - // This multiplied by a fraction is added to what is specified in kind + /// This multiplied by a fraction is added to what is specified in `kind`. + /// + /// Note, that this must be the same variant as what is specified in `kind`. pub scaled: Option, pub range: f32, pub angle: f32, diff --git a/common/systems/src/beam.rs b/common/systems/src/beam.rs index 9025aba01b..e4d8f1ae8b 100644 --- a/common/systems/src/beam.rs +++ b/common/systems/src/beam.rs @@ -14,7 +14,7 @@ use common::{ GroupTarget, }; use common_ecs::{Job, Origin, ParMode, Phase, System}; -use rand::{thread_rng, Rng}; +use rand::Rng; use rayon::iter::ParallelIterator; use specs::{ saveload::MarkerAllocator, shred::ResourceId, Entities, Join, ParJoin, Read, ReadExpect, @@ -99,7 +99,9 @@ impl<'a> System<'a> for Sys { read_data.uid_allocator.retrieve_entity_internal(uid.into()) }); - let mut rng = thread_rng(); + // Note: rayon makes it difficult to hold onto a thread-local RNG, if grabbing + // this becomes a bottleneck we can look into alternatives. + let mut rng = rand::thread_rng(); if rng.gen_bool(0.005) { server_events.push(ServerEvent::Sound { sound: Sound::new(SoundKind::Beam, pos.0, 13.0, time), @@ -261,6 +263,7 @@ impl<'a> System<'a> for Sys { *read_data.time, |e| server_events.push(e), |o| outcomes.push(o), + &mut rng, ); add_hit_entities.push((beam_owner, *uid_b)); diff --git a/common/systems/src/melee.rs b/common/systems/src/melee.rs index b08576e145..077aa59d79 100644 --- a/common/systems/src/melee.rs +++ b/common/systems/src/melee.rs @@ -66,6 +66,7 @@ impl<'a> System<'a> for Sys { fn run(_job: &mut Job, (read_data, mut melee_attacks, outcomes): Self::SystemData) { let mut server_emitter = read_data.server_bus.emitter(); let mut outcomes_emitter = outcomes.emitter(); + let mut rng = rand::thread_rng(); // Attacks for (attacker, uid, pos, ori, melee_attack, body) in ( @@ -239,6 +240,7 @@ impl<'a> System<'a> for Sys { *read_data.time, |e| server_emitter.emit(e), |o| outcomes_emitter.emit(o), + &mut rng, ); if is_applied { diff --git a/common/systems/src/projectile.rs b/common/systems/src/projectile.rs index 2bf69a74e0..69b5cd5447 100644 --- a/common/systems/src/projectile.rs +++ b/common/systems/src/projectile.rs @@ -15,7 +15,7 @@ use common::{ use common::vol::ReadVol; use common_ecs::{Job, Origin, Phase, System}; -use rand::{thread_rng, Rng}; +use rand::Rng; use specs::{ saveload::MarkerAllocator, shred::ResourceId, Entities, Entity as EcsEntity, Join, Read, ReadExpect, ReadStorage, SystemData, World, WriteStorage, @@ -71,6 +71,7 @@ impl<'a> System<'a> for Sys { ) { let mut server_emitter = read_data.server_bus.emitter(); let mut outcomes_emitter = outcomes.emitter(); + let mut rng = rand::thread_rng(); // Attacks 'projectile_loop: for (entity, pos, physics, vel, mut projectile) in ( @@ -86,7 +87,6 @@ impl<'a> System<'a> for Sys { .owner .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())); - let mut rng = thread_rng(); if physics.on_surface().is_none() && rng.gen_bool(0.05) { server_emitter.emit(ServerEvent::Sound { sound: Sound::new(SoundKind::Projectile, pos.0, 4.0, read_data.time.0), @@ -175,6 +175,7 @@ impl<'a> System<'a> for Sys { &mut projectile_vanished, &mut outcomes_emitter, &mut server_emitter, + &mut rng, ); } @@ -263,6 +264,7 @@ fn dispatch_hit( projectile_vanished: &mut bool, outcomes_emitter: &mut Emitter, server_emitter: &mut Emitter, + rng: &mut rand::rngs::ThreadRng, ) { match projectile_info.effect { projectile::Effect::Attack(attack) => { @@ -358,6 +360,7 @@ fn dispatch_hit( *read_data.time, |e| server_emitter.emit(e), |o| outcomes_emitter.emit(o), + rng, ); }, projectile::Effect::Explode(e) => { diff --git a/common/systems/src/shockwave.rs b/common/systems/src/shockwave.rs index 7fffbd56df..408ed881bc 100644 --- a/common/systems/src/shockwave.rs +++ b/common/systems/src/shockwave.rs @@ -13,7 +13,7 @@ use common::{ GroupTarget, }; use common_ecs::{Job, Origin, Phase, System}; -use rand::{thread_rng, Rng}; +use rand::Rng; use specs::{ saveload::MarkerAllocator, shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, WriteStorage, @@ -67,6 +67,7 @@ impl<'a> System<'a> for Sys { ) { let mut server_emitter = read_data.server_bus.emitter(); let mut outcomes_emitter = outcomes.emitter(); + let mut rng = rand::thread_rng(); let time = read_data.time.0; let dt = read_data.dt.0; @@ -93,7 +94,6 @@ impl<'a> System<'a> for Sys { .owner .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())); - let mut rng = thread_rng(); if rng.gen_bool(0.05) { server_emitter.emit(ServerEvent::Sound { sound: Sound::new(SoundKind::Shockwave, pos.0, 40.0, time), @@ -253,6 +253,7 @@ impl<'a> System<'a> for Sys { *read_data.time, |e| server_emitter.emit(e), |o| outcomes_emitter.emit(o), + &mut rng, ); shockwave_hit_list.hit_entities.push(*uid_b); diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 7efa635355..6b448e9d84 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -980,6 +980,7 @@ pub fn handle_explosion(server: &Server, pos: Vec3, explosion: Explosion, o *time, |e| emitter.emit(e), |o| outcomes_emitter.emit(o), + &mut rng, ); } } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 375a8f0a73..b82221efd9 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -2987,7 +2987,8 @@ impl Hud { skillsets.get(entity), bodies.get(entity), ) { - let context = AbilityContext::from(stances.get(entity)); + let stance = stances.get(entity); + let context = AbilityContext::from(stance); match Skillbar::new( client, &info, @@ -3016,7 +3017,7 @@ impl Hud { context, combos.get(entity), char_states.get(entity), - stances.get(entity), + stance, ) .set(self.ids.skillbar, ui_widgets) {