Skip to content

Commit 52fa95e

Browse files
committed
fix wound audio spam by disabling more than one per MO per frame
1 parent a5f43b0 commit 52fa95e

File tree

8 files changed

+49
-2
lines changed

8 files changed

+49
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3131
- New `SoundContainer` features.
3232
Lua property `Paused` (R/W) to pause or unpause all sounds of a SoundContainer. Newly played sounds will not begin playback until unpaused.
3333
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.
34+
35+
- New `AEmitter` and `PEmitter` INI and Lua (R/W) property `PlayBurstSound` which denotes whether the BurstSound should play when appropriate. This should not be confused for a trigger - it's just a enable/disable toggle to avoid having to remove and add BurstSound altogether.
3436

3537
- Allow lua scripts to use LuaJIT's BitOp module (see https://bitop.luajit.org/api.html)
3638

@@ -54,6 +56,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5456

5557
- `MovableMan:OpenAllDoors()`, when passed `NOTEAM`, will now open/close doors specifically for `NOTEAM` (instead of all doors).
5658

59+
- MOs now only play the BurstSound of the first Wound they receive in a frame, which not only solves audio spam during e.g. explosions but also preserves intended audio when firing guns with a high ParticleCount at them.
60+
5761
</details>
5862

5963
<details><summary><b>Fixed</b></summary>

Source/Entities/AEmitter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void AEmitter::Clear() {
3838
// Set this to really long so an initial burst will be possible
3939
m_BurstTimer.SetElapsedSimTimeS(50000);
4040
m_BurstTimer.SetElapsedRealTimeS(50000);
41+
m_PlayBurstSound = true;
4142
m_EmitAngle.Reset();
4243
m_EmissionOffset.Reset();
4344
m_EmitDamage = 0;
@@ -87,6 +88,7 @@ int AEmitter::Create(const AEmitter& reference) {
8788
m_EmitterDamageMultiplier = reference.m_EmitterDamageMultiplier;
8889
m_BurstSpacing = reference.m_BurstSpacing;
8990
m_BurstTriggered = reference.m_BurstTriggered;
91+
m_PlayBurstSound = reference.m_PlayBurstSound;
9092
m_EmitAngle = reference.m_EmitAngle;
9193
m_EmissionOffset = reference.m_EmissionOffset;
9294
m_EmitDamage = reference.m_EmitDamage;
@@ -147,6 +149,7 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
147149
MatchProperty("EmitterDamageMultiplier", { reader >> m_EmitterDamageMultiplier; });
148150
MatchProperty("BurstSpacing", { reader >> m_BurstSpacing; });
149151
MatchProperty("BurstTriggered", { reader >> m_BurstTriggered; });
152+
MatchProperty("PlayBurstSound", { reader >> m_PlayBurstSound; });
150153
MatchProperty("EmissionAngle", { reader >> m_EmitAngle; });
151154
MatchProperty("EmissionOffset", { reader >> m_EmissionOffset; });
152155
MatchProperty("EmissionDamage", { reader >> m_EmitDamage; });
@@ -197,6 +200,8 @@ int AEmitter::Save(Writer& writer) const {
197200
writer << m_BurstSpacing;
198201
writer.NewProperty("BurstTriggered");
199202
writer << m_BurstTriggered;
203+
writer.NewProperty("PlayBurstSound");
204+
writer << m_PlayBurstSound;
200205
writer.NewProperty("EmissionAngle");
201206
writer << m_EmitAngle;
202207
writer.NewProperty("EmissionOffset");
@@ -392,7 +397,7 @@ void AEmitter::Update() {
392397
float throttleFactor = GetThrottleFactor();
393398
m_FlashScale = throttleFactor;
394399
// Check burst triggering against whether the spacing is fulfilled
395-
if (m_BurstTriggered && CanTriggerBurst()) {
400+
if (m_PlayBurstSound && m_BurstTriggered && CanTriggerBurst()) {
396401
// Play burst sound
397402
if (m_BurstSound) {
398403
m_BurstSound->Play(m_Pos);

Source/Entities/AEmitter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ namespace RTE {
292292
/// @param newValue Emit damage of emitter.
293293
void SetEmitDamage(float newValue) { m_EmitDamage = newValue; }
294294

295+
/// Returns whether this emitter will play its burst sound when appropriate or not.
296+
/// @return Whether this emitter will play its burst sound when appropriate or not.
297+
bool GetPlayBurstSound() const { return m_PlayBurstSound; }
298+
299+
/// Sets whether this emitter will play its burst sound when appropriate or not.
300+
/// @param playBurstSound Whether this emitter should play its burst sound when appropriate or not.
301+
void SetPlayBurstSound(bool playBurstSound) { m_PlayBurstSound = playBurstSound; }
302+
295303
/// Returns damage multiplier of this emitter.
296304
/// @return Damage multiplier of emitter.
297305
float GetEmitterDamageMultiplier() const { return m_EmitterDamageMultiplier; }
@@ -390,6 +398,8 @@ namespace RTE {
390398
float m_BurstSpacing;
391399
// Measures the shortest possible time between bursts
392400
Timer m_BurstTimer;
401+
// Whether to play the BurstSound when a burst is triggered or not.
402+
bool m_PlayBurstSound;
393403
// The angle of the direction the emitted particles will head in.
394404
// The m_Roataion of this AEmitter will be added to this angle.
395405
Matrix m_EmitAngle;

Source/Entities/MOSRotating.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void MOSRotating::Clear() {
5454
m_RecoilForce.Reset();
5555
m_RecoilOffset.Reset();
5656
m_Wounds.clear();
57+
m_WoundBurstSoundPlayedThisFrame = false;
5758
m_Attachables.clear();
5859
m_ReferenceHardcodedAttachableUniqueIDs.clear();
5960
m_HardcodedAttachableUniqueIDsAndSetters.clear();
@@ -458,6 +459,12 @@ void MOSRotating::AddWound(AEmitter* woundToAdd, const Vector& parentOffsetToSet
458459
woundToAdd->SetParentOffset(parentOffsetToSet);
459460
woundToAdd->SetParent(this);
460461
woundToAdd->SetIsWound(true);
462+
if (woundToAdd->GetBurstSound()) {
463+
if (m_WoundBurstSoundPlayedThisFrame) {
464+
woundToAdd->SetPlayBurstSound(false);
465+
}
466+
m_WoundBurstSoundPlayedThisFrame = true;
467+
}
461468
if (woundToAdd->HasNoSetDamageMultiplier()) {
462469
woundToAdd->SetDamageMultiplier(1.0F);
463470
}
@@ -1340,6 +1347,8 @@ void MOSRotating::Update() {
13401347
m_Rotation += radsToGo * m_OrientToVel * velInfluence;
13411348
}
13421349

1350+
m_WoundBurstSoundPlayedThisFrame = false;
1351+
13431352
for (auto woundItr = m_Wounds.begin(); woundItr != m_Wounds.end();) {
13441353
AEmitter* wound = *woundItr;
13451354
RTEAssert(wound && wound->IsAttachedTo(this), "Broken wound AEmitter in Update");

Source/Entities/MOSRotating.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ namespace RTE {
540540
Vector m_RecoilOffset;
541541
// The list of wound AEmitters currently attached to this MOSRotating, and owned here as well.
542542
std::vector<AEmitter*> m_Wounds;
543+
// Whether we added a wound with a BurstSound this frame or not, so we can disable further ones to avoid audio spam.
544+
bool m_WoundBurstSoundPlayedThisFrame;
543545
// The list of Attachables currently attached and Owned by this.
544546
std::list<Attachable*> m_Attachables;
545547
std::unordered_set<unsigned long> m_ReferenceHardcodedAttachableUniqueIDs; //!< An unordered set is filled with the Unique IDs of all of the reference object's hardcoded Attachables when using the copy Create.

Source/Entities/PEmitter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void PEmitter::Clear() {
3535
// Set this to really long so an initial burst will be possible
3636
m_BurstTimer.SetElapsedSimTimeS(50000);
3737
m_BurstTimer.SetElapsedRealTimeS(50000);
38+
m_PlayBurstSound = true;
3839
m_EmitAngle.Reset();
3940
m_EmissionOffset.Reset();
4041
m_LastEmitTmr.Reset();
@@ -73,6 +74,7 @@ int PEmitter::Create(const PEmitter& reference) {
7374
m_BurstScale = reference.m_BurstScale;
7475
m_BurstSpacing = reference.m_BurstSpacing;
7576
m_BurstTriggered = reference.m_BurstTriggered;
77+
m_PlayBurstSound = reference.m_PlayBurstSound;
7678
m_EmitAngle = reference.m_EmitAngle;
7779
m_EmissionOffset = reference.m_EmissionOffset;
7880
m_FlashScale = reference.m_FlashScale;
@@ -122,6 +124,7 @@ int PEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
122124
MatchProperty("BurstScale", { reader >> m_BurstScale; });
123125
MatchProperty("BurstSpacing", { reader >> m_BurstSpacing; });
124126
MatchProperty("BurstTriggered", { reader >> m_BurstTriggered; });
127+
MatchProperty("PlayBurstSound", { reader >> m_PlayBurstSound; });
125128
MatchProperty("EmissionAngle", { reader >> m_EmitAngle; });
126129
MatchProperty("EmissionOffset", { reader >> m_EmissionOffset; });
127130
MatchProperty("FlashScale", { reader >> m_FlashScale; });
@@ -166,6 +169,8 @@ int PEmitter::Save(Writer& writer) const {
166169
writer << m_BurstSpacing;
167170
writer.NewProperty("BurstTriggered");
168171
writer << m_BurstTriggered;
172+
writer.NewProperty("PlayBurstSound");
173+
writer << m_PlayBurstSound;
169174
writer.NewProperty("EmissionAngle");
170175
writer << m_EmitAngle;
171176
writer.NewProperty("EmissionOffset");
@@ -295,7 +300,7 @@ void PEmitter::Update() {
295300
float throttleFactor = GetThrottleFactor();
296301
m_FlashScale = throttleFactor;
297302
// Check burst triggering against whether the spacing is fulfilled
298-
if (m_BurstTriggered && (m_BurstSpacing <= 0 || m_BurstTimer.IsPastSimMS(m_BurstSpacing))) {
303+
if (m_PlayBurstSound && m_BurstTriggered && (m_BurstSpacing <= 0 || m_BurstTimer.IsPastSimMS(m_BurstSpacing))) {
299304
// Play burst sound
300305
m_BurstSound.Play(m_Pos);
301306
// Start timing until next burst

Source/Entities/PEmitter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ namespace RTE {
226226
/// Indicates whether this PEmitter is set to burst next update or not.
227227
/// @return Whether a burst is gonna happen or not..
228228
bool IsSetToBurst() const { return m_BurstTriggered; }
229+
230+
/// Returns whether this emitter will play its burst sound when appropriate or not.
231+
/// @return Whether this emitter will play its burst sound when appropriate or not.
232+
bool GetPlayBurstSound() const { return m_PlayBurstSound; }
233+
234+
/// Sets whether this emitter will play its burst sound when appropriate or not.
235+
/// @param playBurstSound Whether this emitter should play its burst sound when appropriate or not.
236+
void SetPlayBurstSound(bool playBurstSound) { m_PlayBurstSound = playBurstSound; }
229237

230238
/// Registers a new AlarmEvent if this emitter has a loudness above zero.
231239
/// @param Team Team that will ignore this AlarmEvent.
@@ -300,6 +308,8 @@ namespace RTE {
300308
float m_BurstSpacing;
301309
// Measures the shortest possible time between bursts
302310
Timer m_BurstTimer;
311+
// Whether to play the BurstSound when a burst is triggered or not.
312+
bool m_PlayBurstSound;
303313
// The angle of the direction the emitted particles will head in.
304314
// The m_Roataion of this PEmitter will be added to this angle.
305315
Matrix m_EmitAngle;

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, AEmitter) {
340340
.property("BurstSound", &AEmitter::GetBurstSound, &LuaAdaptersPropertyOwnershipSafetyFaker::AEmitterSetBurstSound)
341341
.property("EndSound", &AEmitter::GetEndSound, &LuaAdaptersPropertyOwnershipSafetyFaker::AEmitterSetEndSound)
342342
.property("BurstScale", &AEmitter::GetBurstScale, &AEmitter::SetBurstScale)
343+
.property("PlayBurstSound", &AEmitter::GetPlayBurstSound, &AEmitter::SetPlayBurstSound)
343344
.property("EmitAngle", &AEmitter::GetEmitAngle, &AEmitter::SetEmitAngle)
344345
.property("GetThrottle", &AEmitter::GetThrottle, &AEmitter::SetThrottle)
345346
.property("Throttle", &AEmitter::GetThrottle, &AEmitter::SetThrottle)
@@ -1002,6 +1003,7 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, PEmitter) {
10021003
return ConcreteTypeLuaClassDefinition(PEmitter, MOSParticle)
10031004

10041005
.property("BurstScale", &PEmitter::GetBurstScale, &PEmitter::SetBurstScale)
1006+
.property("PlayBurstSound", &PEmitter::GetPlayBurstSound, &PEmitter::SetPlayBurstSound)
10051007
.property("EmitAngle", &PEmitter::GetEmitAngle, &PEmitter::SetEmitAngle)
10061008
.property("GetThrottle", &PEmitter::GetThrottle, &PEmitter::SetThrottle)
10071009
.property("Throttle", &PEmitter::GetThrottle, &PEmitter::SetThrottle)

0 commit comments

Comments
 (0)