Acoustics stage 1: mod plays near sounds when the engine muffles, band-energy check tool (#96, fork patch 39)
build / mod (push) Successful in 3m52s
build / mod (push) Successful in 3m52s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -192,6 +192,8 @@ struct PendingSound {
|
||||
const SOUND_SPEED: f64 = 17.15;
|
||||
/// Past this the far variant plays: muffled, more rolling echo.
|
||||
const FAR: f64 = 140.0;
|
||||
/// The same when the game's acoustics muffle (its tracing reaches 512 blocks).
|
||||
const ACOUSTIC_FAR: f64 = 480.0;
|
||||
|
||||
/// Impulsive sounds (blasts, launches, shots, shock waves) come late from afar and have far variants.
|
||||
fn travels(event: &str) -> bool {
|
||||
@@ -747,13 +749,16 @@ impl AirDef {
|
||||
let now = self.sim.tick;
|
||||
// Blasts play layered (cinema.rs), the nearest ones in full.
|
||||
let mut booms: Vec<(f64, usize, DVec3, f32, f32)> = Vec::new();
|
||||
// The game muffles by walls and distance itself (#96): the near variants play out to the
|
||||
// reach of its tracing, so nothing is muffled twice; past it the far ones still do.
|
||||
let far = if render::acoustics() { ACOUSTIC_FAR } else { FAR };
|
||||
for (event, at, volume, pitch) in out.sounds {
|
||||
let dist = at.distance(self.listener);
|
||||
if let Some(power) = cinema::blast_power(event) {
|
||||
booms.push((dist, power, at, volume, pitch));
|
||||
} else if travels(event) {
|
||||
// Seen first, heard later; from afar muffled.
|
||||
let name = if dist > FAR { format!("{event}_far") } else { event.to_string() };
|
||||
let name = if dist > far { format!("{event}_far") } else { event.to_string() };
|
||||
let delay = (dist / SOUND_SPEED) as u64;
|
||||
if delay == 0 {
|
||||
render::play_sound(&name, at.x, at.y, at.z, volume, pitch);
|
||||
@@ -766,7 +771,7 @@ impl AirDef {
|
||||
}
|
||||
booms.sort_by(|a, b| a.0.total_cmp(&b.0));
|
||||
for (rank, (dist, power, at, volume, pitch)) in booms.into_iter().enumerate() {
|
||||
for l in cinema::layers(power, dist, FAR, volume, pitch, rank) {
|
||||
for l in cinema::layers(power, dist, far, volume, pitch, rank) {
|
||||
// Seen first, heard later: each voice after the sound has travelled.
|
||||
let delay = (dist / SOUND_SPEED) as u64 + l.delay;
|
||||
if delay == 0 {
|
||||
|
||||
Reference in New Issue
Block a user