nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
jukebox.cc
Go to the documentation of this file.
1#include "client/jukebox.h"
2
3#include <algorithm>
4
5namespace nanommo {
6
7Jukebox::Cue Jukebox::Update(float seconds, bool in_world, bool playing) {
8 if (!in_world) {
9 // A player who comes back hears the track from the start, straight away.
10 started_ = false;
11 rest_ = 0.0f;
12 if (!playing) {
13 return Cue::kNothing;
14 }
15 volume_ = std::max(volume_ - seconds / kFadeOut, 0.0f);
16 return volume_ == 0.0f ? Cue::kStop : Cue::kNothing;
17 }
18 if (playing) {
19 volume_ = std::min(volume_ + seconds / kFadeIn, 1.0f);
20 return Cue::kNothing;
21 }
22 // The track has played through, so it rests before it starts again.
23 if (started_) {
24 started_ = false;
25 rest_ = kRest;
26 }
27 rest_ -= seconds;
28 if (rest_ > 0.0f) {
29 return Cue::kNothing;
30 }
31 started_ = true;
32 volume_ = 0.0f;
33 return Cue::kStart;
34}
35
36} // namespace nanommo
Cue Update(float seconds, bool in_world, bool playing)
Definition jukebox.cc:7
Cue
What the track should do this frame.
Definition jukebox.h:18
static constexpr float kFadeIn
In seconds.
Definition jukebox.h:13
static constexpr float kFadeOut
Definition jukebox.h:14
static constexpr float kRest
Definition jukebox.h:15
Definition chat.cc:9