mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Code cleanup
This commit is contained in:
@ -89,16 +89,12 @@ impl AudioFrontend {
|
|||||||
///```ignore
|
///```ignore
|
||||||
///audio.play_sound("voxygen.audio.sfx.step");
|
///audio.play_sound("voxygen.audio.sfx.step");
|
||||||
///```
|
///```
|
||||||
pub fn play_sound(&mut self, sound: String, pos: Vec3<f32>) -> usize {
|
pub fn play_sound(&mut self, sound: &str, pos: Vec3<f32>) -> usize {
|
||||||
let id = self.next_channel_id;
|
let id = self.next_channel_id;
|
||||||
self.next_channel_id += 1;
|
self.next_channel_id += 1;
|
||||||
|
|
||||||
if let Some(_) = &self.audio_device {
|
if let Some(_) = &self.audio_device {
|
||||||
let calc_pos = [
|
let calc_pos = ((pos - self.listener_pos) * FALLOFF).into_array();
|
||||||
(pos.x - self.listener_pos.x) * FALLOFF,
|
|
||||||
(pos.y - self.listener_pos.y) * FALLOFF,
|
|
||||||
(pos.z - self.listener_pos.z) * FALLOFF,
|
|
||||||
];
|
|
||||||
|
|
||||||
let sound = self.sound_cache.load_sound(sound);
|
let sound = self.sound_cache.load_sound(sound);
|
||||||
|
|
||||||
@ -112,7 +108,7 @@ impl AudioFrontend {
|
|||||||
channel.set_right_ear_position(right_ear);
|
channel.set_right_ear_position(right_ear);
|
||||||
channel.play(sound);
|
channel.play(sound);
|
||||||
} else {
|
} else {
|
||||||
println!("No available channels!");
|
log::warn!("No available channels!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,18 +129,16 @@ impl AudioFrontend {
|
|||||||
|
|
||||||
for channel in self.channels.iter_mut() {
|
for channel in self.channels.iter_mut() {
|
||||||
if channel.get_audio_type() == AudioType::Sfx {
|
if channel.get_audio_type() == AudioType::Sfx {
|
||||||
channel.set_emitter_position([
|
channel.set_emitter_position(
|
||||||
(channel.pos.x - self.listener_pos.x) * FALLOFF,
|
((channel.pos - self.listener_pos) * FALLOFF).into_array(),
|
||||||
(channel.pos.y - self.listener_pos.y) * FALLOFF,
|
);
|
||||||
(channel.pos.z - self.listener_pos.z) * FALLOFF,
|
|
||||||
]);
|
|
||||||
channel.set_left_ear_position(pos_left.into_array());
|
channel.set_left_ear_position(pos_left.into_array());
|
||||||
channel.set_right_ear_position(pos_right.into_array());
|
channel.set_right_ear_position(pos_right.into_array());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play_music(&mut self, sound: String) -> usize {
|
pub fn play_music(&mut self, sound: &str) -> usize {
|
||||||
let id = self.next_channel_id;
|
let id = self.next_channel_id;
|
||||||
self.next_channel_id += 1;
|
self.next_channel_id += 1;
|
||||||
|
|
||||||
|
@ -44,10 +44,10 @@ impl SoundCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_sound(&mut self, name: String) -> rodio::Decoder<io::Cursor<Sound>> {
|
pub fn load_sound(&mut self, name: &str) -> rodio::Decoder<io::Cursor<Sound>> {
|
||||||
self.sounds
|
self.sounds
|
||||||
.entry(name.clone())
|
.entry(name.to_string())
|
||||||
.or_insert(Sound::load(&name).unwrap())
|
.or_insert(Sound::load(name).unwrap())
|
||||||
.decoder()
|
.decoder()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ impl SoundMgr {
|
|||||||
if state.last_step_sound.elapsed().as_secs_f64() > 0.25 {
|
if state.last_step_sound.elapsed().as_secs_f64() > 0.25 {
|
||||||
let rand_step = (rand::random::<usize>() % 7) + 1;
|
let rand_step = (rand::random::<usize>() % 7) + 1;
|
||||||
audio.play_sound(
|
audio.play_sound(
|
||||||
format!("voxygen.audio.footsteps.stepdirt_{}", rand_step),
|
&format!("voxygen.audio.footsteps.stepdirt_{}", rand_step),
|
||||||
pos.0,
|
pos.0,
|
||||||
);
|
);
|
||||||
state.last_step_sound = Instant::now();
|
state.last_step_sound = Instant::now();
|
||||||
|
Reference in New Issue
Block a user