Merge branch 'DaforLynx/last-minute-fixes' into 'master'

Minor audio code cleanup

See merge request veloren/veloren!3738
This commit is contained in:
Joshua Barretto 2022-12-31 23:50:38 +00:00
commit 7579b86dc1
5 changed files with 22 additions and 54 deletions

View File

@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Experience bar below the hotbar - Experience bar below the hotbar
- Bridges. - Bridges.
- Tool for exporting PNG images of all in-game models (`cargo img-export`) - Tool for exporting PNG images of all in-game models (`cargo img-export`)
- Calendar event soundtracks.
### Changed ### Changed

View File

@ -15,17 +15,12 @@ use music::MusicTransitionManifest;
use sfx::{SfxEvent, SfxTriggerItem}; use sfx::{SfxEvent, SfxTriggerItem};
use soundcache::load_ogg; use soundcache::load_ogg;
use std::time::Duration; use std::time::Duration;
use tracing::{debug, error, warn}; use tracing::{debug, error};
use common::assets::{AssetExt, AssetHandle}; use common::assets::{AssetExt, AssetHandle};
use rodio::{source::Source, OutputStream, OutputStreamHandle, StreamError}; use rodio::{source::Source, OutputStream, OutputStreamHandle, StreamError};
use vek::*; use vek::*;
/// Prevents sounds that are too low in volume from playing. This may marginally
/// improve performance in certain situations since less audio channels will be
/// used on average.
const MIN_HEARABLE_VOLUME: f32 = 0.003;
#[derive(Default, Clone)] #[derive(Default, Clone)]
pub struct Listener { pub struct Listener {
pos: Vec3<f32>, pos: Vec3<f32>,
@ -116,15 +111,6 @@ impl AudioFrontend {
/// Construct in `no-audio` mode for debugging /// Construct in `no-audio` mode for debugging
pub fn no_audio() -> Self { pub fn no_audio() -> Self {
let audio_manifest = "voxygen.audio.music_transition_manifest";
let mtm = MusicTransitionManifest::load_or_insert_with(audio_manifest, |err| {
warn!(
"Error loading MusicTransitionManifest {:?}: {:?}",
audio_manifest, err
);
MusicTransitionManifest::default()
});
Self { Self {
// The following is for the disabled device switcher // The following is for the disabled device switcher
//device: "".to_string(), //device: "".to_string(),
@ -142,7 +128,7 @@ impl AudioFrontend {
master_volume: 1.0, master_volume: 1.0,
music_spacing: 1.0, music_spacing: 1.0,
listener: Listener::default(), listener: Listener::default(),
mtm, mtm: AssetExt::load_expect("voxygen.audio.music_transition_manifest"),
} }
} }
@ -268,7 +254,7 @@ impl AudioFrontend {
) { ) {
if let Some(sfx_file) = Self::get_sfx_file(trigger_item) { if let Some(sfx_file) = Self::get_sfx_file(trigger_item) {
// Play sound in empty channel at given position // Play sound in empty channel at given position
if self.audio_stream.is_some() && volume.map_or(true, |v| v > MIN_HEARABLE_VOLUME) { if self.audio_stream.is_some() {
let sound = load_ogg(sfx_file).amplify(volume.unwrap_or(1.0)); let sound = load_ogg(sfx_file).amplify(volume.unwrap_or(1.0));
let listener = self.listener.clone(); let listener = self.listener.clone();
@ -302,7 +288,7 @@ impl AudioFrontend {
) { ) {
if let Some(sfx_file) = Self::get_sfx_file(trigger_item) { if let Some(sfx_file) = Self::get_sfx_file(trigger_item) {
// Play sound in empty channel at given position // Play sound in empty channel at given position
if self.audio_stream.is_some() && volume.map_or(true, |v| v > MIN_HEARABLE_VOLUME) { if self.audio_stream.is_some() {
let sound = load_ogg(sfx_file).amplify(volume.unwrap_or(1.0)); let sound = load_ogg(sfx_file).amplify(volume.unwrap_or(1.0));
let listener = self.listener.clone(); let listener = self.listener.clone();
@ -337,7 +323,7 @@ impl AudioFrontend {
) { ) {
if let Some(sfx_file) = Self::get_sfx_file(trigger_item) { if let Some(sfx_file) = Self::get_sfx_file(trigger_item) {
// Play sound in empty channel // Play sound in empty channel
if self.audio_stream.is_some() && volume.map_or(true, |v| v > MIN_HEARABLE_VOLUME) { if self.audio_stream.is_some() {
let sound = load_ogg(sfx_file).amplify(volume.unwrap_or(1.0)); let sound = load_ogg(sfx_file).amplify(volume.unwrap_or(1.0));
if let Some(channel) = self.get_ui_channel() { if let Some(channel) = self.get_ui_channel() {

View File

@ -207,9 +207,11 @@ impl MovementEventMapper {
} else { } else {
match underfoot_block_kind { match underfoot_block_kind {
BlockKind::Snow => SfxEvent::Run(BlockKind::Snow), BlockKind::Snow => SfxEvent::Run(BlockKind::Snow),
BlockKind::Rock | BlockKind::WeakRock | BlockKind::Ice => { BlockKind::Rock
SfxEvent::Run(BlockKind::Rock) | BlockKind::WeakRock
}, | BlockKind::GlowingRock
| BlockKind::GlowingWeakRock
| BlockKind::Ice => SfxEvent::Run(BlockKind::Rock),
BlockKind::Earth => SfxEvent::Run(BlockKind::Earth), BlockKind::Earth => SfxEvent::Run(BlockKind::Earth),
// BlockKind::Sand => SfxEvent::Run(BlockKind::Sand), // BlockKind::Sand => SfxEvent::Run(BlockKind::Sand),
BlockKind::Air => SfxEvent::Idle, BlockKind::Air => SfxEvent::Idle,
@ -237,7 +239,11 @@ impl MovementEventMapper {
} else if physics_state.on_ground.is_some() && vel.magnitude() > 0.1 { } else if physics_state.on_ground.is_some() && vel.magnitude() > 0.1 {
match underfoot_block_kind { match underfoot_block_kind {
BlockKind::Snow => SfxEvent::Run(BlockKind::Snow), BlockKind::Snow => SfxEvent::Run(BlockKind::Snow),
BlockKind::Rock | BlockKind::WeakRock => SfxEvent::Run(BlockKind::Rock), BlockKind::Rock
| BlockKind::WeakRock
| BlockKind::GlowingRock
| BlockKind::GlowingWeakRock
| BlockKind::Ice => SfxEvent::Run(BlockKind::Rock),
// BlockKind::Sand => SfxEvent::Run(BlockKind::Sand), // BlockKind::Sand => SfxEvent::Run(BlockKind::Sand),
BlockKind::Earth => SfxEvent::Run(BlockKind::Earth), BlockKind::Earth => SfxEvent::Run(BlockKind::Earth),
BlockKind::Air => SfxEvent::Idle, BlockKind::Air => SfxEvent::Idle,
@ -259,7 +265,11 @@ impl MovementEventMapper {
} else if physics_state.on_ground.is_some() && vel.magnitude() > 0.1 { } else if physics_state.on_ground.is_some() && vel.magnitude() > 0.1 {
match underfoot_block_kind { match underfoot_block_kind {
BlockKind::Snow => SfxEvent::QuadRun(BlockKind::Snow), BlockKind::Snow => SfxEvent::QuadRun(BlockKind::Snow),
BlockKind::Rock | BlockKind::WeakRock => SfxEvent::QuadRun(BlockKind::Rock), BlockKind::Rock
| BlockKind::WeakRock
| BlockKind::GlowingRock
| BlockKind::GlowingWeakRock
| BlockKind::Ice => SfxEvent::QuadRun(BlockKind::Rock),
// BlockKind::Sand => SfxEvent::QuadRun(BlockKind::Sand), // BlockKind::Sand => SfxEvent::QuadRun(BlockKind::Sand),
BlockKind::Earth => SfxEvent::QuadRun(BlockKind::Earth), BlockKind::Earth => SfxEvent::QuadRun(BlockKind::Earth),
BlockKind::Air => SfxEvent::Idle, BlockKind::Air => SfxEvent::Idle,

View File

@ -120,29 +120,6 @@ use vek::*;
/// player. /// player.
const SFX_DIST_LIMIT_SQR: f32 = 20000.0; const SFX_DIST_LIMIT_SQR: f32 = 20000.0;
pub struct SfxEventItem {
/// The SFX event that triggers this sound
pub sfx: SfxEvent,
/// The position at which the sound should play
pub pos: Option<Vec3<f32>>,
/// The volume to play the sound at
pub vol: Option<f32>,
}
impl SfxEventItem {
pub fn new(sfx: SfxEvent, pos: Option<Vec3<f32>>, vol: Option<f32>) -> Self {
Self { sfx, pos, vol }
}
pub fn at_player_position(sfx: SfxEvent) -> Self {
Self {
sfx,
pos: None,
vol: None,
}
}
}
#[derive(Clone, Debug, PartialEq, Deserialize, Hash, Eq)] #[derive(Clone, Debug, PartialEq, Deserialize, Hash, Eq)]
pub enum SfxEvent { pub enum SfxEvent {
Campfire, Campfire,
@ -169,8 +146,6 @@ pub enum SfxEvent {
CatchAir, CatchAir,
Jump, Jump,
Fall, Fall,
ExperienceGained,
LevelUp,
Attack(CharacterAbilityType, ToolKind), Attack(CharacterAbilityType, ToolKind),
Wield(ToolKind), Wield(ToolKind),
Unwield(ToolKind), Unwield(ToolKind),

View File

@ -1,8 +1,7 @@
pub mod comp; pub mod comp;
pub mod sys; pub mod sys;
use crate::audio::sfx::SfxEventItem; use common::slowjob::SlowJobPool;
use common::{event::EventBus, slowjob::SlowJobPool};
use specs::{World, WorldExt}; use specs::{World, WorldExt};
pub fn init(world: &mut World) { pub fn init(world: &mut World) {
@ -15,7 +14,4 @@ pub fn init(world: &mut World) {
pool.configure("FIGURE_MESHING", |n| n / 2); pool.configure("FIGURE_MESHING", |n| n / 2);
pool.configure("TERRAIN_MESHING", |n| n / 2); pool.configure("TERRAIN_MESHING", |n| n / 2);
} }
// Voxygen event buses
world.insert(EventBus::<SfxEventItem>::default());
} }