Stop unbounded wind volume when zooming out, make campfires quieter

This commit is contained in:
Imbris
2020-11-27 12:43:47 -05:00
parent d1a9264a99
commit a96e9982c7
2 changed files with 27 additions and 23 deletions

View File

@ -69,31 +69,34 @@ impl AmbientMgr {
// non-positional ambient sound in the game. Others can be added // non-positional ambient sound in the game. Others can be added
// as seen fit. // as seen fit.
// Wind volume increases with altitude let target_volume = {
let alt_multiplier = (cam_pos.z / 1200.0).abs(); // Wind volume increases with altitude
let alt_multiplier = (cam_pos.z / 1200.0).abs();
// Tree density factors into wind volume. The more trees, // Tree density factors into wind volume. The more trees,
// the lower wind volume. The trees make more of an impact // the lower wind volume. The trees make more of an impact
// the closer the camera is to the ground. // the closer the camera is to the ground.
self.tree_multiplier = self.tree_multiplier = ((1.0 - tree_density)
((1.0 - tree_density) + ((cam_pos.z - terrain_alt) / 150.0).powi(2)).min(1.0); + ((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 // Checks if the camera is underwater to stop ambient sounds
if state if state
.terrain() .terrain()
.get((cam_pos).map(|e| e.floor() as i32)) .get((cam_pos).map(|e| e.floor() as i32))
.map(|b| b.is_liquid()) .map(|b| b.is_liquid())
.unwrap_or(false) .unwrap_or(false)
{ {
volume_multiplier *= 0.1; volume_multiplier *= 0.1;
} }
if cam_pos.z < terrain_alt - 10.0 { if cam_pos.z < terrain_alt - 10.0 {
volume_multiplier = 0.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 // Transitions the ambient sounds (more) smoothly
self.volume = audio.get_ambient_volume(); self.volume = audio.get_ambient_volume();
@ -113,7 +116,7 @@ impl AmbientMgr {
self.began_playing = Instant::now(); self.began_playing = Instant::now();
self.next_track_change = track.length; self.next_track_change = track.length;
audio.play_ambient(AmbientChannelTag::Wind, &track.path, volume_multiplier); audio.play_ambient(AmbientChannelTag::Wind, &track.path, target_volume);
} }
} }
} }

View File

@ -72,7 +72,8 @@ impl EventMapper for CampfireEventMapper {
.map(|b| b.is_liquid()) .map(|b| b.is_liquid())
.unwrap_or(false); .unwrap_or(false);
let sfx_trigger_item = triggers.get_key_value(&mapped_event); 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(); internal_state.time = Instant::now();
} }