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/game.cpp | 8 ++++++- src/menu.cpp | 3 +++ src/muxer.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/muxer.h | 3 +++ 4 files changed, 82 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index acccbc6..d63c208 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -668,7 +668,7 @@ void Game::setZoom(size_t zoom) muxer.setMusicLevel(0); } else if (zoomLevel < 3) { muxer.setMusicLevel(1); - } else if (zoomLevel < 5) { + } else if (zoomLevel < 4) { muxer.setMusicLevel(2); } else if (zoomLevel < 6) { muxer.setMusicLevel(3); @@ -796,6 +796,12 @@ void Game::updatePlaying(size_t frameTime) { break; } + + case SDLK_m: + { + muxer.toggleMute(); + break; + } } } } diff --git a/src/menu.cpp b/src/menu.cpp index b9a3ace..da88a90 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -11,6 +11,9 @@ Menu::Menu() { items.push_back({.text = "Toggle Fullscreen", .activationFunction = [] (Game& game) { game.renderer.toggleFullscreen(); }}); + items.push_back({.text = "Toggle Music", .activationFunction = [] (Game& game) { + game.muxer.toggleMute(); + }}); items.push_back({.text = "Quit", .activationFunction = [this] (Game& game) { close(); game.losing = LoseState::PoppingLamps; 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; + } + } + } +} diff --git a/src/muxer.h b/src/muxer.h index acceca8..8c643de 100644 --- a/src/muxer.h +++ b/src/muxer.h @@ -40,12 +40,15 @@ public: void update(); + void toggleMute(); + private: fmod_system_ptr system_; FMOD::Studio::EventInstance* exploration_event_; FMOD::Studio::EventInstance* transition_event_; FMOD::Studio::EventInstance* the_world_event_; TransitionState transition_state_ = TransitionState::Pre; + bool muted_ = false; }; #endif /* end of include guard: MUXER_H_3146C802 */ -- cgit 1.4.1