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

Commit 13893c0

Browse files
authored
Merge pull request #254 from cortex-command-community/CF112-FMOD-Fixes
Cf112 fmod fixes
2 parents 020d2ee + f80bb01 commit 13893c0

31 files changed

+1625
-997
lines changed

CHANGELOG.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,32 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
143143

144144
- Added new lua `Vector` functions: `GetRadRotated(angle)` and `GetDegRotated(angle)`. They return a rotated copy of the vector without modifying it.
145145

146+
- Added `Enum` binding for `SoundSet.SoundSelectionCycleMode`: `RANDOM = 0, FORWARDS = 1, ALL = 2`.
147+
148+
- Added `Enum` binding for `SoundContainer.SoundOverlapMode`: `OVERLAP = 0, RESTART = 1, IGNORE_PLAY = 2`.
149+
150+
- New `SoundContainer` function `Restart`, which allows you to restart a playing `SoundContainer`. Also another `Play` function, that lets you just specify the player to play the sound for.
151+
152+
- New `HDFirearm` INI property `PreFireSound`, which allows you to specify a sound that will play exactly once before the weapon fires.
153+
Note that this was designed primarily for things like flamethrowers, semi-auto weapons may wonky with it, and full-auto weapons may fire multiple shots in the first burst, if you don't also set an `ActivationDelay`.
154+
155+
- `SoundSets` have been made a bit more fully featured, they can now have sub `SoundSets` and their own `SoundSelectionCycleMode` and they now have a Lua binding so you can create them in Lua with `local mySoundSet = SoundSet()`.
156+
They have the following INI and Lua properties:
157+
158+
`SoundSelectionCycleMode` (INI and Lua R/W) - Determines how sounds in this `SoundSet` will be selected each time it is played (or when `SelectNextSounds` is called).
159+
Note that sub `SoundSets` can have different `SoundSelectionCycleModes`. `SoundSets` with sub `SoundSets` and sounds whose `SoundSelectionCycleMode` is `FORWARDS` will first go through their sounds, then each sub `SoundSet`.
160+
161+
`soundSet.SubSoundSets` (Lua R) - An iterator over the sub `SoundSets` of this `SoundSet`, allowing you to manipulate them as you would any `SoundSet`.
162+
`soundSet:HasAnySounds(includeSubSoundSets)` (Lua) - Whether or not this `SoundSet` has any sounds, optionally including its sub `SoundSets`.
163+
`soundSet:SelectNextSounds()` (Lua) - Selects the next sounds for this `SoundSet`. Note that playing a `SoundContainer` will always also do this, so this is only really useful to allow you to skip sounds when `SoundSelectionCycleMode` is set to `FORWARDS`.
164+
`soundSet:AddSound("Path/to/sound")` (Lua) - Adds the sound at the given path with no offset, 0 minimum audible distance, and default attenuation start distance.
165+
`soundSet:AddSound("Path/to/sound", offset, minimumAudibleDistance, attenuationStartDistance)` (Lua) - Adds the sound at the given path with the given parameters.
166+
`soundSet:AddSoundSet(soundSetToAdd)` (Lua) - Adds the given `SoundSet` as a sub `SoundSet` of this `SoundSet`.
167+
168+
Additionally, `AddSound` and `AddSoundSet` INI properties work for `SoundSets`. They are exactly the same as they are for `SoundContainers`.
169+
170+
- You can get the top level `SoundSet` of a `SoundContainer` with `soundContainer:GetTopLevelSoundSet` and manipulate it as described above. This allows you full interaction with all levels of `SoundSets` in a `SoundContainer`.
171+
146172
### Changed
147173

148174
- Codebase now uses the C++17 standard.
@@ -236,6 +262,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
236262

237263
- `Scenes` with a `PresetName` containing the strings "Test", "Editor" and "Tutorial" are no longer excluded from the scenarios screen and from the MetaGame.
238264

265+
- `SoundContainer` is now a concrete Lua entity. This means it can now be created with `CreateSoundContainer("PresetName", "DataModule.rte")` and has all the standard functionality like cloning, etc.
266+
To support these changes, a bunch of Lua functionality has been added and modified:
267+
268+
`soundContainer.Immobile` - Whether or not the `SoundContainer` is immobile. Immobile sounds are generally used for GUI elements and will never be automatically panned, pitched or attenuated.
269+
`soundContainer.AttenuationStartDistance` - Formerly INI only, this property is now gettable and settable through Lua. See previous changelog entries for details on it.
270+
`soundContainer.Pos` - Rather than updating the `SoundContainer's` position through `AudioMan`, you should now use the `Pos` property.
271+
`soundContainer.Volume` - In addition to attenuation based volume changes, it is now possible to set a `SoundContainer's` overall volume. This works together with volume changes caused by attenuation.
272+
`soundContainer.Pitch` - Rather than updating the `SoundContainer's` pitch through `AudioMan`, you should now use the `Pitch` property. Also note that this now works properly with the game's global pitch so no complicated handling is necessary.
273+
274+
- `AddSound` and `SelectNextSoundSet` Lua bindings have been moved from `SoundContainer` to `SoundSet`. The latter has been renamed and the former have been trimmed down slightly since some complexity is no longer needed. Their speciifcs are mentioned in the `Added` section.
275+
239276
### Fixed
240277

241278
- Fix crash when returning to `MetaGame` scenario screen after activity end.
@@ -260,6 +297,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
260297

261298
- Pressing escape at the options, mod manager, game editors and credits screens no longer quits the game.
262299

300+
- `HDFirearm` INI property `DeactivationSound` now works properly instead of constantly playing.
301+
302+
- Gold mining sound has been set to restart its playback everytime it's played, making it way less annoying. It's still pretty wonky, but it's better.
303+
304+
- Sound panning should now work properly around scene seams. Additionally, sounds should be less stuttery (e.g. distant jetpacks) and generally sound better.
305+
263306
### Removed
264307

265308
- Removed the ability to remove scripts from objects with Lua. This is no longer needed cause of code efficiency increases.
@@ -276,6 +319,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
276319

277320
- Removed `Activity` property `FundsOfTeam#`, use `Team#Funds` instead.
278321

322+
- Some functionality has been moved from `AudioMan` to `SoundContainer`. As such, the following `AudioMan` Lua bindings are no longer available:
323+
`SetSoundPosition(soundContainer)`, `SetSoundPitch(soundContainer`, `PlaySound(filePath, position, player, loops, priority, pitchOrAffectedByGlobalPitch`, `attenuationStartDistance, immobile)`
324+
325+
The lengthy `PlaySound` function should be replaced by making a `SoundContainer` in your `Create` function and setting properties appropriately.
326+
This can be done by creating one defined INI with `soundContainer = CreateSoundContainer(...)`, or by making an empty one with `soundContainer = SoundContainer()`.
327+
279328
***
280329

281330
## [0.1.0 pre-release 2][0.1.0-pre2] - 2020/05/08

Entities/ADoor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ namespace RTE {
422422
m_SpriteAnimDuration = LERP(0, m_MaxHealth, 10, m_InitialSpriteAnimDuration, m_Health);
423423

424424
if (!m_DoorMoveSound.IsBeingPlayed()) { m_DoorMoveSound.Play(m_Pos); }
425-
g_AudioMan.SetSoundPitch(&m_DoorMoveSound, LERP(10, m_InitialSpriteAnimDuration, 2, 1, m_SpriteAnimDuration) * g_AudioMan.GetGlobalPitch());
425+
m_DoorMoveSound.SetPitch(LERP(10, m_InitialSpriteAnimDuration, 2, 1, m_SpriteAnimDuration));
426426

427427
m_Health -= 0.4F;
428428
}

Entities/HDFirearm.cpp

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ void HDFirearm::Clear()
3535
m_pMagazine = 0;
3636

3737
m_pFlash = 0;
38+
m_PreFireSound.Reset();
3839
m_FireSound.Reset();
40+
m_FireEchoSound.Reset();
3941
m_ActiveSound.Reset();
4042
m_DeactivationSound.Reset();
4143
m_EmptySound.Reset();
@@ -111,7 +113,9 @@ int HDFirearm::Create(const HDFirearm &reference)
111113
m_pFlash = dynamic_cast<Attachable *>(reference.m_pFlash->Clone());
112114
m_pFlash->Attach(this, m_pFlash->GetParentOffset());
113115
}
116+
m_PreFireSound = reference.m_PreFireSound;
114117
m_FireSound = reference.m_FireSound;
118+
m_FireEchoSound = reference.m_FireEchoSound;
115119
m_ActiveSound = reference.m_ActiveSound;
116120
m_DeactivationSound = reference.m_DeactivationSound;
117121
m_EmptySound = reference.m_EmptySound;
@@ -172,15 +176,20 @@ int HDFirearm::ReadProperty(std::string propName, Reader &reader)
172176
if (m_pFlash)
173177
m_pFlash->Attach(this);
174178
}
175-
}
176-
else if (propName == "FireSound")
179+
} else if (propName == "PreFireSound") {
180+
reader >> m_PreFireSound;
181+
m_DeactivationSound.SetSoundOverlapMode(SoundContainer::SoundOverlapMode::IGNORE_PLAY);
182+
} else if (propName == "FireSound")
177183
reader >> m_FireSound;
178-
else if (propName == "ActiveSound") {
184+
else if (propName == "FireEchoSound") {
185+
reader >> m_FireEchoSound;
186+
m_FireEchoSound.SetSoundOverlapMode(SoundContainer::SoundOverlapMode::RESTART);
187+
} else if (propName == "ActiveSound") {
179188
reader >> m_ActiveSound;
180-
m_ActiveSound.SetAffectedByGlobalPitch(false); //Active sound (i.e. weapon spinup) modifies its pitch, so it has to account for global pitch on its own.
181-
} else if (propName == "DeactivationSound")
189+
} else if (propName == "DeactivationSound") {
182190
reader >> m_DeactivationSound;
183-
else if (propName == "EmptySound")
191+
m_DeactivationSound.SetSoundOverlapMode(SoundContainer::SoundOverlapMode::IGNORE_PLAY);
192+
} else if (propName == "EmptySound")
184193
reader >> m_EmptySound;
185194
else if (propName == "ReloadStartSound")
186195
reader >> m_ReloadStartSound;
@@ -254,8 +263,12 @@ int HDFirearm::Save(Writer &writer) const
254263
writer << m_pMagazine;
255264
writer.NewProperty("Flash");
256265
writer << m_pFlash;
266+
writer.NewProperty("PreFireSound");
267+
writer << m_PreFireSound;
257268
writer.NewProperty("FireSound");
258269
writer << m_FireSound;
270+
writer.NewProperty("FireEchoSound");
271+
writer << m_FireEchoSound;
259272
writer.NewProperty("ActiveSound");
260273
writer << m_ActiveSound;
261274
writer.NewProperty("DeactivationSound");
@@ -312,7 +325,9 @@ void HDFirearm::Destroy(bool notInherited)
312325
{
313326
delete m_pMagazine;
314327
delete m_pFlash;
328+
m_PreFireSound.Stop();
315329
m_FireSound.Stop();
330+
m_FireEchoSound.Stop();
316331
m_ActiveSound.Stop();
317332
m_DeactivationSound.Stop();
318333

@@ -555,13 +570,14 @@ void HDFirearm::SetID(const MOID newID)
555570
// Description: Activates one of this HDFirearm's features. Analogous to 'pulling
556571
// the trigger'.
557572

558-
void HDFirearm::Activate()
559-
{
573+
void HDFirearm::Activate() {
574+
bool wasActivated = m_Activated;
560575
HeldDevice::Activate();
561576

562-
// Play the pre-fire sound
563-
if (!IsReloading() && !m_ActiveSound.IsBeingPlayed())
564-
m_ActiveSound.Play(this->m_Pos);
577+
if (!IsReloading()) {
578+
if (!m_ActiveSound.IsBeingPlayed()) { m_ActiveSound.Play(this->m_Pos); }
579+
if (!wasActivated && !m_PreFireSound.IsBeingPlayed()) { m_PreFireSound.Play(this->m_Pos); }
580+
}
565581
}
566582

567583

@@ -571,18 +587,14 @@ void HDFirearm::Activate()
571587
// Description: Deactivates one of this HDFirearm's features. Analogous to 'releasing
572588
// the trigger'.
573589

574-
void HDFirearm::Deactivate()
575-
{
590+
void HDFirearm::Deactivate() {
591+
bool wasActivated = m_Activated;
576592
HeldDevice::Deactivate();
577593
m_FiredOnce = false;
578594

579-
// Stop any looping fire sounds
580-
if (m_FireSound.GetLoopSetting() == -1 && m_FireSound.IsBeingPlayed())
581-
m_FireSound.Stop();
582-
583-
// Play the post-fire sound
584-
if (!m_DeactivationSound.IsBeingPlayed())
585-
m_DeactivationSound.Play(m_Pos);
595+
m_PreFireSound.Stop();
596+
if (m_FireSound.GetLoopSetting() == -1) { m_FireSound.Stop(); }
597+
if (wasActivated && m_pMagazine && !m_pMagazine->IsEmpty() && !m_DeactivationSound.IsBeingPlayed()) { m_DeactivationSound.Play(m_Pos); }
586598
}
587599

588600
//////////////////////////////////////////////////////////////////////////////////////////
@@ -691,6 +703,8 @@ void HDFirearm::Update()
691703
{
692704
HeldDevice::Update();
693705

706+
if (m_PreFireSound.IsBeingPlayed()) { m_PreFireSound.SetPosition(m_Pos); }
707+
if (m_FireSound.IsBeingPlayed()) { m_FireSound.SetPosition(m_Pos); }
694708
if (m_ActiveSound.IsBeingPlayed()) { m_ActiveSound.SetPosition(m_Pos); }
695709
if (m_DeactivationSound.IsBeingPlayed()) { m_DeactivationSound.SetPosition(m_Pos); }
696710

@@ -708,8 +722,7 @@ void HDFirearm::Update()
708722

709723
if (m_pMagazine && !m_pMagazine->IsEmpty())
710724
{
711-
if (m_Activated)
712-
{
725+
if (m_Activated && !m_PreFireSound.IsBeingPlayed()) {
713726

714727
// Get the parent root of this AEmitter
715728
// TODO: Potentially get this once outside instead, like in attach/detach")
@@ -908,6 +921,7 @@ void HDFirearm::Update()
908921
{
909922
// Play empty pin click sound.
910923
m_EmptySound.Play(m_Pos);
924+
m_DeactivationSound.Play(m_Pos);
911925
// Indicate that we have clicked once during the current activation.
912926
m_AlreadyClicked = true;
913927

@@ -927,6 +941,8 @@ void HDFirearm::Update()
927941
m_ActivationTimer.Reset();
928942
m_ActivationTimer.Reset();
929943
m_LastFireTmr.Reset();
944+
945+
if (m_Activated) { m_PreFireSound.Play(); }
930946
}
931947

932948
m_Reloading = false;
@@ -939,6 +955,7 @@ void HDFirearm::Update()
939955
// Reset the click indicator.
940956
m_AlreadyClicked = false;
941957

958+
m_PreFireSound.Stop();
942959
// Stop any looping activation sounds
943960
if (m_FireSound.GetLoopSetting() == -1)// && m_FireSound.IsBeingPlayed())
944961
m_FireSound.Stop();
@@ -987,8 +1004,12 @@ void HDFirearm::Update()
9871004

9881005
// Play firing sound
9891006
// Only start playing if it's not a looping fire sound that is already playing, and if there's a mag
990-
if (!(m_FireSound.GetLoopSetting() == -1 && m_FireSound.IsBeingPlayed()) && m_pMagazine)
991-
m_FireSound.Play(m_Pos);
1007+
if (m_pMagazine) {
1008+
if (!(m_FireSound.GetLoopSetting() == -1 && m_FireSound.IsBeingPlayed())) {
1009+
m_FireSound.Play(m_Pos);
1010+
}
1011+
m_FireEchoSound.Play(m_Pos);
1012+
}
9921013
}
9931014
else {
9941015
m_Recoiled = false;
@@ -1009,13 +1030,13 @@ void HDFirearm::Update()
10091030
if (m_Activated && !m_Reloading && m_ActivationTimer.GetElapsedSimTimeMS() < m_ActivationDelay)
10101031
{
10111032
animDuration = (int)LERP(0, m_ActivationDelay, (float)(m_SpriteAnimDuration * 10), (float)m_SpriteAnimDuration, m_ActivationTimer.GetElapsedSimTimeMS());
1012-
g_AudioMan.SetSoundPitch(&m_ActiveSound, LERP(0, m_ActivationDelay, 0, 1.0, m_ActivationTimer.GetElapsedSimTimeMS()) * g_AudioMan.GetGlobalPitch());
1033+
m_ActiveSound.SetPitch(LERP(0, m_ActivationDelay, 0, 1.0, m_ActivationTimer.GetElapsedSimTimeMS()));
10131034
}
10141035
// Spin down
10151036
if ((!m_Activated || m_Reloading) && m_LastFireTmr.GetElapsedSimTimeMS() < m_DeactivationDelay)
10161037
{
10171038
animDuration = (int)LERP(0, m_DeactivationDelay, (float)m_SpriteAnimDuration, (float)(m_SpriteAnimDuration * 10), m_LastFireTmr.GetElapsedSimTimeMS());
1018-
g_AudioMan.SetSoundPitch(&m_ActiveSound, LERP(0, m_DeactivationDelay, 1.0, 0, m_LastFireTmr.GetElapsedSimTimeMS()) * g_AudioMan.GetGlobalPitch());
1039+
m_ActiveSound.SetPitch(LERP(0, m_DeactivationDelay, 1.0, 0, m_LastFireTmr.GetElapsedSimTimeMS()));
10191040
}
10201041

10211042
if (animDuration > 0 && !(m_Reloading && m_LastFireTmr.GetElapsedSimTimeMS() >= m_DeactivationDelay))

Entities/HDFirearm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,10 @@ ClassInfoGetters
741741
// Muzzle Flash Attachable. Owned
742742
Attachable *m_pFlash;
743743

744+
SoundContainer m_PreFireSound; //!< The sound this HDFirearm should play before it starts firing. Distinct from activation sound in that it will play exactly once per trigger pull and not pitch up.
744745
// The audio of this FireArm being fired.
745746
SoundContainer m_FireSound;
747+
SoundContainer m_FireEchoSound; //!< The audio that is played as the echo for the gun. Each shot will restart this sound, so it doesn't ever overlap.
746748
// The audio that is played immediately upon activation, but perhaps before actual first firing, if there's a pre-delay
747749
SoundContainer m_ActiveSound;
748750
// The audio that is played immediately upon cease of activation

0 commit comments

Comments
 (0)