Skip to content

Commit b3ca3e3

Browse files
committed
final c++ touches?
1 parent 4e20e31 commit b3ca3e3

File tree

8 files changed

+62
-26
lines changed

8 files changed

+62
-26
lines changed

Data/Browncoats.rte/Music.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ AddDynamicSongSection = DynamicSongSection
148148
CopyOf = BCOSTTest Ambient Transition 1
149149
AddSoundContainer = SoundContainer
150150
CopyOf = BCOSTTest Ambient Main 1
151+
AddSoundContainer = SoundContainer
152+
CopyOf = BCOSTTest Ambient Main 2
153+
AddSoundContainer = SoundContainer
154+
CopyOf = BCOSTTest Ambient Main 3
151155

152156
AddDynamicSongSection = DynamicSongSection
153157
PresetName = BCOSTTest Tense

Source/Entities/SoundContainer.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void SoundContainer::Clear() {
5353
m_Pitch = 1.0F;
5454
m_PitchVariation = 0;
5555

56+
m_WasFadedOut = false;
5657
m_Paused = false;
5758
m_MusicPreEntryTime = 0.0F;
5859
m_MusicPostExitTime = 0.0F;
@@ -81,6 +82,7 @@ int SoundContainer::Create(const SoundContainer& reference) {
8182
m_Pitch = reference.m_Pitch;
8283
m_PitchVariation = reference.m_PitchVariation;
8384

85+
m_WasFadedOut = reference.m_WasFadedOut;
8486
m_Paused = reference.m_Paused;
8587
m_MusicPreEntryTime = reference.m_MusicPreEntryTime;
8688
m_MusicPostExitTime = reference.m_MusicPostExitTime;
@@ -202,6 +204,8 @@ int SoundContainer::Save(Writer& writer) const {
202204
writer.NewProperty("PitchVariation");
203205
writer << m_PitchVariation;
204206

207+
writer.NewProperty("WasFadedOut");
208+
writer << m_WasFadedOut;
205209
writer.NewProperty("Paused");
206210
writer << m_Paused;
207211
writer.NewProperty("MusicPreEntryTime");
@@ -302,6 +306,7 @@ void SoundContainer::SetPaused(bool paused) {
302306

303307
bool SoundContainer::Play(int player) {
304308
if (HasAnySounds()) {
309+
m_WasFadedOut = false;
305310
if (IsBeingPlayed()) {
306311
if (m_SoundOverlapMode == SoundOverlapMode::RESTART) {
307312
return Restart(player);
@@ -323,7 +328,8 @@ bool SoundContainer::Restart(int player) {
323328
}
324329

325330
void SoundContainer::FadeOut(int fadeOutTime) {
326-
if (IsBeingPlayed()) {
331+
if (!m_WasFadedOut && IsBeingPlayed()) {
332+
m_WasFadedOut = true;
327333
return g_AudioMan.FadeOutSoundContainerPlayingChannels(this, fadeOutTime);
328334
}
329335
}

Source/Entities/SoundContainer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ namespace RTE {
353353
float m_PitchVariation; //!< The randomized pitch variation of this SoundContainer's sounds. 1 means the sound will vary a full octave both ways.
354354
float m_Volume; //!< The current natural volume of this SoundContainer's sounds.
355355

356+
bool m_WasFadedOut; //!< Whether this SoundContainer has had its current playing sounds faded out or not.
356357
bool m_Paused; //!< Whether this SoundContainer is paused or not.
357358
float m_MusicPreEntryTime; //!< The time in MS before the music starts in this SoundContainer.
358359
float m_MusicPostExitTime; //!< The time in MS after the music ends in this SoundContainer, until the end of the sound.

Source/Lua/LuaAdapterDefinitions.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,18 @@ namespace RTE {
430430
static bool PlayDynamicSong2(MusicMan& musicMan, const std::string& songName, const std::string& songSectionType);
431431
static bool PlayDynamicSong3(MusicMan& musicMan, const std::string& songName, const std::string& songSectionType, bool playImmediately);
432432
static bool PlayDynamicSong4(MusicMan& musicMan, const std::string& songName, const std::string& songSectionType, bool playImmediately, bool playTransition);
433+
static bool PlayDynamicSong5(MusicMan& musicMan, const std::string& songName, const std::string& songSectionType, bool playImmediately, bool playTransition, bool smoothFade);
433434

434435
static bool SetNextDynamicSongSection1(MusicMan& musicMan, const std::string& songSectionType);
435436
static bool SetNextDynamicSongSection2(MusicMan& musicMan, const std::string& songSectionType, bool playImmediately);
436437
static bool SetNextDynamicSongSection3(MusicMan& musicMan, const std::string& songSectionType, bool playImmediately, bool playTransition);
438+
static bool SetNextDynamicSongSection4(MusicMan& musicMan, const std::string& songSectionType, bool playImmediately, bool playTransition, bool smoothFade);
437439

438440
static bool CyclePlayingSoundContainers1(MusicMan& musicMan);
439-
static bool CyclePlayingSoundContainers2(MusicMan& musicMan, bool fadeOutCurrent);
441+
static bool CyclePlayingSoundContainers2(MusicMan& musicMan, bool smoothFade);
442+
443+
static bool EndDynamicMusic1(MusicMan& musicMan);
444+
static bool EndDynamicMusic2(MusicMan& musicMan, bool fadeOutCurrent);
440445
};
441446
#pragma endregion
442447

Source/Lua/LuaAdapters.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,10 @@ bool LuaAdaptersMusicMan::PlayDynamicSong4(MusicMan& musicMan, const std::string
554554
return musicMan.PlayDynamicSong(songName, songSectionType, playImmediately, playTransition);
555555
}
556556

557+
bool LuaAdaptersMusicMan::PlayDynamicSong5(MusicMan& musicMan, const std::string& songName, const std::string& songSectionType, bool playImmediately, bool playTransition, bool smoothFade) {
558+
return musicMan.PlayDynamicSong(songName, songSectionType, playImmediately, playTransition, smoothFade);
559+
}
560+
557561
bool LuaAdaptersMusicMan::SetNextDynamicSongSection1(MusicMan& musicMan, const std::string& songSectionType) {
558562
return musicMan.SetNextDynamicSongSection(songSectionType);
559563
}
@@ -566,12 +570,24 @@ bool LuaAdaptersMusicMan::SetNextDynamicSongSection3(MusicMan& musicMan, const s
566570
return musicMan.SetNextDynamicSongSection(songSectionType, playImmediately, playTransition);
567571
}
568572

573+
bool LuaAdaptersMusicMan::SetNextDynamicSongSection4(MusicMan& musicMan, const std::string& songSectionType, bool playImmediately, bool playTransition, bool smoothFade) {
574+
return musicMan.SetNextDynamicSongSection(songSectionType, playImmediately, playTransition, smoothFade);
575+
}
576+
569577
bool LuaAdaptersMusicMan::CyclePlayingSoundContainers1(MusicMan& musicMan) {
570578
return musicMan.CyclePlayingSoundContainers();
571579
}
572580

573-
bool LuaAdaptersMusicMan::CyclePlayingSoundContainers2(MusicMan& musicMan, bool fadeOutCurrent) {
574-
return musicMan.CyclePlayingSoundContainers(fadeOutCurrent);
581+
bool LuaAdaptersMusicMan::CyclePlayingSoundContainers2(MusicMan& musicMan, bool smoothFade) {
582+
return musicMan.CyclePlayingSoundContainers(smoothFade);
583+
}
584+
585+
bool LuaAdaptersMusicMan::EndDynamicMusic1(MusicMan& musicMan) {
586+
return musicMan.EndDynamicMusic();
587+
}
588+
589+
bool LuaAdaptersMusicMan::EndDynamicMusic2(MusicMan& musicMan, bool fadeOutCurrent) {
590+
return musicMan.EndDynamicMusic(fadeOutCurrent);
575591
}
576592

577593
double LuaAdaptersTimerMan::GetDeltaTimeTicks(const TimerMan& timerMan) {

Source/Lua/LuaBindingsManagers.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,23 @@ LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, AudioMan) {
4343
LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, MusicMan) {
4444
return luabind::class_<MusicMan>("MusicManager")
4545

46+
.def("ResetMusicState", &MusicMan::ResetMusicState)
4647
.def("PlayDynamicSong", &LuaAdaptersMusicMan::PlayDynamicSong1)
4748
.def("PlayDynamicSong", &LuaAdaptersMusicMan::PlayDynamicSong2)
4849
.def("PlayDynamicSong", &LuaAdaptersMusicMan::PlayDynamicSong3)
4950
.def("PlayDynamicSong", &LuaAdaptersMusicMan::PlayDynamicSong4)
51+
.def("PlayDynamicSong", &LuaAdaptersMusicMan::PlayDynamicSong5)
5052
.def("SetNextDynamicSongSection", &LuaAdaptersMusicMan::SetNextDynamicSongSection1)
5153
.def("SetNextDynamicSongSection", &LuaAdaptersMusicMan::SetNextDynamicSongSection2)
5254
.def("SetNextDynamicSongSection", &LuaAdaptersMusicMan::SetNextDynamicSongSection3)
55+
.def("SetNextDynamicSongSection", &LuaAdaptersMusicMan::SetNextDynamicSongSection4)
5356
.def("CyclePlayingSoundContainers", &LuaAdaptersMusicMan::CyclePlayingSoundContainers1)
5457
.def("CyclePlayingSoundContainers", &LuaAdaptersMusicMan::CyclePlayingSoundContainers2)
55-
.def("EndDynamicMusic", &MusicMan::EndDynamicMusic);
58+
.def("EndDynamicMusic", &LuaAdaptersMusicMan::EndDynamicMusic1)
59+
.def("EndDynamicMusic", &LuaAdaptersMusicMan::EndDynamicMusic2)
60+
.def("PlayInterruptingMusic", &MusicMan::PlayInterruptingMusic)
61+
.def("EndInterruptingMusic", &MusicMan::EndInterruptingMusic);
62+
5663
}
5764

5865
LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, ConsoleMan) {

Source/Managers/MusicMan.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void MusicMan::ResetMusicState() {
8585
Clear();
8686
}
8787

88-
bool MusicMan::PlayDynamicSong(const std::string& songName, const std::string& songSectionType, bool playImmediately, bool playTransition) {
88+
bool MusicMan::PlayDynamicSong(const std::string& songName, const std::string& songSectionType, bool playImmediately, bool playTransition, bool smoothFade) {
8989
if (const DynamicSong* dynamicSongToPlay = dynamic_cast<const DynamicSong*>(g_PresetMan.GetEntityPreset("DynamicSong", songName))) {
9090
m_CurrentSong = std::unique_ptr<DynamicSong>(dynamic_cast<DynamicSong*>(dynamicSongToPlay->Clone()));
9191
SetCurrentSongSectionType(songSectionType);
@@ -98,16 +98,8 @@ bool MusicMan::PlayDynamicSong(const std::string& songName, const std::string& s
9898
m_PreviousSoundContainer->Stop();
9999
m_PreviousSoundContainer = nullptr;
100100
}
101-
102-
if (m_CurrentSoundContainer) {
103-
m_PreviousSoundContainerSetToFade = true;
104-
m_MusicFadeTimer.Reset();
105-
m_MusicFadeTimer.SetRealTimeLimitMS(static_cast<int>(m_NextSoundContainer->GetMusicPreEntryTime()));
106-
m_PreviousSoundContainer = std::unique_ptr<SoundContainer>(m_CurrentSoundContainer.release());
107-
m_CurrentSoundContainer = nullptr;
108-
}
109101
}
110-
CyclePlayingSoundContainers();
102+
CyclePlayingSoundContainers(smoothFade);
111103
}
112104
m_IsPlayingDynamicMusic = true;
113105

@@ -117,7 +109,7 @@ bool MusicMan::PlayDynamicSong(const std::string& songName, const std::string& s
117109
return false;
118110
}
119111

120-
bool MusicMan::SetNextDynamicSongSection(const std::string& newSongSectionType, bool playImmediately, bool playTransition) {
112+
bool MusicMan::SetNextDynamicSongSection(const std::string& newSongSectionType, bool playImmediately, bool playTransition, bool smoothFade) {
121113
if (!m_IsPlayingDynamicMusic) {
122114
return false;
123115
}
@@ -130,14 +122,16 @@ bool MusicMan::SetNextDynamicSongSection(const std::string& newSongSectionType,
130122
m_PreviousSoundContainer->Stop();
131123
m_PreviousSoundContainer = nullptr;
132124
}
133-
CyclePlayingSoundContainers(true);
125+
CyclePlayingSoundContainers(smoothFade);
134126
}
135127
return true;
136128
}
137129

138-
bool MusicMan::CyclePlayingSoundContainers(bool fadeOutCurrent) {
130+
bool MusicMan::CyclePlayingSoundContainers(bool smoothFade) {
139131
if (m_CurrentSoundContainer && m_CurrentSoundContainer->IsBeingPlayed()) {
140-
if (fadeOutCurrent) {
132+
if (smoothFade) {
133+
m_CurrentSoundContainer->FadeOut(static_cast<int>(m_NextSoundContainer->GetMusicPreEntryTime()));
134+
} else {
141135
m_PreviousSoundContainerSetToFade = true;
142136
m_MusicFadeTimer.Reset();
143137
m_MusicFadeTimer.SetRealTimeLimitMS(static_cast<int>(m_NextSoundContainer->GetMusicPreEntryTime()));

Source/Managers/MusicMan.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,35 @@ namespace RTE {
4343
/// @param songSectionType Type of DynamicSongSection to play first.
4444
/// @param playImmediately Whether to immediately play this song or wait for the current music piece to end.
4545
/// @param playTransition Whether to play the TransitionSoundContainer of the upcoming section or not.
46+
/// @param smoothFade True is long fade of the previous SoundContainer according to new PreEntry, false is fast fade at the new PreEntry.
4647
/// @return Whether the song was successfully started or not.
47-
bool PlayDynamicSong(const std::string& songName, const std::string& songSectionType = "Default", bool playImmediately = false, bool playTransition = true);
48+
bool PlayDynamicSong(const std::string& songName, const std::string& songSectionType = "Default", bool playImmediately = false, bool playTransition = true, bool smoothFade = false);
4849

4950
/// Switches the next SongSection queued to play.
5051
/// @param songSectionType Next SongSectionType to play.
5152
/// @param playImmediately Whether to immediately play the new SongSectionType or not.
5253
/// @param playTransition Whether to play the TransitionSoundContainer of the upcoming section or not.
53-
bool SetNextDynamicSongSection(const std::string& songSectionType, bool playImmediately = false, bool playTransition = true);
54+
/// @param smoothFade True is long fade of the previous SoundContainer according to new PreEntry, false is fast fade at the new PreEntry.
55+
/// @return True if successful, false if no dynamic song is currently playing.
56+
bool SetNextDynamicSongSection(const std::string& songSectionType, bool playImmediately = false, bool playTransition = true, bool smoothFade = false);
5457

5558
/// Plays the next queued SoundContainer and prepares a new one.
56-
/// @param fadeOutCurrent Whether to fade out the current playing SoundContainer or let it play out. False may cause undesirable overlap.
59+
/// @param smoothFade True is long fade of the previous SoundContainer according to new PreEntry, false is fast fade at the new PreEntry.
5760
/// @return Whether the function completed successfully or not.
58-
bool CyclePlayingSoundContainers(bool fadeOutCurrent = true);
61+
bool CyclePlayingSoundContainers(bool smoothFade = false);
5962

6063
/// Sets the current playing dynamic music to end, disabling further playback of new music.
6164
/// @param fadeOutCurrent Whether to also fade out the current playing music or not.
6265
/// @return True if this was not set to end music previously, false if it already was.
6366
bool EndDynamicMusic(bool fadeOutCurrent = false);
6467

6568
/// 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).
69+
/// Used for hardcoded music like the intro and main menu.
70+
/// This is exposed to Lua, but the above hardcoded calls will happily override the Lua. Something to keep in mind.
6871
/// @param soundContainer The SoundContainer to play as interrupting music.
6972
void PlayInterruptingMusic(const SoundContainer* soundContainer);
7073

71-
/// Signals the end of hardcoded music, resuming other music if needed.
74+
/// Signals the end of hardcoded music, resuming dynamic music if needed.
7275
void EndInterruptingMusic();
7376
#pragma endregion
7477

0 commit comments

Comments
 (0)