pub struct MusicState { /* private fields */ }Expand description
Which tracks play, and how one gives way to the next (ADR-0054): each
switch is a MusicSwitch, the request’s own or the default one. The
old track fades out; the new one starts once it has stopped, or as it
begins to fade (a crossfade), and may fade in. A cue already playing
doesn’t restart, and at most two tracks are loaded at once. A fade-in,
and an old track’s fade in a crossfade, wait until the new track sounds
(heard), or LOAD_WAIT_SECS.
Pure: feed it requests, time and what sounds, read the commands.
Implementations§
Source§impl MusicState
impl MusicState
Sourcepub const LOAD_WAIT_SECS: f32 = 3.0
pub const LOAD_WAIT_SECS: f32 = 3.0
How long a fade waits for the new track to sound, in seconds: after that it runs anyway, so a file that never loads never holds the old track.
Sourcepub fn new(fade_secs: f32) -> Self
pub fn new(fade_secs: f32) -> Self
Silence, with switches that fade out over fade_secs (to the
millisecond; negative or NaN counts as 0), then start the new track
at full gain (MusicSwitch::after_fade).
Sourcepub fn with_switch(default: MusicSwitch) -> Self
pub fn with_switch(default: MusicSwitch) -> Self
Silence, switching with default when a request names no switch,
and stopping with its out_ms.
Sourcepub fn target(&self) -> Option<&str>
pub fn target(&self) -> Option<&str>
The track a switch brings in, or the current one; None while the
music fades to silence.
Sourcepub fn heard(&mut self, clock: Option<&MusicClock>)
pub fn heard(&mut self, clock: Option<&MusicClock>)
Tells it what sounds: the music clock the platform reported for this
frame (Ctx::music_clock). A track sounds
once the clock names it, and stays sounding after.
Game::set_music_playing calls it
every frame.
Sourcepub fn request<V>(
&mut self,
request: &AudioRequest<V>,
out: &mut Vec<MusicCommand>,
)
pub fn request<V>( &mut self, request: &AudioRequest<V>, out: &mut Vec<MusicCommand>, )
Applies one request (sound and voice requests are ignored),
appending the commands it needs to out.
Sourcepub fn update(&mut self, dt: f32, out: &mut Vec<MusicCommand>)
pub fn update(&mut self, dt: f32, out: &mut Vec<MusicCommand>)
Advances the fades by dt seconds, appending the gain changes, the
stop of a track faded out and the start of the one waiting for it.
Trait Implementations§
Source§impl Clone for MusicState
impl Clone for MusicState
Source§fn clone(&self) -> MusicState
fn clone(&self) -> MusicState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more