summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2022-03-21 13:02:11 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2022-03-21 13:02:11 -0400
commit61aa4f941e67cf45833f1e12fe25428b3f283f74 (patch)
tree36728b116c68c26f9841a56773a80ede77120b62
parent766a559d50149fac90cf3d5dac1490b8316fb943 (diff)
downloadether-61aa4f941e67cf45833f1e12fe25428b3f283f74.tar.gz
ether-61aa4f941e67cf45833f1e12fe25428b3f283f74.tar.bz2
ether-61aa4f941e67cf45833f1e12fe25428b3f283f74.zip
game can be muted now
not re-rendering the menu overlay because it looks fine tbh
-rw-r--r--src/game.cpp8
-rw-r--r--src/menu.cpp3
-rw-r--r--src/muxer.cpp74
-rw-r--r--src/muxer.h3
4 files changed, 82 insertions, 6 deletions
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)
668 muxer.setMusicLevel(0); 668 muxer.setMusicLevel(0);
669 } else if (zoomLevel < 3) { 669 } else if (zoomLevel < 3) {
670 muxer.setMusicLevel(1); 670 muxer.setMusicLevel(1);
671 } else if (zoomLevel < 5) { 671 } else if (zoomLevel < 4) {
672 muxer.setMusicLevel(2); 672 muxer.setMusicLevel(2);
673 } else if (zoomLevel < 6) { 673 } else if (zoomLevel < 6) {
674 muxer.setMusicLevel(3); 674 muxer.setMusicLevel(3);
@@ -796,6 +796,12 @@ void Game::updatePlaying(size_t frameTime) {
796 796
797 break; 797 break;
798 } 798 }
799
800 case SDLK_m:
801 {
802 muxer.toggleMute();
803 break;
804 }
799 } 805 }
800 } 806 }
801 } 807 }
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() {
11 items.push_back({.text = "Toggle Fullscreen", .activationFunction = [] (Game& game) { 11 items.push_back({.text = "Toggle Fullscreen", .activationFunction = [] (Game& game) {
12 game.renderer.toggleFullscreen(); 12 game.renderer.toggleFullscreen();
13 }}); 13 }});
14 items.push_back({.text = "Toggle Music", .activationFunction = [] (Game& game) {
15 game.muxer.toggleMute();
16 }});
14 items.push_back({.text = "Quit", .activationFunction = [this] (Game& game) { 17 items.push_back({.text = "Quit", .activationFunction = [this] (Game& game) {
15 close(); 18 close();
16 game.losing = LoseState::PoppingLamps; 19 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) {
39} 39}
40 40
41void Muxer::playSound(std::string name) { 41void 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
53void Muxer::playSoundAtPosition(std::string name, float x, float y) { 55void 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) {
72void Muxer::setMusicLevel(int level) { 76void 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
165void 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}
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:
40 40
41 void update(); 41 void update();
42 42
43 void toggleMute();
44
43private: 45private:
44 fmod_system_ptr system_; 46 fmod_system_ptr system_;
45 FMOD::Studio::EventInstance* exploration_event_; 47 FMOD::Studio::EventInstance* exploration_event_;
46 FMOD::Studio::EventInstance* transition_event_; 48 FMOD::Studio::EventInstance* transition_event_;
47 FMOD::Studio::EventInstance* the_world_event_; 49 FMOD::Studio::EventInstance* the_world_event_;
48 TransitionState transition_state_ = TransitionState::Pre; 50 TransitionState transition_state_ = TransitionState::Pre;
51 bool muted_ = false;
49}; 52};
50 53
51#endif /* end of include guard: MUXER_H_3146C802 */ 54#endif /* end of include guard: MUXER_H_3146C802 */