From a96e9982c7dd45d33a06592e6bf679dd807e27cf Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 27 Nov 2020 12:43:47 -0500 Subject: [PATCH] Stop unbounded wind volume when zooming out, make campfires quieter --- voxygen/src/audio/ambient.rs | 47 ++++++++++--------- .../audio/sfx/event_mapper/campfire/mod.rs | 3 +- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/voxygen/src/audio/ambient.rs b/voxygen/src/audio/ambient.rs index 0742bb5278..15d336044c 100644 --- a/voxygen/src/audio/ambient.rs +++ b/voxygen/src/audio/ambient.rs @@ -69,31 +69,34 @@ impl AmbientMgr { // non-positional ambient sound in the game. Others can be added // as seen fit. - // Wind volume increases with altitude - let alt_multiplier = (cam_pos.z / 1200.0).abs(); + let target_volume = { + // Wind volume increases with altitude + let alt_multiplier = (cam_pos.z / 1200.0).abs(); - // Tree density factors into wind volume. The more trees, - // the lower wind volume. The trees make more of an impact - // the closer the camera is to the ground. - self.tree_multiplier = - ((1.0 - tree_density) + ((cam_pos.z - terrain_alt) / 150.0).powi(2)).min(1.0); + // Tree density factors into wind volume. The more trees, + // the lower wind volume. The trees make more of an impact + // the closer the camera is to the ground. + self.tree_multiplier = ((1.0 - tree_density) + + ((cam_pos.z - terrain_alt).abs() / 150.0).powi(2)) + .min(1.0); - let mut volume_multiplier = alt_multiplier * self.tree_multiplier; + let mut volume_multiplier = alt_multiplier * self.tree_multiplier; - // Checks if the camera is underwater to stop ambient sounds - if state - .terrain() - .get((cam_pos).map(|e| e.floor() as i32)) - .map(|b| b.is_liquid()) - .unwrap_or(false) - { - volume_multiplier *= 0.1; - } - if cam_pos.z < terrain_alt - 10.0 { - volume_multiplier = 0.0; - } + // Checks if the camera is underwater to stop ambient sounds + if state + .terrain() + .get((cam_pos).map(|e| e.floor() as i32)) + .map(|b| b.is_liquid()) + .unwrap_or(false) + { + volume_multiplier *= 0.1; + } + if cam_pos.z < terrain_alt - 10.0 { + volume_multiplier = 0.0; + } - let target_volume = volume_multiplier.clamped(0.0, 1.0); + volume_multiplier.clamped(0.0, 1.0) + }; // Transitions the ambient sounds (more) smoothly self.volume = audio.get_ambient_volume(); @@ -113,7 +116,7 @@ impl AmbientMgr { self.began_playing = Instant::now(); self.next_track_change = track.length; - audio.play_ambient(AmbientChannelTag::Wind, &track.path, volume_multiplier); + audio.play_ambient(AmbientChannelTag::Wind, &track.path, target_volume); } } } diff --git a/voxygen/src/audio/sfx/event_mapper/campfire/mod.rs b/voxygen/src/audio/sfx/event_mapper/campfire/mod.rs index 26773bd387..bfa11e09bc 100644 --- a/voxygen/src/audio/sfx/event_mapper/campfire/mod.rs +++ b/voxygen/src/audio/sfx/event_mapper/campfire/mod.rs @@ -72,7 +72,8 @@ impl EventMapper for CampfireEventMapper { .map(|b| b.is_liquid()) .unwrap_or(false); let sfx_trigger_item = triggers.get_key_value(&mapped_event); - audio.emit_sfx(sfx_trigger_item, pos.0, None, underwater); + const CAMPFIRE_VOLUME: f32 = 0.1; + audio.emit_sfx(sfx_trigger_item, pos.0, Some(CAMPFIRE_VOLUME), underwater); internal_state.time = Instant::now(); }