smooth out engine volume, fixing audio glitches
This commit is contained in:
parent
65f57cbccb
commit
a1c4fbb821
|
@ -152,7 +152,7 @@ pub struct Engine {
|
||||||
pub reaction_wheels: f32,
|
pub reaction_wheels: f32,
|
||||||
pub engine_type: EngineType,
|
pub engine_type: EngineType,
|
||||||
pub warmup_seconds: f32,
|
pub warmup_seconds: f32,
|
||||||
pub current_warmup: f32,
|
pub current_warmup: f32, // between 0.0 and 1.0
|
||||||
}
|
}
|
||||||
impl Default for Engine {
|
impl Default for Engine {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
|
|
@ -79,6 +79,7 @@ pub fn setup(
|
||||||
source: asset_server.load(ASSET_THRUSTER),
|
source: asset_server.load(ASSET_THRUSTER),
|
||||||
settings: PlaybackSettings {
|
settings: PlaybackSettings {
|
||||||
mode: PlaybackMode::Loop,
|
mode: PlaybackMode::Loop,
|
||||||
|
volume: Volume::new(0.0),
|
||||||
paused: true,
|
paused: true,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
@ -90,6 +91,7 @@ pub fn setup(
|
||||||
source: asset_server.load(ASSET_ROCKET),
|
source: asset_server.load(ASSET_ROCKET),
|
||||||
settings: PlaybackSettings {
|
settings: PlaybackSettings {
|
||||||
mode: PlaybackMode::Loop,
|
mode: PlaybackMode::Loop,
|
||||||
|
volume: Volume::new(0.0),
|
||||||
paused: true,
|
paused: true,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
@ -101,6 +103,7 @@ pub fn setup(
|
||||||
source: asset_server.load(ASSET_ION),
|
source: asset_server.load(ASSET_ION),
|
||||||
settings: PlaybackSettings {
|
settings: PlaybackSettings {
|
||||||
mode: PlaybackMode::Loop,
|
mode: PlaybackMode::Loop,
|
||||||
|
volume: Volume::new(0.0),
|
||||||
paused: true,
|
paused: true,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
|
|
@ -350,25 +350,39 @@ pub fn apply_input_to_player(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Ok(sink) = thruster_sound_controller.get_single() {
|
let sinks = vec![
|
||||||
if play_thruster_sound && !settings.mute_sfx && engine.engine_type == actor::EngineType::Monopropellant {
|
(1.2, actor::EngineType::Monopropellant, thruster_sound_controller.get_single()),
|
||||||
sink.play()
|
(1.0, actor::EngineType::Rocket, rocket_sound_controller.get_single()),
|
||||||
|
(1.4, actor::EngineType::Ion, ion_sound_controller.get_single()),
|
||||||
|
];
|
||||||
|
let seconds_to_max_vol = 0.05;
|
||||||
|
let seconds_to_min_vol = 0.05;
|
||||||
|
for sink_data in sinks {
|
||||||
|
if let (vol_boost, engine_type, Ok(sink)) = sink_data {
|
||||||
|
if settings.mute_sfx {
|
||||||
|
sink.pause();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let volume = sink.volume();
|
||||||
|
if engine.engine_type == engine_type {
|
||||||
|
if play_thruster_sound {
|
||||||
|
sink.play();
|
||||||
|
if volume < 1.0 {
|
||||||
|
let maxvol = vol_boost;
|
||||||
|
//let maxvol = engine.current_warmup * vol_boost;
|
||||||
|
sink.set_volume((volume + dt / seconds_to_max_vol).clamp(0.0, maxvol));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sink.pause()
|
sink.set_volume((volume - dt / seconds_to_min_vol).clamp(0.0, 1.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Ok(sink) = rocket_sound_controller.get_single() {
|
else if volume > 0.0 {
|
||||||
if play_thruster_sound && !settings.mute_sfx && engine.engine_type == actor::EngineType::Rocket {
|
sink.set_volume((volume - dt / seconds_to_min_vol).clamp(0.0, 1.0));
|
||||||
sink.play()
|
}
|
||||||
} else {
|
if volume < 0.0001 {
|
||||||
sink.pause()
|
sink.pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Ok(sink) = ion_sound_controller.get_single() {
|
|
||||||
if play_thruster_sound && !settings.mute_sfx && engine.engine_type == actor::EngineType::Ion {
|
|
||||||
sink.play()
|
|
||||||
} else {
|
|
||||||
sink.pause()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue