mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Switch music at biome transitions
This commit is contained in:
parent
46d3f6f6d2
commit
b5aea464f3
@ -31,8 +31,8 @@
|
||||
title: "Wandering Voices",
|
||||
path: "voxygen.audio.soundtrack.wandering_voices",
|
||||
length: 137.0,
|
||||
timing: Some(Night),
|
||||
biome: Some(Snowlands),
|
||||
timing: Some(Day),
|
||||
biome: Some(Grassland),
|
||||
artist: "Aeronic",
|
||||
),
|
||||
(
|
||||
@ -48,7 +48,7 @@
|
||||
path: "voxygen.audio.soundtrack.mineral_deposits",
|
||||
length: 148.0,
|
||||
timing: Some(Day),
|
||||
biome: Some(Snowlands),
|
||||
biome: Some(Forest),
|
||||
artist: "Aeronic",
|
||||
),
|
||||
(
|
||||
@ -56,7 +56,7 @@
|
||||
path: "voxygen.audio.soundtrack.moonbeams",
|
||||
length: 158.0,
|
||||
timing: Some(Night),
|
||||
biome: Some(Snowlands),
|
||||
biome: Some(Forest),
|
||||
artist: "Aeronic",
|
||||
),
|
||||
(
|
||||
|
@ -113,7 +113,6 @@ impl AmbientMgr {
|
||||
let game_time = (state.get_time_of_day() as u64 % 86400) as u32;
|
||||
let current_period_of_day = Self::get_current_day_period(game_time);
|
||||
let current_biome = Self::get_current_biome(client);
|
||||
println!("Ambient Current biome: {:?}", current_biome);
|
||||
let mut rng = thread_rng();
|
||||
|
||||
let maybe_track = self
|
||||
|
@ -62,9 +62,9 @@ impl MusicChannel {
|
||||
}
|
||||
}
|
||||
|
||||
// Play a music track item on this channel. If the channel has an existing track
|
||||
// playing, the new sounds will be appended and played once they complete.
|
||||
// Otherwise it will begin playing immediately.
|
||||
/// Play a music track item on this channel. If the channel has an existing
|
||||
/// track playing, the new sounds will be appended and played once they
|
||||
/// complete. Otherwise it will begin playing immediately.
|
||||
pub fn play<S>(&mut self, source: S, tag: MusicChannelTag)
|
||||
where
|
||||
S: Source + Send + 'static,
|
||||
@ -82,6 +82,12 @@ impl MusicChannel {
|
||||
};
|
||||
}
|
||||
|
||||
/// Stop whatever is playing on a given channel
|
||||
pub fn stop(&mut self, tag: MusicChannelTag) {
|
||||
self.tag = tag;
|
||||
self.sink.stop();
|
||||
}
|
||||
|
||||
/// Set the volume of the current channel. If the channel is currently
|
||||
/// fading, the volume of the fader is updated to this value.
|
||||
pub fn set_volume(&mut self, volume: f32) {
|
||||
|
@ -205,6 +205,15 @@ impl AudioFrontend {
|
||||
let sound = Decoder::new(file).expect("Failed to decode sound");
|
||||
|
||||
channel.play(sound, channel_tag);
|
||||
//channel.set_fader(Fader::fade_in(2.0, music_volume));
|
||||
}
|
||||
}
|
||||
|
||||
fn stop_music(&mut self, channel_tag: MusicChannelTag) {
|
||||
let music_volume = self.music_volume;
|
||||
if let Some(channel) = self.get_music_channel(channel_tag) {
|
||||
//channel.set_fader(Fader::fade_out(5.0, music_volume));
|
||||
channel.stop(channel_tag);
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,6 +258,12 @@ impl AudioFrontend {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop_exploration_music(&mut self) {
|
||||
if self.music_enabled() {
|
||||
self.stop_music(MusicChannelTag::Exploration)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn play_exploration_ambient(&mut self, item: &str) {
|
||||
if self.ambient_enabled() {
|
||||
self.play_ambient(item, AmbientChannelTag::Exploration)
|
||||
|
@ -83,6 +83,8 @@ pub struct MusicMgr {
|
||||
/// The title of the last track played. Used to prevent a track
|
||||
/// being played twice in a row
|
||||
last_track: String,
|
||||
last_biome: BiomeKind,
|
||||
playing: bool,
|
||||
}
|
||||
|
||||
impl MusicMgr {
|
||||
@ -93,27 +95,46 @@ impl MusicMgr {
|
||||
began_playing: Instant::now(),
|
||||
next_track_change: 0.0,
|
||||
last_track: String::from("None"),
|
||||
last_biome: BiomeKind::Void,
|
||||
playing: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks whether the previous track has completed. If so, sends a
|
||||
/// request to play the next (random) track
|
||||
pub fn maintain(&mut self, audio: &mut AudioFrontend, state: &State, client: &Client) {
|
||||
// Gets the current player biome
|
||||
let current_biome: BiomeKind = match client.current_chunk() {
|
||||
Some(chunk) => chunk.meta().biome(),
|
||||
_ => self.last_biome,
|
||||
};
|
||||
|
||||
if audio.music_enabled()
|
||||
&& !self.soundtrack.tracks.is_empty()
|
||||
&& self.began_playing.elapsed().as_secs_f64() > self.next_track_change
|
||||
&& (self.began_playing.elapsed().as_secs_f64() > self.next_track_change
|
||||
|| !self.playing)
|
||||
{
|
||||
println!("It shoooooooooooooooooooooooooooooooooooooooooooooooooooooooould play!!!");
|
||||
self.play_random_track(audio, state, client);
|
||||
self.playing = true;
|
||||
} else if current_biome != self.last_biome {
|
||||
println!(
|
||||
"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSStop!\
|
||||
!!"
|
||||
);
|
||||
audio.stop_exploration_music();
|
||||
self.playing = false;
|
||||
}
|
||||
self.last_biome = current_biome;
|
||||
}
|
||||
|
||||
fn play_random_track(&mut self, audio: &mut AudioFrontend, state: &State, client: &Client) {
|
||||
const SILENCE_BETWEEN_TRACKS_SECONDS: f64 = 45.0;
|
||||
//const SILENCE_BETWEEN_TRACKS_SECONDS: f64 = 45.0;
|
||||
const SILENCE_BETWEEN_TRACKS_SECONDS: f64 = 5.0;
|
||||
|
||||
let game_time = (state.get_time_of_day() as u64 % 86400) as u32;
|
||||
let current_period_of_day = Self::get_current_day_period(game_time);
|
||||
let current_biome = Self::get_current_biome(client);
|
||||
println!("======> Music Current biome: {:?}", current_biome);
|
||||
let mut rng = thread_rng();
|
||||
|
||||
let maybe_track = self
|
||||
|
Loading…
Reference in New Issue
Block a user