diff options
Diffstat (limited to 'src/muxer.cpp')
| -rw-r--r-- | src/muxer.cpp | 74 |
1 files changed, 69 insertions, 5 deletions
| diff --git a/src/muxer.cpp b/src/muxer.cpp index c276c0f..e6c9a09 100644 --- a/src/muxer.cpp +++ b/src/muxer.cpp | |||
| @@ -39,6 +39,8 @@ void Muxer::setPlayerLoc(int x, int y) { | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | void Muxer::playSound(std::string name) { | 41 | void Muxer::playSound(std::string name) { |
| 42 | if (muted_) return; | ||
| 43 | |||
| 42 | std::string eventPath = std::string("event:/") + name; | 44 | std::string eventPath = std::string("event:/") + name; |
| 43 | 45 | ||
| 44 | FMOD::Studio::EventDescription* eventDescription = nullptr; | 46 | FMOD::Studio::EventDescription* eventDescription = nullptr; |
| @@ -51,6 +53,8 @@ void Muxer::playSound(std::string name) { | |||
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | void Muxer::playSoundAtPosition(std::string name, float x, float y) { | 55 | void Muxer::playSoundAtPosition(std::string name, float x, float y) { |
| 56 | if (muted_) return; | ||
| 57 | |||
| 54 | std::string eventPath = std::string("event:/") + name; | 58 | std::string eventPath = std::string("event:/") + name; |
| 55 | 59 | ||
| 56 | FMOD::Studio::EventDescription* eventDescription = nullptr; | 60 | FMOD::Studio::EventDescription* eventDescription = nullptr; |
| @@ -72,14 +76,23 @@ void Muxer::playSoundAtPosition(std::string name, float x, float y) { | |||
| 72 | void Muxer::setMusicLevel(int level) { | 76 | void Muxer::setMusicLevel(int level) { |
| 73 | if (transition_state_ == TransitionState::Pre) { | 77 | if (transition_state_ == TransitionState::Pre) { |
| 74 | if (level >= 3) { | 78 | if (level >= 3) { |
| 75 | transition_state_ = TransitionState::Transition; | ||
| 76 | ERRCHECK(exploration_event_->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT)); | 79 | ERRCHECK(exploration_event_->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT)); |
| 77 | ERRCHECK(exploration_event_->release()); | 80 | ERRCHECK(exploration_event_->release()); |
| 78 | 81 | ||
| 79 | FMOD::Studio::EventDescription* eventDescription = nullptr; | 82 | if (muted_) { |
| 80 | ERRCHECK(system_->getEvent("event:/transition", &eventDescription)); | 83 | FMOD::Studio::EventDescription* eventDescription = nullptr; |
| 81 | ERRCHECK(eventDescription->createInstance(&transition_event_)); | 84 | ERRCHECK(system_->getEvent("event:/the_world", &eventDescription)); |
| 82 | ERRCHECK(transition_event_->start()); | 85 | ERRCHECK(eventDescription->createInstance(&the_world_event_)); |
| 86 | ERRCHECK(the_world_event_->start()); | ||
| 87 | ERRCHECK(the_world_event_->setVolume(0)); | ||
| 88 | transition_state_ = TransitionState::Post; | ||
| 89 | } else { | ||
| 90 | FMOD::Studio::EventDescription* eventDescription = nullptr; | ||
| 91 | ERRCHECK(system_->getEvent("event:/transition", &eventDescription)); | ||
| 92 | ERRCHECK(eventDescription->createInstance(&transition_event_)); | ||
| 93 | ERRCHECK(transition_event_->start()); | ||
| 94 | transition_state_ = TransitionState::Transition; | ||
| 95 | } | ||
| 83 | } else { | 96 | } else { |
| 84 | ERRCHECK(exploration_event_->setParameterByName("level", level)); | 97 | ERRCHECK(exploration_event_->setParameterByName("level", level)); |
| 85 | } | 98 | } |
| @@ -98,6 +111,10 @@ void Muxer::startMusic() { | |||
| 98 | ERRCHECK(exploration_desc->createInstance(&exploration_event_)); | 111 | ERRCHECK(exploration_desc->createInstance(&exploration_event_)); |
| 99 | ERRCHECK(exploration_event_->start()); | 112 | ERRCHECK(exploration_event_->start()); |
| 100 | 113 | ||
| 114 | if (muted_) { | ||
| 115 | ERRCHECK(exploration_event_->setVolume(0)); | ||
| 116 | } | ||
| 117 | |||
| 101 | transition_state_ = TransitionState::Pre; | 118 | transition_state_ = TransitionState::Pre; |
| 102 | } | 119 | } |
| 103 | 120 | ||
| @@ -136,8 +153,55 @@ void Muxer::update() { | |||
| 136 | ERRCHECK(system_->getEvent("event:/the_world", &eventDescription)); | 153 | ERRCHECK(system_->getEvent("event:/the_world", &eventDescription)); |
| 137 | ERRCHECK(eventDescription->createInstance(&the_world_event_)); | 154 | ERRCHECK(eventDescription->createInstance(&the_world_event_)); |
| 138 | ERRCHECK(the_world_event_->start()); | 155 | ERRCHECK(the_world_event_->start()); |
| 156 | if (muted_) { | ||
| 157 | ERRCHECK(the_world_event_->setVolume(0)); | ||
| 158 | } | ||
| 139 | } | 159 | } |
| 140 | } | 160 | } |
| 141 | 161 | ||
| 142 | ERRCHECK(system_->update()); | 162 | ERRCHECK(system_->update()); |
| 143 | } | 163 | } |
| 164 | |||
| 165 | void Muxer::toggleMute() { | ||
| 166 | muted_ = !muted_; | ||
| 167 | |||
| 168 | if (muted_) { | ||
| 169 | switch (transition_state_) { | ||
| 170 | case TransitionState::Pre: { | ||
| 171 | ERRCHECK(exploration_event_->setVolume(0)); | ||
| 172 | break; | ||
| 173 | } | ||
| 174 | case TransitionState::Transition: { | ||
| 175 | ERRCHECK(transition_event_->setVolume(0)); | ||
| 176 | break; | ||
| 177 | } | ||
| 178 | case TransitionState::Post: { | ||
| 179 | ERRCHECK(the_world_event_->setVolume(0)); | ||
| 180 | break; | ||
| 181 | } | ||
| 182 | case TransitionState::Stopped: { | ||
| 183 | // Do nothing. | ||
| 184 | break; | ||
| 185 | } | ||
| 186 | } | ||
| 187 | } else { | ||
| 188 | switch (transition_state_) { | ||
| 189 | case TransitionState::Pre: { | ||
| 190 | ERRCHECK(exploration_event_->setVolume(1)); | ||
| 191 | break; | ||
| 192 | } | ||
| 193 | case TransitionState::Transition: { | ||
| 194 | ERRCHECK(transition_event_->setVolume(1)); | ||
| 195 | break; | ||
| 196 | } | ||
| 197 | case TransitionState::Post: { | ||
| 198 | ERRCHECK(the_world_event_->setVolume(1)); | ||
| 199 | break; | ||
| 200 | } | ||
| 201 | case TransitionState::Stopped: { | ||
| 202 | // Do nothing. | ||
| 203 | break; | ||
| 204 | } | ||
| 205 | } | ||
| 206 | } | ||
| 207 | } | ||
