mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Start working on music change
This commit is contained in:
parent
9a3b5d3ec8
commit
7207ad4cce
@ -48,6 +48,7 @@ use client::Client;
|
|||||||
use common::{
|
use common::{
|
||||||
assets::{self, AssetExt, AssetHandle},
|
assets::{self, AssetExt, AssetHandle},
|
||||||
terrain::{BiomeKind, SitesKind},
|
terrain::{BiomeKind, SitesKind},
|
||||||
|
comp::Pos
|
||||||
};
|
};
|
||||||
use common_state::State;
|
use common_state::State;
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
@ -155,6 +156,8 @@ pub struct MusicMgr {
|
|||||||
last_interrupt: Instant,
|
last_interrupt: Instant,
|
||||||
/// The previous track's activity kind, for transitions
|
/// The previous track's activity kind, for transitions
|
||||||
last_activity: MusicState,
|
last_activity: MusicState,
|
||||||
|
last_player_pos: Pos,
|
||||||
|
player_travel_distance: f32
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@ -202,6 +205,8 @@ impl Default for MusicMgr {
|
|||||||
last_track: String::from("None"),
|
last_track: String::from("None"),
|
||||||
last_interrupt: Instant::now(),
|
last_interrupt: Instant::now(),
|
||||||
last_activity: MusicState::Activity(MusicActivity::Explore),
|
last_activity: MusicState::Activity(MusicActivity::Explore),
|
||||||
|
last_player_pos: Pos::default(),
|
||||||
|
player_travel_distance: 100.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,7 +227,7 @@ impl MusicMgr {
|
|||||||
// player_alt = position.0.z;
|
// player_alt = position.0.z;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
use common::comp::{group::ENEMY, Group, Health, Pos};
|
use common::comp::{group::ENEMY, Group, Health};
|
||||||
use specs::{Join, WorldExt};
|
use specs::{Join, WorldExt};
|
||||||
|
|
||||||
let mut activity_state = MusicActivity::Explore;
|
let mut activity_state = MusicActivity::Explore;
|
||||||
@ -279,6 +284,17 @@ impl MusicMgr {
|
|||||||
MusicState::Transition(_, next) => MusicState::Activity(next),
|
MusicState::Transition(_, next) => MusicState::Activity(next),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut interrupt_tp = false;
|
||||||
|
if let Some(player_pos) = positions.get(player) {
|
||||||
|
if (player_pos.0 - self.last_player_pos.0).magnitude_squared() > self.player_travel_distance.powi(2) {
|
||||||
|
println!("Need to stop music!!!!!!");
|
||||||
|
interrupt_tp = true;
|
||||||
|
}
|
||||||
|
self.last_player_pos = *player_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Instead of a constant tick, make this a timer that starts only when
|
// TODO: Instead of a constant tick, make this a timer that starts only when
|
||||||
// combat might end, providing a proper "buffer".
|
// combat might end, providing a proper "buffer".
|
||||||
let interrupt = matches!(music_state, MusicState::Transition(_, _))
|
let interrupt = matches!(music_state, MusicState::Transition(_, _))
|
||||||
@ -286,9 +302,9 @@ impl MusicMgr {
|
|||||||
|
|
||||||
if audio.music_enabled()
|
if audio.music_enabled()
|
||||||
&& !self.soundtrack.read().tracks.is_empty()
|
&& !self.soundtrack.read().tracks.is_empty()
|
||||||
&& (self.began_playing.elapsed().as_secs_f32() > self.next_track_change || interrupt)
|
&& (self.began_playing.elapsed().as_secs_f32() > self.next_track_change || interrupt || interrupt_tp)
|
||||||
{
|
{
|
||||||
if interrupt {
|
if interrupt || interrupt_tp {
|
||||||
self.last_interrupt = Instant::now();
|
self.last_interrupt = Instant::now();
|
||||||
}
|
}
|
||||||
trace!(
|
trace!(
|
||||||
|
Loading…
Reference in New Issue
Block a user