summary refs log tree commit diff stats
path: root/src/muxer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/muxer.cpp')
-rw-r--r--src/muxer.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/muxer.cpp b/src/muxer.cpp index 5b09ef8..3450187 100644 --- a/src/muxer.cpp +++ b/src/muxer.cpp
@@ -62,9 +62,65 @@ void Muxer::playSoundAtPosition(std::string name, float x, float y) {
62} 62}
63 63
64void Muxer::setMusicLevel(int level) { 64void Muxer::setMusicLevel(int level) {
65 ERRCHECK(exploration_event_->setParameterByName("level", level)); 65 if (transition_state_ == TransitionState::Pre) {
66 if (level >= 3) {
67 transition_state_ = TransitionState::Transition;
68 ERRCHECK(exploration_event_->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT));
69 ERRCHECK(exploration_event_->release());
70
71 FMOD::Studio::EventDescription* eventDescription = nullptr;
72 ERRCHECK(system_->getEvent("event:/transition", &eventDescription));
73 ERRCHECK(eventDescription->createInstance(&transition_event_));
74 ERRCHECK(transition_event_->start());
75 } else {
76 ERRCHECK(exploration_event_->setParameterByName("level", level));
77 }
78 } else if (transition_state_ == TransitionState::Post) {
79 if (level <= 3) {
80 ERRCHECK(the_world_event_->setParameterByName("level_full", 0));
81 } else {
82 ERRCHECK(the_world_event_->setParameterByName("level_full", level - 3));
83 }
84 }
85}
86
87void Muxer::stopMusic() {
88 switch (transition_state_) {
89 case TransitionState::Pre: {
90 ERRCHECK(exploration_event_->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT));
91 break;
92 }
93 case TransitionState::Transition: {
94 ERRCHECK(transition_event_->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT));
95 break;
96 }
97 case TransitionState::Post: {
98 ERRCHECK(the_world_event_->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT));
99 break;
100 }
101 case TransitionState::Stopped: {
102 // Do nothing.
103 break;
104 }
105 }
106
107 transition_state_ = TransitionState::Stopped;
66} 108}
67 109
68void Muxer::update() { 110void Muxer::update() {
111 if (transition_state_ == TransitionState::Transition) {
112 FMOD_STUDIO_PLAYBACK_STATE playbackState;
113 ERRCHECK(transition_event_->getPlaybackState(&playbackState));
114 if (playbackState == FMOD_STUDIO_PLAYBACK_STOPPED) {
115 transition_state_ = TransitionState::Post;
116 transition_event_->release();
117
118 FMOD::Studio::EventDescription* eventDescription = nullptr;
119 ERRCHECK(system_->getEvent("event:/the_world", &eventDescription));
120 ERRCHECK(eventDescription->createInstance(&the_world_event_));
121 ERRCHECK(the_world_event_->start());
122 }
123 }
124
69 ERRCHECK(system_->update()); 125 ERRCHECK(system_->update());
70} 126}