Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 16fae2f

Browse files
committed
Clean up SoundContainer and AudioMan
Change shorts and stuff to ints where it makes sense, renamed some things, change NULL to nullptr, changed to range for loops Reorganized various method positions, added struct comments and missing regions to audioman.h Removed complexity in setting pitch and volume for soundcontainers, global pitch can be done to sound groups and individual pitch can be done to sounds. Volume and position shouldn't need to be dependent Change soundcontainer position, volume and pitch setters so they're they the audioman versions just take the soundcontainer
1 parent c08e22b commit 16fae2f

File tree

4 files changed

+108
-166
lines changed

4 files changed

+108
-166
lines changed

Entities/SoundContainer.cpp

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "SoundContainer.h"
2-
#include "RTETools.h"
32

43
namespace RTE {
54

@@ -118,13 +117,13 @@ namespace RTE {
118117
int SoundContainer::ReadSoundOrSoundSet(const std::string &propName, Reader &reader) {
119118
vector<SoundData> soundSet;
120119
if (propName == "AddSound") {
121-
soundSet.push_back(ReadSound(reader));
120+
soundSet.push_back(ReadAndGetSound(reader));
122121
} else if (propName == "AddSoundSet") {
123122
reader.ReadPropValue();
124123
while (reader.NextProperty()) {
125124
std::string soundSetSubPropertyName = reader.ReadPropName();
126125
if (soundSetSubPropertyName == "AddSound") {
127-
soundSet.push_back(ReadSound(reader));
126+
soundSet.push_back(ReadAndGetSound(reader));
128127
} else {
129128
reader.ReportError(soundSetSubPropertyName + " is not a valid property of SoundSets.");
130129
}
@@ -137,7 +136,7 @@ namespace RTE {
137136

138137
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
139138

140-
SoundContainer::SoundData SoundContainer::ReadSound(Reader &reader) {
139+
SoundContainer::SoundData SoundContainer::ReadAndGetSound(Reader &reader) const {
141140
std::string propValue = reader.ReadPropValue();
142141
SoundData soundData;
143142

@@ -279,7 +278,7 @@ namespace RTE {
279278
}
280279
}
281280
}
282-
return NULL;
281+
return nullptr;
283282
}
284283

285284
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -373,28 +372,4 @@ namespace RTE {
373372

374373
return result;
375374
}
376-
377-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
378-
379-
//TODO this needs to be used or be deleted
380-
void SoundContainer::CalculateCustomRolloffPoints(const SoundData &soundDataToCalculateFor, FMOD_VECTOR *rolloffPoints, int numRolloffPoints) {
381-
float attenuationStartDistance = (soundDataToCalculateFor.AttenuationStartDistance < 0) ? m_AttenuationStartDistance : soundDataToCalculateFor.AttenuationStartDistance;
382-
float currentDistance = attenuationStartDistance;
383-
float currentVolumeLevel = 1;
384-
385-
int i = 0;
386-
if (soundDataToCalculateFor.MinimumAudibleDistance > 0) {
387-
i = 2;
388-
currentDistance += soundDataToCalculateFor.MinimumAudibleDistance;
389-
rolloffPoints[0] = FMOD_VECTOR{0, 0, 0};
390-
rolloffPoints[1] = FMOD_VECTOR{soundDataToCalculateFor.MinimumAudibleDistance - 0.1F, 0, 0};
391-
}
392-
393-
for (i = ((soundDataToCalculateFor.MinimumAudibleDistance > 0) ? 2 : 0); i < numRolloffPoints - 1; i++) {
394-
rolloffPoints[i] = FMOD_VECTOR{currentDistance, currentVolumeLevel, 0};
395-
currentDistance += attenuationStartDistance;
396-
currentVolumeLevel = (currentDistance < c_SoundMaxAudibleDistance) ? currentVolumeLevel * 0.5F : 0;
397-
}
398-
rolloffPoints[numRolloffPoints - 1] = FMOD_VECTOR{currentDistance, 0, 0};
399-
}
400375
}

Entities/SoundContainer.h

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace RTE {
9797

9898
#pragma region INI Handling
9999
/// <summary>
100-
/// Handles reading a SoundSet from INI. If the Reader is trying to read a line adding a sound, it'll call ReadSound and add the resulting sound to a new SoundSet.
100+
/// Handles reading a SoundSet from INI. If the Reader is trying to read a line adding a sound, it'll call ReadAndGetSound and add the resulting sound to a new SoundSet.
101101
/// </summary>
102102
/// <param name="propName">The name of the property to be read.</param>
103103
/// <param name="reader">A Reader lined up to the value of the property to be read.</param>
@@ -109,7 +109,7 @@ namespace RTE {
109109
/// </summary>
110110
/// <param name="reader">A Reader lined up to the value of the property to be read.</param>
111111
/// <returns>SoundData for the newly read sound.</returns>
112-
SoundData ReadSound(Reader &reader);
112+
SoundData ReadAndGetSound(Reader &reader) const;
113113
#pragma endregion
114114

115115
#pragma region Sound Addition
@@ -199,7 +199,7 @@ namespace RTE {
199199
/// Gets the channels playing sounds from this SoundContainer.
200200
/// </summary>
201201
/// <returns>The channels currently being used.</returns>
202-
std::unordered_set<unsigned short> *GetPlayingChannels() { return &m_PlayingChannels; }
202+
std::unordered_set<int> *GetPlayingChannels() { return &m_PlayingChannels; }
203203

204204
/// <summary>
205205
/// Indicates whether any sound in this SoundContainer is currently being played.
@@ -211,13 +211,13 @@ namespace RTE {
211211
/// Adds a channel index to the SoundContainer's collection of playing channels.
212212
/// </summary>
213213
/// <param name="channel">The channel index to add.</param>
214-
void AddPlayingChannel(unsigned short channel) { m_PlayingChannels.insert(channel); }
214+
void AddPlayingChannel(int channel) { m_PlayingChannels.insert(channel); }
215215

216216
/// <summary>
217217
/// Removes a channel index from the SoundContainer's collection of playing channels.
218218
/// </summary>
219219
/// <param name="channel">The channel index to remove.</param>
220-
void RemovePlayingChannel(unsigned short channel) { m_PlayingChannels.erase(channel); }
220+
void RemovePlayingChannel(int channel) { m_PlayingChannels.erase(channel); }
221221

222222
/// <summary>
223223
/// Gets the SoundOverlapMode of this SoundContainer, which is used to determine how it should behave when it's told to play while already playing.
@@ -311,7 +311,7 @@ namespace RTE {
311311
/// </summary>
312312
/// <param name="position">The new position to play the SoundContainer's sounds.</param>
313313
/// <returns>Whether this SoundContainer's attenuation setting was successful.</returns>
314-
void SetPosition(const Vector &newPosition) { if (IsBeingPlayed() && !m_Immobile) { g_AudioMan.ChangePlayingSoundContainerPosition(this, newPosition); } m_Pos = m_Immobile ? Vector() : newPosition; }
314+
void SetPosition(const Vector &newPosition) { if (!m_Immobile && newPosition != m_Pos) { m_Pos = newPosition; if (IsBeingPlayed()) { g_AudioMan.ChangeSoundContainerPlayingChannelsPosition(this); } } }
315315

316316
/// <summary>
317317
/// 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.
@@ -323,7 +323,7 @@ namespace RTE {
323323
/// Sets the volume sounds in this SoundContainer should be played at. Note that this does not factor volume changes due to the SoundContainer's position. Does not affect currently playing sounds.
324324
/// </summary>
325325
/// <param name="newVolume">The new volume sounds in this SoundContainer should be played at. Limited between 0 and 10.</param>
326-
void SetVolume(float newVolume) { newVolume = std::clamp(newVolume, 0.0F, 10.0F); if (IsBeingPlayed()) { g_AudioMan.ChangePlayingSoundContainerVolume(this, newVolume); } m_Volume = newVolume; }
326+
void SetVolume(float newVolume) { m_Volume = std::clamp(newVolume, 0.0F, 10.0F); if (IsBeingPlayed()) { g_AudioMan.ChangeSoundContainerPlayingChannelsVolume(this); } }
327327

328328
/// <summary>
329329
/// Gets the pitch the sounds in this SoundContainer are played at. Note that this does not factor in global pitch.
@@ -335,7 +335,7 @@ namespace RTE {
335335
/// Sets the pitch sounds in this SoundContainer should be played at and updates any playing instances accordingly.
336336
/// </summary>
337337
/// <param name="newPitch">The new pitch sounds in this SoundContainer should be played at. Limited between 0.125 and 8 (8 octaves up or down).</param>
338-
void SetPitch(float newPitch) { newPitch = std::clamp(newPitch, 0.125F, 8.0F); if (IsBeingPlayed()) { g_AudioMan.ChangePlayingSoundContainerPitch(this, newPitch); } m_Pitch = newPitch; }
338+
void SetPitch(float newPitch) { m_Pitch = std::clamp(newPitch, 0.125F, 8.0F); if (IsBeingPlayed()) { g_AudioMan.ChangeSoundContainerPlayingChannelsPitch(this); } }
339339
#pragma endregion
340340

341341
#pragma region Playback Controls
@@ -424,7 +424,7 @@ namespace RTE {
424424
size_t m_SelectedSoundSet; //!< The selected SoundSet for this SoundContainer, used to determine what sounds will play when Play is called.
425425
SoundCycleMode m_SoundSelectionCycleMode; //!< The SoundCycleMode for this SoundContainer, used to determine what will play next, each time play is called.
426426

427-
std::unordered_set<unsigned short> m_PlayingChannels; //!< The channels this SoundContainer is currently using.
427+
std::unordered_set<int> m_PlayingChannels; //!< The channels this SoundContainer is currently using.
428428
SoundOverlapMode m_SoundOverlapMode; //!< The SoundOverlapMode for this SoundContainer, used to determine how it should handle overlapping play calls.
429429

430430
bool m_Immobile; //!< Whether this SoundContainer's sounds should be treated as immobile, i.e. not affected by 3D sound effects. Mostly used for GUI sounds and the like.
@@ -439,14 +439,6 @@ namespace RTE {
439439
float m_Pitch; //!< The current natural pitch of this SoundContainer's sounds.
440440
float m_Volume; //!< The current natural volume of this SoundContainer's sounds.
441441

442-
/// <summary>
443-
/// TODO This is currently not used in favor of a simpler 2-point method but is kept in case it should be changed back. Examine this and remove or use it in future.
444-
/// </summary>
445-
/// <param name="soundDataToCalculateFor"></param>
446-
/// <param name="rolloffPoints"></param>
447-
/// <param name="numRolloffPoints"></param>
448-
void CalculateCustomRolloffPoints(const SoundData &soundDataToCalculateFor, FMOD_VECTOR *rolloffPoints, int numRolloffPoints);
449-
450442
/// <summary>
451443
/// Clears all the member variables of this SoundContainer, effectively resetting the members of this abstraction level only.
452444
/// </summary>

0 commit comments

Comments
 (0)