From 61aa4f941e67cf45833f1e12fe25428b3f283f74 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 21 Mar 2022 13:02:11 -0400 Subject: game can be muted now not re-rendering the menu overlay because it looks fine tbh --- src/muxer.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 5 deletions(-) (limited to 'src/muxer.cpp') 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) { } void Muxer::playSound(std::string name) { + if (muted_) return; + std::string eventPath = std::string("event:/") + name; FMOD::Studio::EventDescription* eventDescription = nullptr; @@ -51,6 +53,8 @@ void Muxer::playSound(std::string name) { } void Muxer::playSoundAtPosition(std::string name, float x, float y) { + if (muted_) return; + std::string eventPath = std::string("event:/") + name; FMOD::Studio::EventDescription* eventDescription = nullptr; @@ -72,14 +76,23 @@ void Muxer::playSoundAtPosition(std::string name, float x, float y) { void Muxer::setMusicLevel(int level) { if (transition_state_ == TransitionState::Pre) { if (level >= 3) { - transition_state_ = TransitionState::Transition; ERRCHECK(exploration_event_->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT)); ERRCHECK(exploration_event_->release()); - FMOD::Studio::EventDescription* eventDescription = nullptr; - ERRCHECK(system_->getEvent("event:/transition", &eventDescription)); - ERRCHECK(eventDescription->createInstance(&transition_event_)); - ERRCHECK(transition_event_->start()); + if (muted_) { + FMOD::Studio::EventDescription* eventDescription = nullptr; + ERRCHECK(system_->getEvent("event:/the_world", &eventDescription)); + ERRCHECK(eventDescription->createInstance(&the_world_event_)); + ERRCHECK(the_world_event_->start()); + ERRCHECK(the_world_event_->setVolume(0)); + transition_state_ = TransitionState::Post; + } else { + FMOD::Studio::EventDescription* eventDescription = nullptr; + ERRCHECK(system_->getEvent("event:/transition", &eventDescription)); + ERRCHECK(eventDescription->createInstance(&transition_event_)); + ERRCHECK(transition_event_->start()); + transition_state_ = TransitionState::Transition; + } } else { ERRCHECK(exploration_event_->setParameterByName("level", level)); } @@ -98,6 +111,10 @@ void Muxer::startMusic() { ERRCHECK(exploration_desc->createInstance(&exploration_event_)); ERRCHECK(exploration_event_->start()); + if (muted_) { + ERRCHECK(exploration_event_->setVolume(0)); + } + transition_state_ = TransitionState::Pre; } @@ -136,8 +153,55 @@ void Muxer::update() { ERRCHECK(system_->getEvent("event:/the_world", &eventDescription)); ERRCHECK(eventDescription->createInstance(&the_world_event_)); ERRCHECK(the_world_event_->start()); + if (muted_) { + ERRCHECK(the_world_event_->setVolume(0)); + } } } ERRCHECK(system_->update()); } + +void Muxer::toggleMute() { + muted_ = !muted_; + + if (muted_) { + switch (transition_state_) { + case TransitionState::Pre: { + ERRCHECK(exploration_event_->setVolume(0)); + break; + } + case TransitionState::Transition: { + ERRCHECK(transition_event_->setVolume(0)); + break; + } + case TransitionState::Post: { + ERRCHECK(the_world_event_->setVolume(0)); + break; + } + case TransitionState::Stopped: { + // Do nothing. + break; + } + } + } else { + switch (transition_state_) { + case TransitionState::Pre: { + ERRCHECK(exploration_event_->setVolume(1)); + break; + } + case TransitionState::Transition: { + ERRCHECK(transition_event_->setVolume(1)); + break; + } + case TransitionState::Post: { + ERRCHECK(the_world_event_->setVolume(1)); + break; + } + case TransitionState::Stopped: { + // Do nothing. + break; + } + } + } +} -- cgit 1.4.1