Sounds: layered synthesis, far variants, delay by the speed of sound
Rockets roar and crackle instead of whistling; blasts are a crack, a falling sub-bass boom and rolling echoes instead of noise; interceptors get their own flight sound. Far blasts, launches and shots play muffled variants, late by their distance at 343 m/s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -35,7 +35,15 @@
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:drone_rocket",
|
||||
"attenuation_distance": 420
|
||||
"attenuation_distance": 450
|
||||
}
|
||||
]
|
||||
},
|
||||
"missile.flight": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:missile_flight",
|
||||
"attenuation_distance": 380
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -55,11 +63,27 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"boom.sonic_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:boom_sonic_far",
|
||||
"attenuation_distance": 1440
|
||||
}
|
||||
]
|
||||
},
|
||||
"launch.patriot": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_patriot",
|
||||
"attenuation_distance": 600
|
||||
"attenuation_distance": 650
|
||||
}
|
||||
]
|
||||
},
|
||||
"launch.patriot_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_patriot_far",
|
||||
"attenuation_distance": 1040
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -67,7 +91,15 @@
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_s400_eject",
|
||||
"attenuation_distance": 350
|
||||
"attenuation_distance": 400
|
||||
}
|
||||
]
|
||||
},
|
||||
"launch.s400_eject_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_s400_eject_far",
|
||||
"attenuation_distance": 640
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -75,7 +107,15 @@
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_s400",
|
||||
"attenuation_distance": 800
|
||||
"attenuation_distance": 900
|
||||
}
|
||||
]
|
||||
},
|
||||
"launch.s400_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_s400_far",
|
||||
"attenuation_distance": 1440
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -83,7 +123,15 @@
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_s500_eject",
|
||||
"attenuation_distance": 450
|
||||
"attenuation_distance": 500
|
||||
}
|
||||
]
|
||||
},
|
||||
"launch.s500_eject_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_s500_eject_far",
|
||||
"attenuation_distance": 800
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -91,7 +139,15 @@
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_s500",
|
||||
"attenuation_distance": 1000
|
||||
"attenuation_distance": 1100
|
||||
}
|
||||
]
|
||||
},
|
||||
"launch.s500_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_s500_far",
|
||||
"attenuation_distance": 1760
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -99,7 +155,15 @@
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_pantsir",
|
||||
"attenuation_distance": 450
|
||||
"attenuation_distance": 500
|
||||
}
|
||||
]
|
||||
},
|
||||
"launch.pantsir_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:launch_pantsir_far",
|
||||
"attenuation_distance": 800
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -107,7 +171,15 @@
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:gun_gepard",
|
||||
"attenuation_distance": 380
|
||||
"attenuation_distance": 400
|
||||
}
|
||||
]
|
||||
},
|
||||
"gun.gepard_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:gun_gepard_far",
|
||||
"attenuation_distance": 640
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -115,7 +187,15 @@
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:gun_pantsir",
|
||||
"attenuation_distance": 350
|
||||
"attenuation_distance": 380
|
||||
}
|
||||
]
|
||||
},
|
||||
"gun.pantsir_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:gun_pantsir_far",
|
||||
"attenuation_distance": 608
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -123,7 +203,15 @@
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:blast_big",
|
||||
"attenuation_distance": 900
|
||||
"attenuation_distance": 1000
|
||||
}
|
||||
]
|
||||
},
|
||||
"blast.big_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:blast_big_far",
|
||||
"attenuation_distance": 1600
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -131,7 +219,15 @@
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:blast_medium",
|
||||
"attenuation_distance": 600
|
||||
"attenuation_distance": 700
|
||||
}
|
||||
]
|
||||
},
|
||||
"blast.medium_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:blast_medium_far",
|
||||
"attenuation_distance": 1120
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -139,7 +235,15 @@
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:blast_air",
|
||||
"attenuation_distance": 700
|
||||
"attenuation_distance": 800
|
||||
}
|
||||
]
|
||||
},
|
||||
"blast.air_far": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "airdef:blast_air_far",
|
||||
"attenuation_distance": 1280
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+40
-1
@@ -47,6 +47,20 @@ struct AirDef {
|
||||
monitor_shown: bool,
|
||||
/// The menu's page while it is open.
|
||||
menu: Option<Page>,
|
||||
/// Where the player is, for the sounds' delay and far variants.
|
||||
listener: DVec3,
|
||||
/// Sounds on their way to the player at the speed of sound: (tick, event, at, pitch).
|
||||
pending: Vec<(u64, String, DVec3, f32)>,
|
||||
}
|
||||
|
||||
/// Blocks a tick the sound travels (343 m/s).
|
||||
const SOUND_SPEED: f64 = 17.15;
|
||||
/// Past this the far variant plays: muffled, more rolling echo.
|
||||
const FAR: f64 = 140.0;
|
||||
|
||||
/// Impulsive sounds (blasts, launches, shots, shock waves) come late from afar and have far variants.
|
||||
fn travels(event: &str) -> bool {
|
||||
["airdef:blast", "airdef:launch", "airdef:gun", "airdef:boom"].iter().any(|p| event.starts_with(p))
|
||||
}
|
||||
|
||||
/// A page of the menu.
|
||||
@@ -238,8 +252,30 @@ impl AirDef {
|
||||
.collect();
|
||||
render::spawn_particles(&spawns);
|
||||
}
|
||||
let now = self.sim.tick;
|
||||
for (event, at, volume, pitch) in out.sounds {
|
||||
render::play_sound(event, at.x, at.y, at.z, volume, pitch);
|
||||
let dist = at.distance(self.listener);
|
||||
if travels(event) {
|
||||
// Seen first, heard later; from afar muffled.
|
||||
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);
|
||||
} else if self.pending.len() < 256 {
|
||||
self.pending.push((now + delay, name, at, pitch));
|
||||
}
|
||||
} else {
|
||||
render::play_sound(event, at.x, at.y, at.z, volume, pitch);
|
||||
}
|
||||
}
|
||||
let mut i = 0;
|
||||
while i < self.pending.len() {
|
||||
if self.pending[i].0 <= now {
|
||||
let (_, name, at, pitch) = self.pending.swap_remove(i);
|
||||
render::play_sound(&name, at.x, at.y, at.z, 1.0, pitch);
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
if !out.commands.is_empty() {
|
||||
command::run_quiet(&out.commands);
|
||||
@@ -419,6 +455,8 @@ impl Mod for AirDef {
|
||||
monitor: None,
|
||||
monitor_shown: false,
|
||||
menu: None,
|
||||
listener: DVec3::ZERO,
|
||||
pending: Vec::new(),
|
||||
};
|
||||
let _ = input::register_key("menu", "Меню AirDef", "key.keyboard.n");
|
||||
let _ = input::register_key("monitor", "Монитор ПВО: следующий комплекс", "key.keyboard.k");
|
||||
@@ -442,6 +480,7 @@ impl Mod for AirDef {
|
||||
let now = self.sim.tick;
|
||||
self.ground.answer(render::ground(), now);
|
||||
let mut out = Out::default();
|
||||
self.listener = DVec3::new(p.x, p.y + 1.6, p.z);
|
||||
self.sim.step(&mut self.ground, Some(DVec3::new(p.x, p.y, p.z)), &mut out);
|
||||
let wanted = self.ground.take_wanted();
|
||||
if !wanted.is_empty() {
|
||||
|
||||
@@ -1655,12 +1655,12 @@ impl Sim {
|
||||
if lit {
|
||||
if (m.age - spec.cold) % 46 == 1 {
|
||||
let pitch = match m.kind {
|
||||
MissileKind::Pac3 => 1.15,
|
||||
MissileKind::M57e6 => 1.45,
|
||||
MissileKind::M48n6 => 0.9,
|
||||
MissileKind::M77n6 => 0.75,
|
||||
MissileKind::Pac3 => 1.0,
|
||||
MissileKind::M57e6 => 1.12,
|
||||
MissileKind::M48n6 => 0.88,
|
||||
MissileKind::M77n6 => 0.8,
|
||||
};
|
||||
out.sound("airdef:drone.rocket", m.pos, 1.0, pitch);
|
||||
out.sound("airdef:missile.flight", m.pos, 1.0, pitch);
|
||||
}
|
||||
let back = m.pos - new * 1.4 * spec.scale;
|
||||
out.particles("minecraft:flame", back, 0.05, -new * 0.1, 0.01, 2);
|
||||
|
||||
Reference in New Issue
Block a user