Skip to content

Commit eec2451

Browse files
committed
Refactoring to make it hardcoded at point-of-use instead of within the MusicMan itself
1 parent 3094a1b commit eec2451

File tree

4 files changed

+13
-59
lines changed

4 files changed

+13
-59
lines changed

Source/Managers/MusicMan.cpp

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ MusicMan::~MusicMan() {
1616

1717
void MusicMan::Clear() {
1818
m_IsPlayingDynamicMusic = false;
19-
m_HardcodedSoundContainersInitialized = false;
20-
21-
m_IntroMusicSoundContainer = nullptr;
22-
m_MainMenuMusicSoundContainer = nullptr;
23-
m_ScenarioMenuMusicSoundContainer = nullptr;
2419

2520
m_InterruptingMusicSoundContainer = nullptr;
2621

@@ -45,39 +40,19 @@ bool MusicMan::Initialize() {
4540
return true;
4641
}
4742

48-
bool MusicMan::InitializeHardcodedSoundContainers() {
49-
// Have to do it here so these are read in at all..
50-
if (const SoundContainer* introMusicSoundContainer = dynamic_cast<const SoundContainer*>(g_PresetMan.GetEntityPreset("SoundContainer", "Intro Music"))) {
51-
m_IntroMusicSoundContainer = dynamic_cast<SoundContainer*>(introMusicSoundContainer->Clone());
52-
}
53-
54-
if (const SoundContainer* mainMenuMusicSoundContainer = dynamic_cast<const SoundContainer*>(g_PresetMan.GetEntityPreset("SoundContainer", "Main Menu Music"))) {
55-
m_MainMenuMusicSoundContainer = dynamic_cast<SoundContainer*>(mainMenuMusicSoundContainer->Clone());
56-
}
57-
58-
if (const SoundContainer* mainMenuMusicSoundContainer = dynamic_cast<const SoundContainer*>(g_PresetMan.GetEntityPreset("SoundContainer", "Scenario Menu Music"))) {
59-
m_ScenarioMenuMusicSoundContainer = dynamic_cast<SoundContainer*>(mainMenuMusicSoundContainer->Clone());
60-
}
61-
62-
return true;
63-
}
64-
6543
void MusicMan::Destroy() {
6644
// AudioMan will stop any music playing on its Destroy since they're just SoundContainers, so we don't need to worry
6745
Clear();
6846
}
6947

7048
void MusicMan::Update() {
71-
if (!m_HardcodedSoundContainersInitialized) {
72-
m_HardcodedSoundContainersInitialized = InitializeHardcodedSoundContainers();
73-
}
74-
7549
if (m_IsPlayingDynamicMusic) {
7650
if (m_MusicTimer.IsPastRealTimeLimit()) {
7751
CyclePlayingSoundContainers(false);
7852
}
7953
if (m_PreviousSoundContainerSetToFade && m_MusicFadeTimer.IsPastRealTimeLimit()) {
80-
m_PreviousSoundContainer->FadeOut(250);
54+
const int musicFadeOutTimeMs = 250;
55+
m_PreviousSoundContainer->FadeOut(musicFadeOutTimeMs);
8156
m_PreviousSoundContainerSetToFade = false;
8257
}
8358
} else {
@@ -204,7 +179,7 @@ bool MusicMan::EndDynamicMusic(bool fadeOutCurrent) {
204179
return true;
205180
}
206181

207-
void MusicMan::PlayInterruptingMusic(SoundContainer* soundContainer) {
182+
void MusicMan::PlayInterruptingMusic(const SoundContainer* soundContainer) {
208183
if (m_InterruptingMusicSoundContainer != nullptr) {
209184
m_InterruptingMusicSoundContainer->Stop();
210185
}

Source/Managers/MusicMan.h

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ namespace RTE {
1919
/// Makes the MusicMan object ready for use.
2020
/// @return Whether the muic system was initialized successfully.
2121
bool Initialize();
22-
23-
// Makes the hardcoded music ready for use.
24-
// @return Whether the SoundContainers were successfully found or not.
25-
bool InitializeHardcodedSoundContainers();
2622
#pragma endregion
2723

2824
#pragma region Destruction
@@ -38,20 +34,6 @@ namespace RTE {
3834
void Update();
3935
#pragma endregion
4036

41-
#pragma region Music Getters and Setters
42-
/// Gets the hardcoded intro music SoundContainer for the game.
43-
/// @return A pointer to the SoundContainer.
44-
SoundContainer* GetHardcodedIntroMusic() const { return m_IntroMusicSoundContainer; }
45-
46-
/// Gets the hardcoded main menu music SoundContainer for the game.
47-
/// @return A pointer to the SoundContainer.
48-
SoundContainer* GetHardcodedMainMenuMusic() const { return m_MainMenuMusicSoundContainer; }
49-
50-
/// Gets the hardcoded scenario menu music SoundContainer for the game.
51-
/// @return A pointer to the SoundContainer.
52-
SoundContainer* GetHardcodedScenarioMenuMusic() const { return m_ScenarioMenuMusicSoundContainer; }
53-
#pragma endregion
54-
5537
#pragma region Music Handling
5638
/// Resets music state, stopping and clearing playing dynamic songs or interrupting music, etc. to make ready for new music.
5739
void ResetMusicState();
@@ -81,20 +63,17 @@ namespace RTE {
8163
bool EndDynamicMusic(bool fadeOutCurrent = false);
8264

8365
/// Function to interrupt other music and play a SoundContainer as music. DynamicSongs playing are paused accordingly.
66+
/// This is generally used for hardcoded music, e.g Intro/Scenario/Main Menu music.
67+
/// In future we may expose this to script and make these things non-hardcoded (perhaps scripts that can run during menus).
8468
/// @param soundContainer The SoundContainer to play as interrupting music.
85-
void PlayInterruptingMusic(SoundContainer* soundContainer);
69+
void PlayInterruptingMusic(const SoundContainer* soundContainer);
8670

8771
/// Signals the end of hardcoded music, resuming other music if needed.
8872
void EndInterruptingMusic();
8973
#pragma endregion
9074

9175
protected:
9276
bool m_IsPlayingDynamicMusic; //!< Whether this is actively playing dynamic music or not.
93-
bool m_HardcodedSoundContainersInitialized; //!< Whether we have initialized base hardcoded SoundContainers or not.
94-
95-
SoundContainer* m_IntroMusicSoundContainer; //!< SoundContainer for hardcoded intro music.
96-
SoundContainer* m_MainMenuMusicSoundContainer; //!< SoundContainer for hardcoded main menu music.
97-
SoundContainer* m_ScenarioMenuMusicSoundContainer; //!< SoundContainer for hardcoded scenario menu music.
9877

9978
std::unique_ptr<SoundContainer> m_InterruptingMusicSoundContainer; //!< Current interrupting music being played.
10079

Source/Menus/MetagameGUI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2622,7 +2622,7 @@ void MetagameGUI::CompletedActivity() {
26222622
UpdateScenesBox(true);
26232623

26242624
// Play some nice ambient music
2625-
g_MusicMan.PlayInterruptingMusic(g_MusicMan.GetHardcodedMainMenuMusic());
2625+
g_MusicMan.PlayInterruptingMusic(dynamic_cast<const SoundContainer*>(g_PresetMan.GetEntityPreset("SoundContainer", "Main Menu Music")));
26262626
g_AudioMan.SetMusicMuffledState(false);
26272627
}
26282628
}

Source/Menus/TitleScreen.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void TitleScreen::UpdateIntroSlideshowSequence(bool skipSlideshow) {
265265
m_IntroScrollDuration = 66.6F - m_IntroScrollStartTime;
266266
m_ScrollOffset.SetY(m_IntroScrollStartOffsetY);
267267

268-
g_MusicMan.PlayInterruptingMusic(g_MusicMan.GetHardcodedIntroMusic());
268+
g_MusicMan.PlayInterruptingMusic(dynamic_cast<const SoundContainer*>(g_PresetMan.GetEntityPreset("SoundContainer", "Intro Music")));
269269
g_AudioMan.SetMusicMuffledState(false);
270270
}
271271
m_FadeAmount = static_cast<int>(Lerp(0, 1.0F, 255.0F, 0, m_SectionProgress));
@@ -395,7 +395,7 @@ void TitleScreen::UpdateIntroPreMainMenuSequence() {
395395
if (m_SectionSwitch) {
396396
SetSectionDurationAndResetSwitch(0.5F * g_SettingsMan.GetMenuTransitionDurationMultiplier());
397397
m_FadeAmount = 0;
398-
g_MusicMan.PlayInterruptingMusic(g_MusicMan.GetHardcodedMainMenuMusic());
398+
g_MusicMan.PlayInterruptingMusic(dynamic_cast<const SoundContainer*>(g_PresetMan.GetEntityPreset("SoundContainer", "Main Menu Music")));
399399
g_AudioMan.SetMusicMuffledState(false);
400400
}
401401
m_ScrollOffset.SetY(EaseOut(m_PreMainMenuScrollOffsetY, 0, m_SectionProgress));
@@ -433,7 +433,7 @@ void TitleScreen::UpdateTitleTransitions() {
433433
if (m_SectionSwitch) {
434434
SetSectionDurationAndResetSwitch(1.0F * g_SettingsMan.GetMenuTransitionDurationMultiplier());
435435
g_GUISound.SplashSound()->Play();
436-
g_MusicMan.PlayInterruptingMusic(g_MusicMan.GetHardcodedScenarioMenuMusic());
436+
g_MusicMan.PlayInterruptingMusic(dynamic_cast<const SoundContainer*>(g_PresetMan.GetEntityPreset("SoundContainer", "Scenario Menu Music")));
437437
g_AudioMan.SetMusicMuffledState(false);
438438
}
439439
m_ScrollOffset.SetY(EaseOut(0, m_PlanetViewScrollOffsetY, m_SectionProgress));
@@ -445,7 +445,7 @@ void TitleScreen::UpdateTitleTransitions() {
445445
case TitleTransition::PlanetToMainMenu:
446446
if (m_SectionSwitch) {
447447
SetSectionDurationAndResetSwitch(1.0F * g_SettingsMan.GetMenuTransitionDurationMultiplier());
448-
g_MusicMan.PlayInterruptingMusic(g_MusicMan.GetHardcodedMainMenuMusic());
448+
g_MusicMan.PlayInterruptingMusic(dynamic_cast<const SoundContainer*>(g_PresetMan.GetEntityPreset("SoundContainer", "Main Menu Music")));
449449
g_AudioMan.SetMusicMuffledState(false);
450450
}
451451
m_ScrollOffset.SetY(EaseOut(m_PlanetViewScrollOffsetY, 0, m_SectionProgress));
@@ -478,7 +478,7 @@ void TitleScreen::UpdateTitleTransitions() {
478478
m_ScrollOffset.SetY(m_PlanetViewScrollOffsetY);
479479
m_GameLogo.SetPos(Vector(static_cast<float>(m_TitleScreenMaxWidth / 2), m_GameLogoPlanetViewOffsetY));
480480
m_StationOrbitTimer.SetElapsedRealTimeS(m_StationOrbitTimerElapsedTime);
481-
g_MusicMan.PlayInterruptingMusic(g_MusicMan.GetHardcodedScenarioMenuMusic());
481+
g_MusicMan.PlayInterruptingMusic(dynamic_cast<const SoundContainer*>(g_PresetMan.GetEntityPreset("SoundContainer", "Scenario Menu Music")));
482482
g_AudioMan.SetMusicMuffledState(false);
483483
}
484484
m_FadeAmount = static_cast<int>(Lerp(0, 1.0F, 255.0F, 0, m_SectionProgress));
@@ -499,7 +499,7 @@ void TitleScreen::UpdateTitleTransitions() {
499499
if (m_SectionSwitch) {
500500
SetSectionDurationAndResetSwitch(0.75F * g_SettingsMan.GetMenuTransitionDurationMultiplier());
501501
m_StationOrbitTimer.SetElapsedRealTimeS(m_StationOrbitTimerElapsedTime);
502-
g_MusicMan.PlayInterruptingMusic(g_MusicMan.GetHardcodedMainMenuMusic());
502+
g_MusicMan.PlayInterruptingMusic(dynamic_cast<const SoundContainer*>(g_PresetMan.GetEntityPreset("SoundContainer", "Main Menu Music")));
503503
g_AudioMan.SetMusicMuffledState(false);
504504
}
505505
m_ScrollOffset.SetY(EaseOut(250, 0, m_SectionProgress));

0 commit comments

Comments
 (0)