Skip to content

Commit 98d9b80

Browse files
committed
fix music transitioning into itself
1 parent fa055fb commit 98d9b80

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

Data/Browncoats.rte/Activities/RefineryAssault.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function RefineryAssault:StartActivity(newGame)
147147
self.MOUtility = require("Scripts/Utility/MOUtility");
148148

149149
self.GameIntensityCalculator = require("Activities/Utility/GameIntensityCalculator");
150-
self.GameIntensityCalculator:Initialize(self, newGame, 0.15, 0.01, self.verboseLogging);
150+
self.GameIntensityCalculator:Initialize(self, newGame, 0.11, 0.01, self.verboseLogging);
151151

152152
self.actorSpawnerReturnedActors = {};
153153

@@ -540,24 +540,30 @@ function RefineryAssault:UpdateActivity()
540540

541541
-- Music
542542
local gameIntensity = self.GameIntensityCalculator:UpdateGameIntensityCalculator();
543-
print(gameIntensity)
544-
print(self.saveTable.musicState)
545543
if self.saveTable.musicState ~= "Boss" and self.musicGraceTimer:IsPastRealMS(20000) then
546544
if gameIntensity > 0.67 then
547545
if self.saveTable.musicState ~= "Intense" then
548546
self.saveTable.musicState = "Intense";
549-
MusicMan:SetNextDynamicSongSection("Intense", true, true, true);
547+
if MusicMan:GetCurrentDynamicSongSectionType() == "Intense" then
548+
MusicMan:SetNextDynamicSongSection("Intense", false, false, false);
549+
else
550+
MusicMan:SetNextDynamicSongSection("Intense", true, true, false);
551+
end
550552
end
551553
elseif gameIntensity > 0.2 then
552554
if self.saveTable.musicState ~= "Tense" then
553555
local playImmediately = self.saveTable.musicState == "Ambient" and true or false;
554556
self.saveTable.musicState = "Tense";
555-
MusicMan:SetNextDynamicSongSection("Tense", playImmediately, true, true);
557+
if MusicMan:GetCurrentDynamicSongSectionType() == "Tense" then
558+
MusicMan:SetNextDynamicSongSection("Tense", false, false, false);
559+
else
560+
MusicMan:SetNextDynamicSongSection("Tense", playImmediately, true, true);
561+
end
556562
end
557563
else
558564
if self.saveTable.musicState ~= "Ambient" then
559565
self.saveTable.musicState = "Ambient";
560-
MusicMan:SetNextDynamicSongSection("Ambient", false, true, true);
566+
MusicMan:SetNextDynamicSongSection("Ambient", false, true, false);
561567
end
562568
end
563569
end

Source/Lua/LuaBindingsManagers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, MusicMan) {
5656
.def("SetNextDynamicSongSection", &LuaAdaptersMusicMan::SetNextDynamicSongSection4)
5757
.def("CyclePlayingSoundContainers", &LuaAdaptersMusicMan::CyclePlayingSoundContainers1)
5858
.def("CyclePlayingSoundContainers", &LuaAdaptersMusicMan::CyclePlayingSoundContainers2)
59+
.def("GetCurrentDynamicSongSectionType", &MusicMan::GetCurrentSongSectionType)
5960
.def("EndDynamicMusic", &LuaAdaptersMusicMan::EndDynamicMusic1)
6061
.def("EndDynamicMusic", &LuaAdaptersMusicMan::EndDynamicMusic2)
6162
.def("PlayInterruptingMusic", &MusicMan::PlayInterruptingMusic)

Source/Managers/MusicMan.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ void MusicMan::Clear() {
2020
m_InterruptingMusicSoundContainer = nullptr;
2121

2222
m_CurrentSong = nullptr;
23-
m_CurrentSongSectionType = "Default";
24-
m_CurrentSongSection = nullptr;
23+
m_NextSongSectionType = "Default";
24+
m_NextSongSection = nullptr;
2525

2626
m_PreviousSoundContainer = nullptr;
2727
m_CurrentSoundContainer = nullptr;
@@ -98,7 +98,7 @@ void MusicMan::ResetMusicState() {
9898
bool MusicMan::PlayDynamicSong(const std::string& songName, const std::string& songSectionType, bool playImmediately, bool playTransition, bool smoothFade) {
9999
if (const DynamicSong* dynamicSongToPlay = dynamic_cast<const DynamicSong*>(g_PresetMan.GetEntityPreset("DynamicSong", songName))) {
100100
m_CurrentSong = std::unique_ptr<DynamicSong>(dynamic_cast<DynamicSong*>(dynamicSongToPlay->Clone()));
101-
SetCurrentSongSectionType(songSectionType);
101+
SetNextSongSectionType(songSectionType);
102102
SelectNextSongSection();
103103
SelectNextSoundContainer(playTransition);
104104
// If this isn't the case, then the MusicTimer's existing setup should make it play properly anyway, even if it's just instant
@@ -123,7 +123,7 @@ bool MusicMan::SetNextDynamicSongSection(const std::string& newSongSectionType,
123123
if (!m_IsPlayingDynamicMusic) {
124124
return false;
125125
}
126-
SetCurrentSongSectionType(newSongSectionType);
126+
SetNextSongSectionType(newSongSectionType);
127127
SelectNextSongSection();
128128
SelectNextSoundContainer(playTransition);
129129
if (playImmediately) {
@@ -156,6 +156,7 @@ bool MusicMan::CyclePlayingSoundContainers(bool smoothFade) {
156156
double timeUntilNextShouldBePlayed = m_CurrentSoundContainer->GetMusicExitTime() - m_NextSoundContainer->GetMusicPreEntryTime();
157157
m_MusicTimer.SetRealTimeLimitMS(timeUntilNextShouldBePlayed);
158158
m_CurrentSoundContainer->Play();
159+
m_CurrentSongSectionType = m_NextSongSectionType;
159160

160161
return true;
161162
}
@@ -235,25 +236,25 @@ void MusicMan::EndInterruptingMusic() {
235236
}
236237

237238
void MusicMan::SelectNextSongSection() {
238-
if (m_CurrentSongSection && m_CurrentSongSection->GetSectionType() == m_CurrentSongSectionType) {
239+
if (m_NextSongSection && m_NextSongSection->GetSectionType() == m_NextSongSectionType) {
239240
// Our current song section is already suitable
240241
return;
241242
}
242243

243244
for (DynamicSongSection& dynamicSongSection: m_CurrentSong->GetSongSections()) {
244-
if (dynamicSongSection.GetSectionType() == m_CurrentSongSectionType) {
245-
m_CurrentSongSection = &dynamicSongSection;
245+
if (dynamicSongSection.GetSectionType() == m_NextSongSectionType) {
246+
m_NextSongSection = &dynamicSongSection;
246247
return;
247248
}
248249
}
249250

250-
m_CurrentSongSection = &m_CurrentSong->GetDefaultSongSection();
251+
m_NextSongSection = &m_CurrentSong->GetDefaultSongSection();
251252
}
252253

253254
void MusicMan::SelectNextSoundContainer(bool playTransition) {
254255
if (playTransition) {
255-
m_NextSoundContainer = &m_CurrentSongSection->SelectTransitionSoundContainer();
256+
m_NextSoundContainer = &m_NextSongSection->SelectTransitionSoundContainer();
256257
} else {
257-
m_NextSoundContainer = &m_CurrentSongSection->SelectSoundContainer();
258+
m_NextSoundContainer = &m_NextSongSection->SelectSoundContainer();
258259
}
259260
}

Source/Managers/MusicMan.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ namespace RTE {
6464
/// @return Whether the function completed successfully or not.
6565
bool CyclePlayingSoundContainers(bool smoothFade = false);
6666

67+
/// Gets the current DynamicSongSectionType being played.
68+
/// @return The current DynamicSongSectionType being played.
69+
std::string GetCurrentSongSectionType() const { return m_CurrentSongSectionType; }
70+
6771
/// Sets the current playing dynamic music to end, disabling further playback of new music.
6872
/// @param fadeOutCurrent Whether to also fade out the current playing music or not.
6973
/// @return True if this was not set to end music previously, false if it already was.
@@ -85,8 +89,9 @@ namespace RTE {
8589
std::unique_ptr<SoundContainer> m_InterruptingMusicSoundContainer; //!< Current interrupting music being played.
8690

8791
std::unique_ptr<DynamicSong> m_CurrentSong; //!< The current DynamicSong being played.
88-
std::string m_CurrentSongSectionType; //!< The current type of DynamicSongSection we are trying to play.
89-
DynamicSongSection* m_CurrentSongSection; //!< The current DynamicSongSection we are actually playing.
92+
std::string m_NextSongSectionType; //!< The type of DynamicSongSection we will try to play next.
93+
std::string m_CurrentSongSectionType; //!< The current type of DynamicSongSection we are actually playing.
94+
DynamicSongSection* m_NextSongSection; //!< The DynamicSongSection we will try to play next.
9095

9196
std::unique_ptr<SoundContainer> m_PreviousSoundContainer; //!< The previous SoundContainer that was played as music. We keep it to allow it to play out while Current ramps up.
9297
std::unique_ptr<SoundContainer> m_CurrentSoundContainer; //!< The current selected SoundContainer playing as music.
@@ -102,7 +107,7 @@ namespace RTE {
102107
#pragma region Internal Music Handling
103108
/// Sets the current SongSectionType this wants to play.
104109
/// @param newSongSectionType New SongSectionType for this to want to play.
105-
void SetCurrentSongSectionType(const std::string& newSongSectionType) { m_CurrentSongSectionType = newSongSectionType; }
110+
void SetNextSongSectionType(const std::string& newSongSectionType) { m_NextSongSectionType = newSongSectionType; }
106111

107112
/// Selects and sets the next SongSection based on the current SongSectionType.
108113
void SelectNextSongSection();

0 commit comments

Comments
 (0)