Correct the usage of owners in sound emissions

This commit is contained in:
holychowders 2021-05-18 20:26:48 -07:00 committed by Avi Weinstock
parent 9828043a84
commit cf25955eb3
3 changed files with 15 additions and 13 deletions

View File

@ -91,10 +91,14 @@ impl<'a> System<'a> for Sys {
};
let end_time = creation_time + beam_segment.duration.as_secs_f64();
let beam_owner = beam_segment
.owner
.and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into()));
let mut rng = thread_rng();
if rng.gen_bool(0.005) {
server_events.push(ServerEvent::Sound {
sound: Sound::new(SoundKind::Beam, pos.0, 7.0, time, Some(entity)),
sound: Sound::new(SoundKind::Beam, pos.0, 7.0, time, beam_owner),
});
}
@ -119,10 +123,6 @@ 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| 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| read_data.groups.get(e));

View File

@ -72,6 +72,10 @@ impl<'a> System<'a> for Sys {
)
.join()
{
let projectile_owner = projectile
.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 {
@ -89,12 +93,10 @@ impl<'a> System<'a> for Sys {
// Hit entity
for other in physics.touch_entities.iter().copied() {
let same_group = projectile
.owner
let same_group = projectile_owner
// 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| 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) == read_data.uid_allocator

View File

@ -85,10 +85,14 @@ impl<'a> System<'a> for Sys {
let end_time = creation_time + shockwave.duration.as_secs_f64();
let shockwave_owner = shockwave
.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, 16.0, time, Some(entity)),
sound: Sound::new(SoundKind::Shockwave, pos.0, 16.0, time, shockwave_owner),
});
}
@ -120,10 +124,6 @@ impl<'a> System<'a> for Sys {
end: frame_end_dist,
};
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| read_data.groups.get(e));