diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-12 09:53:02 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-12 09:53:02 -0500 |
commit | 3996ccb4e2a0d81500d1b1370b2b97256d1ee465 (patch) | |
tree | e422ab35c9edbb034e44eab00f7a13666eeea6f8 /src | |
parent | de7ee5ef022a8ccaece0ea5f5402adedeafe36b4 (diff) | |
download | ether-3996ccb4e2a0d81500d1b1370b2b97256d1ee465.tar.gz ether-3996ccb4e2a0d81500d1b1370b2b97256d1ee465.tar.bz2 ether-3996ccb4e2a0d81500d1b1370b2b97256d1ee465.zip |
added transition and the world music
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 8 | ||||
-rw-r--r-- | src/muxer.cpp | 58 | ||||
-rw-r--r-- | src/muxer.h | 12 |
3 files changed, 76 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index cd1a8c2..1805357 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -419,8 +419,12 @@ void setZoom(Game& game, size_t zoom) | |||
419 | game.muxer.setMusicLevel(0); | 419 | game.muxer.setMusicLevel(0); |
420 | } else if (zoomLevel < 3) { | 420 | } else if (zoomLevel < 3) { |
421 | game.muxer.setMusicLevel(1); | 421 | game.muxer.setMusicLevel(1); |
422 | } else { | 422 | } else if (zoomLevel < 5) { |
423 | game.muxer.setMusicLevel(2); | 423 | game.muxer.setMusicLevel(2); |
424 | } else if (zoomLevel < 7) { | ||
425 | game.muxer.setMusicLevel(3); | ||
426 | } else { | ||
427 | game.muxer.setMusicLevel(4); | ||
424 | } | 428 | } |
425 | } | 429 | } |
426 | 430 | ||
@@ -493,6 +497,7 @@ int main(int, char**) | |||
493 | quit = true; | 497 | quit = true; |
494 | } else { | 498 | } else { |
495 | losing = LoseState::PoppingLamps; | 499 | losing = LoseState::PoppingLamps; |
500 | game.muxer.stopMusic(); | ||
496 | } | 501 | } |
497 | } else if (e.type == SDL_KEYDOWN) | 502 | } else if (e.type == SDL_KEYDOWN) |
498 | { | 503 | { |
@@ -505,6 +510,7 @@ int main(int, char**) | |||
505 | quit = true; | 510 | quit = true; |
506 | } else { | 511 | } else { |
507 | losing = LoseState::PoppingLamps; | 512 | losing = LoseState::PoppingLamps; |
513 | game.muxer.stopMusic(); | ||
508 | } | 514 | } |
509 | 515 | ||
510 | break; | 516 | break; |
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 | ||
64 | void Muxer::setMusicLevel(int level) { | 64 | void 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 | |||
87 | void 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 | ||
68 | void Muxer::update() { | 110 | void 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 | } |
diff --git a/src/muxer.h b/src/muxer.h index f99cce4..b1a5b26 100644 --- a/src/muxer.h +++ b/src/muxer.h | |||
@@ -15,6 +15,13 @@ public: | |||
15 | 15 | ||
16 | using fmod_system_ptr = std::unique_ptr<FMOD::Studio::System, fmod_system_deleter>; | 16 | using fmod_system_ptr = std::unique_ptr<FMOD::Studio::System, fmod_system_deleter>; |
17 | 17 | ||
18 | enum class TransitionState { | ||
19 | Pre, | ||
20 | Transition, | ||
21 | Post, | ||
22 | Stopped | ||
23 | }; | ||
24 | |||
18 | class Muxer { | 25 | class Muxer { |
19 | public: | 26 | public: |
20 | Muxer(); | 27 | Muxer(); |
@@ -25,11 +32,16 @@ public: | |||
25 | 32 | ||
26 | void setMusicLevel(int level); | 33 | void setMusicLevel(int level); |
27 | 34 | ||
35 | void stopMusic(); | ||
36 | |||
28 | void update(); | 37 | void update(); |
29 | 38 | ||
30 | private: | 39 | private: |
31 | fmod_system_ptr system_; | 40 | fmod_system_ptr system_; |
32 | FMOD::Studio::EventInstance* exploration_event_; | 41 | FMOD::Studio::EventInstance* exploration_event_; |
42 | FMOD::Studio::EventInstance* transition_event_; | ||
43 | FMOD::Studio::EventInstance* the_world_event_; | ||
44 | TransitionState transition_state_ = TransitionState::Pre; | ||
33 | }; | 45 | }; |
34 | 46 | ||
35 | #endif /* end of include guard: MUXER_H_3146C802 */ | 47 | #endif /* end of include guard: MUXER_H_3146C802 */ |