mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Reduce rand::thread_rng
calls, document MeleeConstructor scaled
field more, remove extra stances.get() in hud/mod.rs
This commit is contained in:
parent
564530f5e2
commit
e20cf5f14f
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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<MeleeConstructorKind>,
|
||||
pub range: f32,
|
||||
pub angle: f32,
|
||||
|
@ -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));
|
||||
|
@ -66,6 +66,7 @@ impl<'a> System<'a> for Sys {
|
||||
fn run(_job: &mut Job<Self>, (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 {
|
||||
|
@ -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<Outcome>,
|
||||
server_emitter: &mut Emitter<ServerEvent>,
|
||||
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) => {
|
||||
|
@ -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);
|
||||
|
@ -980,6 +980,7 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
|
||||
*time,
|
||||
|e| emitter.emit(e),
|
||||
|o| outcomes_emitter.emit(o),
|
||||
&mut rng,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user