Skip to content

Commit 8a780ae

Browse files
committed
In SoundContainer.h, stop including SoundSet
1 parent 05ee880 commit 8a780ae

15 files changed

+104
-49
lines changed

Source/Activities/GAScripted.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "Scene.h"
2929
#include "Actor.h"
3030
#include "PieMenu.h"
31+
#include "LuaMan.h"
3132

3233
#include "GUI.h"
3334
#include "GUIFont.h"

Source/Activities/MultiplayerServerLobby.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "DataModule.h"
2727
#include "MetaMan.h"
2828
#include "AudioMan.h"
29+
#include "LuaMan.h"
2930

3031
#include "GUI.h"
3132
#include "AllegroBitmap.h"

Source/Entities/PieMenu.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "UInputMan.h"
55
#include "PresetMan.h"
66
#include "SettingsMan.h"
7+
#include "LuaMan.h"
78

89
#include "AHuman.h"
910
#include "ContentFile.h"

Source/Entities/SoundContainer.cpp

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "SoundContainer.h"
2+
3+
#include "SoundSet.h"
24
#include "SettingsMan.h"
35

46
namespace RTE {
@@ -17,10 +19,26 @@ namespace RTE {
1719
{"Music", SoundContainer::BusRouting::MUSIC}
1820
};
1921

22+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
23+
24+
SoundContainer::SoundContainer() {
25+
Clear();
26+
}
27+
28+
SoundContainer::SoundContainer(const SoundContainer &reference) {
29+
Clear();
30+
Create(reference);
31+
}
32+
33+
SoundContainer::~SoundContainer() {
34+
Destroy(true);
35+
}
36+
2037
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2138

2239
void SoundContainer::Clear() {
23-
m_TopLevelSoundSet.Destroy();
40+
m_TopLevelSoundSet = std::make_shared<SoundSet>();
41+
m_TopLevelSoundSet->Destroy();
2442

2543
m_PlayingChannels.clear();
2644
m_SoundOverlapMode = SoundOverlapMode::OVERLAP;
@@ -47,7 +65,7 @@ namespace RTE {
4765
int SoundContainer::Create(const SoundContainer &reference) {
4866
Entity::Create(reference);
4967

50-
m_TopLevelSoundSet.Create(reference.m_TopLevelSoundSet);
68+
m_TopLevelSoundSet->Create(*reference.m_TopLevelSoundSet);
5169

5270
m_PlayingChannels.clear();
5371
m_SoundOverlapMode = reference.m_SoundOverlapMode;
@@ -70,19 +88,29 @@ namespace RTE {
7088
return 0;
7189
}
7290

91+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
92+
93+
int SoundContainer::Create(const std::string &soundFilePath, bool immobile, bool affectedByGlobalPitch, BusRouting busRouting) {
94+
m_TopLevelSoundSet->AddSound(soundFilePath, true);
95+
SetImmobile(immobile);
96+
SetAffectedByGlobalPitch(affectedByGlobalPitch);
97+
SetBusRouting(busRouting);
98+
return 0;
99+
}
100+
73101
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
74102

75103
int SoundContainer::ReadProperty(const std::string_view &propName, Reader &reader) {
76104
StartPropertyList(return Entity::ReadProperty(propName, reader));
77105

78-
MatchProperty("SpecialBehaviour_TopLevelSoundSet", { reader >> m_TopLevelSoundSet; });
79-
MatchProperty("AddSound", { m_TopLevelSoundSet.AddSoundData(SoundSet::ReadAndGetSoundData(reader)); });
106+
MatchProperty("SpecialBehaviour_TopLevelSoundSet", { reader >> *m_TopLevelSoundSet; });
107+
MatchProperty("AddSound", { m_TopLevelSoundSet->AddSoundData(SoundSet::ReadAndGetSoundData(reader)); });
80108
MatchProperty("AddSoundSet", {
81109
SoundSet soundSetToAdd;
82110
reader >> soundSetToAdd;
83-
m_TopLevelSoundSet.AddSoundSet(soundSetToAdd);
111+
m_TopLevelSoundSet->AddSoundSet(soundSetToAdd);
84112
});
85-
MatchForwards("SoundSelectionCycleMode") MatchProperty("CycleMode", { m_TopLevelSoundSet.SetSoundSelectionCycleMode(SoundSet::ReadSoundSelectionCycleMode(reader)); });
113+
MatchForwards("SoundSelectionCycleMode") MatchProperty("CycleMode", { m_TopLevelSoundSet->SetSoundSelectionCycleMode(SoundSet::ReadSoundSelectionCycleMode(reader)); });
86114
MatchProperty("SoundOverlapMode", {
87115
std::string soundOverlapModeString = reader.ReadPropValue();
88116
if (c_SoundOverlapModeMap.find(soundOverlapModeString) != c_SoundOverlapModeMap.end()) {
@@ -134,10 +162,10 @@ namespace RTE {
134162
Entity::Save(writer);
135163

136164
// Due to writer limitations, the top level SoundSet has to be explicitly written out, even though SoundContainer standard behaviour is to hide it in INI and just have properties be part of the SoundContainer.
137-
writer.NewPropertyWithValue("SpecialBehaviour_TopLevelSoundSet", m_TopLevelSoundSet);
165+
writer.NewPropertyWithValue("SpecialBehaviour_TopLevelSoundSet", *m_TopLevelSoundSet);
138166

139167
writer.NewProperty("SoundSelectionCycleMode");
140-
SoundSet::SaveSoundSelectionCycleMode(writer, m_TopLevelSoundSet.GetSoundSelectionCycleMode());
168+
SoundSet::SaveSoundSelectionCycleMode(writer, m_TopLevelSoundSet->GetSoundSelectionCycleMode());
141169

142170
writer.NewProperty("SoundOverlapMode");
143171
auto overlapModeMapEntry = std::find_if(c_SoundOverlapModeMap.begin(), c_SoundOverlapModeMap.end(), [&soundOverlapMode = m_SoundOverlapMode](auto element) { return element.second == soundOverlapMode; });
@@ -176,20 +204,26 @@ namespace RTE {
176204
return 0;
177205
}
178206

207+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
208+
209+
bool SoundContainer::HasAnySounds() const {
210+
return m_TopLevelSoundSet->HasAnySounds();
211+
}
212+
179213
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
180214

181215
float SoundContainer::GetLength(LengthOfSoundType type) const {
182216
if (!m_SoundPropertiesUpToDate) {
183217
// Todo - use a post-load fixup stage instead of lazily initializing shit everywhere... Eugh.
184218
const_cast<SoundContainer *>(this)->UpdateSoundProperties();
185-
const_cast<SoundContainer*>(this)->m_TopLevelSoundSet.SelectNextSounds();
219+
const_cast<SoundContainer*>(this)->m_TopLevelSoundSet->SelectNextSounds();
186220
}
187221

188-
std::vector<const SoundSet::SoundData*> flattenedSoundData;
189-
m_TopLevelSoundSet.GetFlattenedSoundData(flattenedSoundData, type == LengthOfSoundType::NextPlayed);
222+
std::vector<const SoundData*> flattenedSoundData;
223+
m_TopLevelSoundSet->GetFlattenedSoundData(flattenedSoundData, type == LengthOfSoundType::NextPlayed);
190224

191225
float lengthMilliseconds = 0.0f;
192-
for (const SoundSet::SoundData *selectedSoundData : flattenedSoundData) {
226+
for (const SoundData *selectedSoundData : flattenedSoundData) {
193227
unsigned int length;
194228
selectedSoundData->SoundObject->getLength(&length, FMOD_TIMEUNIT_MS);
195229
lengthMilliseconds = std::max(lengthMilliseconds, static_cast<float>(length));
@@ -198,24 +232,31 @@ namespace RTE {
198232
return lengthMilliseconds;
199233
}
200234

235+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
236+
237+
void SoundContainer::SetTopLevelSoundSet(const SoundSet &newTopLevelSoundSet) {
238+
*m_TopLevelSoundSet = newTopLevelSoundSet;
239+
m_SoundPropertiesUpToDate = false;
240+
}
241+
201242
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
202243

203244
std::vector<std::size_t> SoundContainer::GetSelectedSoundHashes() const {
204245
std::vector<size_t> soundHashes;
205-
std::vector<const SoundSet::SoundData *> flattenedSoundData;
206-
m_TopLevelSoundSet.GetFlattenedSoundData(flattenedSoundData, false);
207-
for (const SoundSet::SoundData *selectedSoundData : flattenedSoundData) {
246+
std::vector<const SoundData *> flattenedSoundData;
247+
m_TopLevelSoundSet->GetFlattenedSoundData(flattenedSoundData, false);
248+
for (const SoundData *selectedSoundData : flattenedSoundData) {
208249
soundHashes.push_back(selectedSoundData->SoundFile.GetHash());
209250
}
210251
return soundHashes;
211252
}
212253

213254
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
214255

215-
const SoundSet::SoundData * SoundContainer::GetSoundDataForSound(const FMOD::Sound *sound) const {
216-
std::vector<const SoundSet::SoundData *> flattenedSoundData;
217-
m_TopLevelSoundSet.GetFlattenedSoundData(flattenedSoundData, false);
218-
for (const SoundSet::SoundData *soundData : flattenedSoundData) {
256+
const SoundData * SoundContainer::GetSoundDataForSound(const FMOD::Sound *sound) const {
257+
std::vector<const SoundData *> flattenedSoundData;
258+
m_TopLevelSoundSet->GetFlattenedSoundData(flattenedSoundData, false);
259+
for (const SoundData *soundData : flattenedSoundData) {
219260
if (sound == soundData->SoundObject) {
220261
return soundData;
221262
}
@@ -245,9 +286,9 @@ namespace RTE {
245286
FMOD_RESULT SoundContainer::UpdateSoundProperties() {
246287
FMOD_RESULT result = FMOD_OK;
247288

248-
std::vector<SoundSet::SoundData *> flattenedSoundData;
249-
m_TopLevelSoundSet.GetFlattenedSoundData(flattenedSoundData, false);
250-
for (SoundSet::SoundData *soundData : flattenedSoundData) {
289+
std::vector<SoundData *> flattenedSoundData;
290+
m_TopLevelSoundSet->GetFlattenedSoundData(flattenedSoundData, false);
291+
for (SoundData *soundData : flattenedSoundData) {
251292
FMOD_MODE soundMode = (m_Loops == 0) ? FMOD_LOOP_OFF : FMOD_LOOP_NORMAL;
252293
if (m_Immobile) {
253294
soundMode |= FMOD_2D;

Source/Entities/SoundContainer.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#pragma once
22

33
#include "Entity.h"
4-
#include "SoundSet.h"
54
#include "AudioMan.h"
65

76
namespace RTE {
87
class Vector;
8+
struct SoundData;
9+
class SoundSet;
910

1011
/// <summary>
1112
/// A container for sounds that represent a specific sound effect.
@@ -40,13 +41,13 @@ namespace RTE {
4041
/// <summary>
4142
/// Constructor method used to instantiate a SoundContainer object in system memory. Create() should be called before using the object.
4243
/// </summary>
43-
SoundContainer() { Clear(); }
44+
SoundContainer();
4445

4546
/// <summary>
4647
/// Copy constructor method used to instantiate a SoundContainer object identical to an already existing one.
4748
/// </summary>
4849
/// <param name="reference">A reference to the SoundContainer to deep copy.</param>
49-
SoundContainer(const SoundContainer &reference) { Clear(); Create(reference); }
50+
SoundContainer(const SoundContainer &reference);
5051

5152
/// <summary>
5253
/// Creates a SoundContainer to be identical to another, by deep copy.
@@ -63,14 +64,14 @@ namespace RTE {
6364
/// <param name="affectedByGlobalPitch">Whether this SoundContainer's sounds' frequency will be affected by the global pitch.</param>
6465
/// <param name="busRouting">Bus to route this sound to.</param>
6566
/// <returns>An error return value signaling success or any particular failure. Anything below 0 is an error signal.</returns>
66-
int Create(const std::string &soundFilePath, bool immobile = false, bool affectedByGlobalPitch = true, BusRouting busRouting = BusRouting::SFX) { m_TopLevelSoundSet.AddSound(soundFilePath, true); SetImmobile(immobile); SetAffectedByGlobalPitch(affectedByGlobalPitch); SetBusRouting(busRouting); return 0; }
67+
int Create(const std::string &soundFilePath, bool immobile = false, bool affectedByGlobalPitch = true, BusRouting busRouting = BusRouting::SFX);
6768
#pragma endregion
6869

6970
#pragma region Destruction
7071
/// <summary>
7172
/// Destructor method used to clean up a SoundContainer object before deletion from system memory.
7273
/// </summary>
73-
~SoundContainer() override { Destroy(true); }
74+
~SoundContainer() override;
7475

7576
/// <summary>
7677
/// Destroys and resets (through Clear()) the SoundContainer object. It doesn't delete the Sound files, since they're owned by ContentFile static maps.
@@ -89,7 +90,7 @@ namespace RTE {
8990
/// Shows whether this SoundContainer's top level SoundSet has any SoundData or SoundSets.
9091
/// </summary>
9192
/// <returns>Whether this SoundContainer has any sounds.</returns>
92-
bool HasAnySounds() const { return m_TopLevelSoundSet.HasAnySounds(); }
93+
bool HasAnySounds() const;
9394

9495
enum class LengthOfSoundType {
9596
Any,
@@ -107,13 +108,13 @@ namespace RTE {
107108
/// Gets a reference to the top level SoundSet of this SoundContainer, to which all SoundData and sub SoundSets belong.
108109
/// </summary>
109110
/// <returns>A reference to the top level SoundSet of this SoundContainer.</returns>
110-
SoundSet & GetTopLevelSoundSet() { return m_TopLevelSoundSet; }
111+
SoundSet & GetTopLevelSoundSet() { return *m_TopLevelSoundSet; }
111112

112113
/// <summary>
113114
/// Copies the passed in SoundSet reference into the top level SoundSet of this SoundContainer, effectively making that the new top level SoundSet.
114115
/// </summary>
115116
/// <param name="newTopLevelSoundSet">A reference to the new top level SoundSet for this SoundContainer.</param>
116-
void SetTopLevelSoundSet(const SoundSet &newTopLevelSoundSet) { m_TopLevelSoundSet = newTopLevelSoundSet; m_SoundPropertiesUpToDate = false; }
117+
void SetTopLevelSoundSet(const SoundSet &newTopLevelSoundSet);
117118

118119
/// <summary>
119120
/// Gets a vector of hashes of the sounds selected to be played next in this SoundContainer.
@@ -126,7 +127,7 @@ namespace RTE {
126127
/// </summary>
127128
/// <param name="sound">The FMOD::Sound to search for.</param>
128129
/// <returns>A pointer to the corresponding SoundData or a null pointer.</returns>
129-
const SoundSet::SoundData * GetSoundDataForSound(const FMOD::Sound *sound) const;
130+
const SoundData * GetSoundDataForSound(const FMOD::Sound *sound) const;
130131

131132
/// <summary>
132133
/// Gets the channels playing sounds from this SoundContainer.
@@ -397,7 +398,7 @@ namespace RTE {
397398
static const std::unordered_map<std::string, SoundOverlapMode> c_SoundOverlapModeMap; //!< A map of strings to SoundOverlapModes to support string parsing for the SoundOverlapMode enum. Populated in the implementing cpp file.
398399
static const std::unordered_map<std::string, BusRouting> c_BusRoutingMap; //!< A map of strings to BusRoutings to support string parsing for the BusRouting enum. Populated in the implementing cpp file.
399400

400-
SoundSet m_TopLevelSoundSet; //The top level SoundSet that handles all SoundData and sub SoundSets in this SoundContainer.
401+
std::shared_ptr<SoundSet> m_TopLevelSoundSet; //The top level SoundSet that handles all SoundData and sub SoundSets in this SoundContainer.
401402

402403
std::unordered_set<int> m_PlayingChannels; //!< The channels this SoundContainer is currently using.
403404
SoundOverlapMode m_SoundOverlapMode; //!< The SoundOverlapMode for this SoundContainer, used to determine how it should handle overlapping play calls.

Source/Entities/SoundSet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ namespace RTE {
5858

5959
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
6060

61-
SoundSet::SoundData SoundSet::ReadAndGetSoundData(Reader &reader) {
62-
SoundSet::SoundData soundData;
61+
SoundData SoundSet::ReadAndGetSoundData(Reader &reader) {
62+
SoundData soundData;
6363

6464
/// <summary>
6565
/// Internal lambda function to load an audio file by path in as a ContentFile, which in turn loads it into FMOD, then returns SoundData for it in the outParam outSoundData.
@@ -182,7 +182,7 @@ namespace RTE {
182182
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
183183

184184
bool SoundSet::RemoveSound(const std::string &soundFilePath, bool removeFromSubSoundSets) {
185-
auto soundsToRemove = std::remove_if(m_SoundData.begin(), m_SoundData.end(), [&soundFilePath](const SoundSet::SoundData &soundData) { return soundData.SoundFile.GetDataPath() == soundFilePath; });
185+
auto soundsToRemove = std::remove_if(m_SoundData.begin(), m_SoundData.end(), [&soundFilePath](const SoundData &soundData) { return soundData.SoundFile.GetDataPath() == soundFilePath; });
186186
bool anySoundsToRemove = soundsToRemove != m_SoundData.end();
187187
if (anySoundsToRemove) { m_SoundData.erase(soundsToRemove, m_SoundData.end()); }
188188
if (removeFromSubSoundSets) {

Source/Entities/SoundSet.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66

77
namespace RTE {
88

9+
/// <summary>
10+
/// Self-contained struct defining an individual sound in a SoundSet.
11+
/// </summary>
12+
struct SoundData {
13+
ContentFile SoundFile;
14+
FMOD::Sound *SoundObject;
15+
Vector Offset = Vector();
16+
float MinimumAudibleDistance = 0.0F;
17+
float AttenuationStartDistance = -1.0F;
18+
};
19+
920
/// <summary>
1021
/// A set of sounds, and their selection data.
1122
/// </summary>
@@ -25,17 +36,6 @@ namespace RTE {
2536
ALL
2637
};
2738

28-
/// <summary>
29-
/// Self-contained struct defining an individual sound in a SoundSet.
30-
/// </summary>
31-
struct SoundData {
32-
ContentFile SoundFile;
33-
FMOD::Sound *SoundObject;
34-
Vector Offset = Vector();
35-
float MinimumAudibleDistance = 0.0F;
36-
float AttenuationStartDistance = -1.0F;
37-
};
38-
3939
#pragma region Creation
4040
/// <summary>
4141
/// Constructor method used to instantiate a SoundSet object in system memory. Create() should be called before using the object.

Source/GUI/GUISound.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "GUISound.h"
22

3+
#include "SoundSet.h"
4+
35
namespace RTE {
46

57
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Source/Lua/LuaAdapters.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "LuaAdapterDefinitions.h"
44
#include "LuabindObjectWrapper.h"
5+
#include "LuaMan.h"
56

67
namespace RTE {
78

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "LuaBindingRegisterDefinitions.h"
44

55
#include "PieSlice.h"
6+
#include "SoundSet.h"
67

78
namespace RTE {
89

0 commit comments

Comments
 (0)