Skip to content

Commit 9bf78e5

Browse files
committed
feature creep
1 parent b6a741f commit 9bf78e5

File tree

9 files changed

+62
-2
lines changed

9 files changed

+62
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1717
`ResetMusicState()` to immediately end all music and return the MusicMan to a blank state.
1818

1919
- New entities `DynamicSongSection` and `DynamicSong` which are used for organizing music to play using the new system.
20+
`DynamicSongSection` is made up of TransitionSoundContainers, SoundContainers, a string SectionType, and either randomnorepeat or shuffle SoundContainerSelectionCycleMode.
21+
`DynamicSong` is a simple container of DynamicSongSections. It can have one DefaultSongSection and as many added sections as needed.
22+
23+
- New `SoundContainer` features.
24+
Lua property `Paused` (R/W) to pause or unpause all sounds of a SoundContainer. Newly played sounds will not begin playback until unpaused.
25+
Lua function `GetAudibleVolume` to get the real audible volume of a SoundContainer's sounds as a float from 0 to 1. This accounts for literally everything, including game volume.
2026

2127
</details>
2228

Source/Entities/SoundContainer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ void SoundContainer::SetPosition(const Vector& newPosition) {
282282
}
283283
}
284284

285+
float SoundContainer::GetAudibleVolume() const {
286+
return g_AudioMan.GetSoundContainerAudibleVolume(this);
287+
}
288+
289+
285290
void SoundContainer::SetVolume(float newVolume) {
286291
newVolume = std::clamp(newVolume, 0.0F, 10.0F);
287292
if (IsBeingPlayed()) {

Source/Entities/SoundContainer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ namespace RTE {
223223
/// @return Whether this SoundContainer's attenuation setting was successful.
224224
void SetPosition(const Vector& newPosition);
225225

226+
/// Gets the real audible volume sounds in this SoundContainer are currently playing at, if any. Accounts for literally everything, including game volume.
227+
/// @return The real audible volume the sounds in this SoundContainer are played at.
228+
float GetAudibleVolume() const;
229+
226230
/// Gets the volume the sounds in this SoundContainer are played at. Note that this does not factor volume changes due to the SoundContainer's position.
227231
/// @return The volume the sounds in this SoundContainer are played at.
228232
float GetVolume() const { return m_Volume; }

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,7 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, SoundContainer) {
12821282
.def("HasAnySounds", &SoundContainer::HasAnySounds)
12831283
.def("GetTopLevelSoundSet", &SoundContainer::GetTopLevelSoundSet)
12841284
.def("SetTopLevelSoundSet", &SoundContainer::SetTopLevelSoundSet)
1285+
.def("GetAudibleVolume", &SoundContainer::GetAudibleVolume)
12851286
.def("IsBeingPlayed", &SoundContainer::IsBeingPlayed)
12861287
.def("Play", (bool(SoundContainer::*)()) & SoundContainer::Play)
12871288
.def("Play", (bool(SoundContainer::*)(const int player)) & SoundContainer::Play)

Source/Lua/LuaBindingsManagers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, MusicMan) {
4444
return luabind::class_<MusicMan>("MusicManager")
4545

4646
.def("ResetMusicState", &MusicMan::ResetMusicState)
47+
.def("IsMusicPlaying", &MusicMan::IsMusicPlaying)
4748
.def("PlayDynamicSong", &LuaAdaptersMusicMan::PlayDynamicSong1)
4849
.def("PlayDynamicSong", &LuaAdaptersMusicMan::PlayDynamicSong2)
4950
.def("PlayDynamicSong", &LuaAdaptersMusicMan::PlayDynamicSong3)

Source/Managers/AudioMan.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,30 @@ bool AudioMan::ChangeSoundContainerPlayingChannelsPosition(const SoundContainer*
471471
return result == FMOD_OK;
472472
}
473473

474+
float AudioMan::GetSoundContainerAudibleVolume(const SoundContainer* soundContainer) {
475+
if (!m_AudioEnabled || !soundContainer || !soundContainer->IsBeingPlayed()) {
476+
return 0.0F;
477+
}
478+
479+
FMOD_RESULT result;
480+
FMOD::Channel* soundChannel;
481+
float audibleVolume;
482+
483+
const std::unordered_set<int> channels = *soundContainer->GetPlayingChannels();
484+
for (int channel: channels) {
485+
result = m_AudioSystem->getChannel(channel, &soundChannel);
486+
result = (result == FMOD_OK) ? soundChannel->getAudibility(&audibleVolume) : result;
487+
488+
if (result != FMOD_OK) {
489+
g_ConsoleMan.PrintString("ERROR: Could not get sound audible volume in SoundContainer " + soundContainer->GetPresetName() + ": " + std::string(FMOD_ErrorString(result)));
490+
} else {
491+
// Simply return the first one, they are all the same
492+
return audibleVolume;
493+
}
494+
}
495+
return 0.0F;
496+
}
497+
474498
bool AudioMan::ChangeSoundContainerPlayingChannelsVolume(const SoundContainer* soundContainer, float newVolume) {
475499
if (!m_AudioEnabled || !soundContainer || !soundContainer->IsBeingPlayed()) {
476500
return false;

Source/Managers/AudioMan.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ namespace RTE {
360360
/// @return Whether the position was successfully set.
361361
bool ChangeSoundContainerPlayingChannelsPosition(const SoundContainer* soundContainer);
362362

363+
/// Sets/updates the position of a SoundContainer's playing sounds.
364+
/// @param soundContainer A pointer to a SoundContainer object. Ownership IS NOT transferred!
365+
/// @return Whether the position was successfully set.
366+
float GetSoundContainerAudibleVolume(const SoundContainer* soundContainer);
367+
363368
/// Changes the volume of a SoundContainer's playing sounds.
364369
/// @param soundContainer A pointer to a SoundContainer object. Ownership IS NOT transferred!
365370
/// @param newVolume The new volume to play sounds at, between 0 and 1.

Source/Managers/MusicMan.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,25 @@ void MusicMan::Update() {
5656
m_PreviousSoundContainerSetToFade = false;
5757
}
5858
} else {
59-
if (m_PreviousSoundContainer && !m_PreviousSoundContainer->IsBeingPlayed()) {
59+
if (m_PreviousSoundContainer && m_PreviousSoundContainer->GetAudibleVolume() == 0.0F) {
6060
m_PreviousSoundContainer = nullptr;
6161
}
62-
if (m_CurrentSoundContainer && !m_CurrentSoundContainer->IsBeingPlayed()) {
62+
if (m_CurrentSoundContainer && m_CurrentSoundContainer->GetAudibleVolume() == 0.0F) {
6363
m_CurrentSoundContainer = nullptr;
6464
}
6565
}
6666
}
6767

68+
bool MusicMan::IsMusicPlaying() const {
69+
bool interruptingMusicSoundContainerPlaying = m_InterruptingMusicSoundContainer != nullptr && m_InterruptingMusicSoundContainer->GetAudibleVolume() > 0.0F;
70+
bool previousSoundContainerPlaying = m_PreviousSoundContainer != nullptr && m_PreviousSoundContainer->GetAudibleVolume() > 0.0F;
71+
bool currentSoundContainerPlaying = m_CurrentSoundContainer != nullptr && m_CurrentSoundContainer->GetAudibleVolume() > 0.0F;
72+
if (interruptingMusicSoundContainerPlaying || previousSoundContainerPlaying || currentSoundContainerPlaying) {
73+
return true;
74+
}
75+
return false;
76+
}
77+
6878
void MusicMan::ResetMusicState() {
6979
if (m_InterruptingMusicSoundContainer != nullptr) {
7080
m_InterruptingMusicSoundContainer->Stop();

Source/Managers/MusicMan.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ namespace RTE {
3838
/// Resets music state, stopping and clearing playing dynamic songs or interrupting music, etc. to make ready for new music.
3939
void ResetMusicState();
4040

41+
/// Gets whether any music is audible, even if further playback is disabled.
42+
/// @return Whether any music is audible or not.
43+
bool IsMusicPlaying() const;
44+
4145
/// Begins playing a new dynamic song.
4246
/// @param songName PresetName of the dynamic song to play.
4347
/// @param songSectionType Type of DynamicSongSection to play first.

0 commit comments

Comments
 (0)