mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Minor audio code cleanup
This commit is contained in:
parent
e6ed8805e4
commit
221d6a67ad
@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Experience bar below the hotbar
|
||||
- Bridges.
|
||||
- Tool for exporting PNG images of all in-game models (`cargo img-export`)
|
||||
- Calendar event soundtracks.
|
||||
|
||||
### Changed
|
||||
|
||||
|
@ -15,17 +15,12 @@ use music::MusicTransitionManifest;
|
||||
use sfx::{SfxEvent, SfxTriggerItem};
|
||||
use soundcache::load_ogg;
|
||||
use std::time::Duration;
|
||||
use tracing::{debug, error, warn};
|
||||
use tracing::{debug, error};
|
||||
|
||||
use common::assets::{AssetExt, AssetHandle};
|
||||
use rodio::{source::Source, OutputStream, OutputStreamHandle, StreamError};
|
||||
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)]
|
||||
pub struct Listener {
|
||||
pos: Vec3<f32>,
|
||||
@ -116,15 +111,6 @@ impl AudioFrontend {
|
||||
|
||||
/// Construct in `no-audio` mode for debugging
|
||||
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 {
|
||||
// The following is for the disabled device switcher
|
||||
//device: "".to_string(),
|
||||
@ -142,7 +128,7 @@ impl AudioFrontend {
|
||||
master_volume: 1.0,
|
||||
music_spacing: 1.0,
|
||||
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) {
|
||||
// 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 listener = self.listener.clone();
|
||||
@ -302,7 +288,7 @@ impl AudioFrontend {
|
||||
) {
|
||||
if let Some(sfx_file) = Self::get_sfx_file(trigger_item) {
|
||||
// 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 listener = self.listener.clone();
|
||||
@ -337,7 +323,7 @@ impl AudioFrontend {
|
||||
) {
|
||||
if let Some(sfx_file) = Self::get_sfx_file(trigger_item) {
|
||||
// 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));
|
||||
|
||||
if let Some(channel) = self.get_ui_channel() {
|
||||
|
@ -207,9 +207,11 @@ impl MovementEventMapper {
|
||||
} else {
|
||||
match underfoot_block_kind {
|
||||
BlockKind::Snow => SfxEvent::Run(BlockKind::Snow),
|
||||
BlockKind::Rock | BlockKind::WeakRock | BlockKind::Ice => {
|
||||
SfxEvent::Run(BlockKind::Rock)
|
||||
},
|
||||
BlockKind::Rock
|
||||
| BlockKind::WeakRock
|
||||
| BlockKind::GlowingRock
|
||||
| BlockKind::GlowingWeakRock
|
||||
| BlockKind::Ice => SfxEvent::Run(BlockKind::Rock),
|
||||
BlockKind::Earth => SfxEvent::Run(BlockKind::Earth),
|
||||
// BlockKind::Sand => SfxEvent::Run(BlockKind::Sand),
|
||||
BlockKind::Air => SfxEvent::Idle,
|
||||
@ -237,7 +239,11 @@ impl MovementEventMapper {
|
||||
} else if physics_state.on_ground.is_some() && vel.magnitude() > 0.1 {
|
||||
match underfoot_block_kind {
|
||||
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::Earth => SfxEvent::Run(BlockKind::Earth),
|
||||
BlockKind::Air => SfxEvent::Idle,
|
||||
@ -259,7 +265,11 @@ impl MovementEventMapper {
|
||||
} else if physics_state.on_ground.is_some() && vel.magnitude() > 0.1 {
|
||||
match underfoot_block_kind {
|
||||
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::Earth => SfxEvent::QuadRun(BlockKind::Earth),
|
||||
BlockKind::Air => SfxEvent::Idle,
|
||||
|
@ -120,29 +120,6 @@ use vek::*;
|
||||
/// player.
|
||||
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)]
|
||||
pub enum SfxEvent {
|
||||
Campfire,
|
||||
@ -169,8 +146,6 @@ pub enum SfxEvent {
|
||||
CatchAir,
|
||||
Jump,
|
||||
Fall,
|
||||
ExperienceGained,
|
||||
LevelUp,
|
||||
Attack(CharacterAbilityType, ToolKind),
|
||||
Wield(ToolKind),
|
||||
Unwield(ToolKind),
|
||||
|
@ -1,8 +1,7 @@
|
||||
pub mod comp;
|
||||
pub mod sys;
|
||||
|
||||
use crate::audio::sfx::SfxEventItem;
|
||||
use common::{event::EventBus, slowjob::SlowJobPool};
|
||||
use common::slowjob::SlowJobPool;
|
||||
use specs::{World, WorldExt};
|
||||
|
||||
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("TERRAIN_MESHING", |n| n / 2);
|
||||
}
|
||||
|
||||
// Voxygen event buses
|
||||
world.insert(EventBus::<SfxEventItem>::default());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user