From c5b3c98613c6558b135b3f8d8ae4a09745437777 Mon Sep 17 00:00:00 2001
From: FrostSalamander <108145197+FrostSalamander@users.noreply.github.com>
Date: Sat, 1 Jun 2024 13:22:00 +0100
Subject: [PATCH 01/10] wip
---
MayaImport.vcxproj.user | 4 ++++
game/Misc.cpp | 1 +
game/Misc.h | 4 ++++
game/PlayerView.cpp | 5 ++++-
sound/snd_local.h | 3 ++-
sound/snd_world.cpp | 7 ++++---
sound/sound.h | 2 +-
tools/radiant/CamWnd.cpp | 2 +-
8 files changed, 21 insertions(+), 7 deletions(-)
create mode 100644 MayaImport.vcxproj.user
diff --git a/MayaImport.vcxproj.user b/MayaImport.vcxproj.user
new file mode 100644
index 000000000..88a550947
--- /dev/null
+++ b/MayaImport.vcxproj.user
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/game/Misc.cpp b/game/Misc.cpp
index a002441da..7511743ed 100644
--- a/game/Misc.cpp
+++ b/game/Misc.cpp
@@ -2516,6 +2516,7 @@ void idLocationEntity::Spawn()
spawnArgs.Set( "location", name );
}
+ m_EfxPreset = spawnArgs.GetString("efx_preset");
m_SndLossMult = idMath::Fabs( spawnArgs.GetFloat("sound_loss_mult", "1.0") );
m_SndVolMod = spawnArgs.GetFloat( "sound_vol_offset", "0.0" );
m_ObjectiveGroup = spawnArgs.GetString( "objective_group", "" );
diff --git a/game/Misc.h b/game/Misc.h
index bc2e26838..17427bca4 100644
--- a/game/Misc.h
+++ b/game/Misc.h
@@ -444,6 +444,10 @@ class idLocationEntity : public idEntity {
const char * GetLocation( void ) const;
public:
+ /**
+ * EFX: Optional EFX preset (instead of using EFX file)
+ **/
+ idStr m_EfxPreset;
/**
* Soundprop: Loss multiplier for atmospheric attenuation
**/
diff --git a/game/PlayerView.cpp b/game/PlayerView.cpp
index 3b0c2627b..e021c0b6e 100644
--- a/game/PlayerView.cpp
+++ b/game/PlayerView.cpp
@@ -432,7 +432,10 @@ void idPlayerView::SingleView( idUserInterface *hud, const renderView_t *view, b
// place the sound origin for the player
// TODO: Support overriding the location area so that reverb settings can be applied for listening thru doors?
idVec3 p = player->GetPrimaryListenerLoc(); // grayman #4882
- gameSoundWorld->PlaceListener( p, view->viewaxis, player->entityNumber + 1, gameLocal.time, hud ? hud->State().GetString( "location" ) : "Undefined" ); // grayman #4882
+ idLocationEntity* currentLocation = player->GetLocation();
+ idStr efxPreset = currentLocation->spawnArgs.GetString("efx_preset");
+
+ gameSoundWorld->PlaceListener( p, view->viewaxis, player->entityNumber + 1, gameLocal.time, hud ? hud->State().GetString( "location" ) : "Undefined", efxPreset ); // grayman #4882
// gameSoundWorld->PlaceListener(player->GetListenerLoc(), view->viewaxis, player->entityNumber + 1, gameLocal.time, hud ? hud->State().GetString("location") : "Undefined");
// hack the shake in at the very last moment, so it can't cause any consistency problems
diff --git a/sound/snd_local.h b/sound/snd_local.h
index 56b168d6e..b3f3fbb5d 100644
--- a/sound/snd_local.h
+++ b/sound/snd_local.h
@@ -546,7 +546,7 @@ class idSoundWorldLocal : public idSoundWorld {
// where is the camera/microphone
// listenerId allows listener-private sounds to be added
- virtual void PlaceListener( const idVec3 &origin, const idMat3 &axis, const int listenerId, const int gameTime, const idStr& areaName ) override;
+ virtual void PlaceListener( const idVec3 &origin, const idMat3 &axis, const int listenerId, const int gameTime, const idStr& areaName, const idStr& efxPreset) override;
// fade all sounds in the world with a given shader soundClass
// to is in Db (sigh), over is in seconds
@@ -618,6 +618,7 @@ class idSoundWorldLocal : public idSoundWorld {
idVec3 listenerQU; // position in "quake units"
int listenerArea;
idStr listenerAreaName;
+ idStr listenerAreaEfxPreset;
ALuint listenerEffect;
ALuint listenerSlot;
ALuint listenerFilter;
diff --git a/sound/snd_world.cpp b/sound/snd_world.cpp
index 3dca3ff54..4cc88fd02 100644
--- a/sound/snd_world.cpp
+++ b/sound/snd_world.cpp
@@ -331,7 +331,7 @@ void idSoundWorldLocal::ProcessDemoCommand( idDemoFile *readDemo ) {
readDemo->ReadInt( listenerId );
readDemo->ReadInt( gameTime );
- PlaceListener( origin, axis, listenerId, gameTime, "" );
+ PlaceListener( origin, axis, listenerId, gameTime, "", "");
};
break;
case SCMD_ALLOC_EMITTER:
@@ -1152,7 +1152,7 @@ idSoundWorldLocal::PlaceListener
===================
*/
void idSoundWorldLocal::PlaceListener( const idVec3& origin, const idMat3& axis,
- const int listenerId, const int gameTime, const idStr& areaName ) {
+ const int listenerId, const int gameTime, const idStr& areaName, const idStr& efxPreset) {
int current44kHzTime;
@@ -1199,6 +1199,7 @@ void idSoundWorldLocal::PlaceListener( const idVec3& origin, const idMat3& axis,
listenerPos = origin * DOOM_TO_METERS; // meters
listenerAxis = axis;
listenerAreaName = areaName;
+ listenerAreaEfxPreset = efxPreset;
if ( rw ) {
listenerArea = rw->GetAreaAtPoint( listenerQU ); // where are we?
@@ -1573,7 +1574,7 @@ void idSoundWorldLocal::ReadFromSaveGame( idFile *savefile ) {
pause44kHz = currentSoundTime;
// place listener
- PlaceListener( origin, axis, listenerId, gameTime, "Undefined" );
+ PlaceListener( origin, axis, listenerId, gameTime, "Undefined", "");
// make sure there are enough
// slots to read the saveGame in. We don't shrink the list
diff --git a/sound/sound.h b/sound/sound.h
index 0dcaf00ae..3a4c8013d 100644
--- a/sound/sound.h
+++ b/sound/sound.h
@@ -222,7 +222,7 @@ class idSoundWorld {
// listenerId allows listener-private and antiPrivate sounds to be filtered
// gameTime is in msec, and is used to time sound queries and removals so that they are independent
// of any race conditions with the async update
- virtual void PlaceListener( const idVec3 &origin, const idMat3 &axis, const int listenerId, const int gameTime, const idStr& areaName ) = 0;
+ virtual void PlaceListener( const idVec3 &origin, const idMat3 &axis, const int listenerId, const int gameTime, const idStr& areaName, const idStr& efxPreset ) = 0;
// fade all sounds in the world with a given shader soundClass
// to is in Db (sigh), over is in seconds
diff --git a/tools/radiant/CamWnd.cpp b/tools/radiant/CamWnd.cpp
index 89c36740a..3eea07e2c 100644
--- a/tools/radiant/CamWnd.cpp
+++ b/tools/radiant/CamWnd.cpp
@@ -950,7 +950,7 @@ void CCamWnd::Cam_Draw() {
// set the sound origin for both simple draw and rendered mode
// the editor uses opposite pitch convention
idMat3 axis = idAngles( -m_Camera.angles.pitch, m_Camera.angles.yaw, m_Camera.angles.roll ).ToMat3();
- g_qeglobals.sw->PlaceListener( m_Camera.origin, axis, 0, Sys_Milliseconds(), "Undefined" );
+ g_qeglobals.sw->PlaceListener( m_Camera.origin, axis, 0, Sys_Milliseconds(), "Undefined", "");
if (renderMode) {
Cam_Render();
From 4f25156d8466406763a916e0efddf44a0d3ec831 Mon Sep 17 00:00:00 2001
From: FrostSalamander <108145197+FrostSalamander@users.noreply.github.com>
Date: Sat, 1 Jun 2024 17:44:14 +0100
Subject: [PATCH 02/10] update
---
game/Misc.cpp | 1 -
game/Misc.h | 4 ---
sound/efxlib.h | 1 +
sound/snd_efxfile.cpp | 84 +++++++++++++++++++++++--------------------
sound/snd_world.cpp | 9 +++++
5 files changed, 56 insertions(+), 43 deletions(-)
diff --git a/game/Misc.cpp b/game/Misc.cpp
index 7511743ed..a002441da 100644
--- a/game/Misc.cpp
+++ b/game/Misc.cpp
@@ -2516,7 +2516,6 @@ void idLocationEntity::Spawn()
spawnArgs.Set( "location", name );
}
- m_EfxPreset = spawnArgs.GetString("efx_preset");
m_SndLossMult = idMath::Fabs( spawnArgs.GetFloat("sound_loss_mult", "1.0") );
m_SndVolMod = spawnArgs.GetFloat( "sound_vol_offset", "0.0" );
m_ObjectiveGroup = spawnArgs.GetString( "objective_group", "" );
diff --git a/game/Misc.h b/game/Misc.h
index 17427bca4..bc2e26838 100644
--- a/game/Misc.h
+++ b/game/Misc.h
@@ -444,10 +444,6 @@ class idLocationEntity : public idEntity {
const char * GetLocation( void ) const;
public:
- /**
- * EFX: Optional EFX preset (instead of using EFX file)
- **/
- idStr m_EfxPreset;
/**
* Soundprop: Loss multiplier for atmospheric attenuation
**/
diff --git a/sound/efxlib.h b/sound/efxlib.h
index c108b9bd2..43cf971a7 100644
--- a/sound/efxlib.h
+++ b/sound/efxlib.h
@@ -47,6 +47,7 @@ class idEFXFile {
~idEFXFile();
bool FindEffect(idStr &name, ALuint *effect);
+ bool FindPreset(idToken token, idSoundEffect* effect, ALenum err);
bool LoadFile(const char *filename);
void Clear(void);
diff --git a/sound/snd_efxfile.cpp b/sound/snd_efxfile.cpp
index abbb41cc1..cb8efd944 100644
--- a/sound/snd_efxfile.cpp
+++ b/sound/snd_efxfile.cpp
@@ -252,6 +252,51 @@ bool idEFXFile::ReadEffectLegacy(idLexer &src, idSoundEffect *effect) {
return true;
}
+bool idEFXFile::FindPreset(idToken token, idSoundEffect* effect, ALenum err) {
+
+ const EFXEAXREVERBPROPERTIES* props = NULL;
+ int k = 0;
+ for (k = 0; efxPresets[k].name[0]; k++)
+ if (efxPresets[k].name == token) {
+ props = &efxPresets[k].props;
+ break;
+ }
+ if (!props && (token.type == TT_NUMBER)) {
+ int idx = token.GetIntValue();
+ if (idx >= 0 && idx < k)
+ props = &efxPresets[idx].props;
+ }
+ if (!props) {
+ //src.Error("idEFXFile::ReadEffect: Unknown preset name %s", token.c_str());
+ return false;
+ }
+
+ efxf(AL_EAXREVERB_DENSITY, props->flDensity);
+ efxf(AL_EAXREVERB_DIFFUSION, props->flDiffusion);
+ efxf(AL_EAXREVERB_GAIN, props->flGain);
+ efxf(AL_EAXREVERB_GAINHF, props->flGainHF);
+ efxf(AL_EAXREVERB_GAINLF, props->flGainLF);
+ efxf(AL_EAXREVERB_DECAY_TIME, props->flDecayTime);
+ efxf(AL_EAXREVERB_DECAY_HFRATIO, props->flDecayHFRatio);
+ efxf(AL_EAXREVERB_DECAY_LFRATIO, props->flDecayLFRatio);
+ efxf(AL_EAXREVERB_REFLECTIONS_GAIN, props->flReflectionsGain);
+ efxf(AL_EAXREVERB_REFLECTIONS_DELAY, props->flReflectionsDelay);
+ efxfv(AL_EAXREVERB_REFLECTIONS_PAN, props->flReflectionsPan[0], props->flReflectionsPan[1], props->flReflectionsPan[2]);
+ efxf(AL_EAXREVERB_LATE_REVERB_GAIN, props->flLateReverbGain);
+ efxf(AL_EAXREVERB_LATE_REVERB_DELAY, props->flLateReverbDelay);
+ efxfv(AL_EAXREVERB_LATE_REVERB_PAN, props->flLateReverbPan[0], props->flLateReverbPan[1], props->flLateReverbPan[2]);
+ efxf(AL_EAXREVERB_ECHO_TIME, props->flEchoTime);
+ efxf(AL_EAXREVERB_ECHO_DEPTH, props->flEchoDepth);
+ efxf(AL_EAXREVERB_MODULATION_TIME, props->flModulationTime);
+ efxf(AL_EAXREVERB_MODULATION_DEPTH, props->flModulationDepth);
+ efxf(AL_EAXREVERB_AIR_ABSORPTION_GAINHF, props->flAirAbsorptionGainHF);
+ efxf(AL_EAXREVERB_HFREFERENCE, props->flHFReference);
+ efxf(AL_EAXREVERB_LFREFERENCE, props->flLFReference);
+ efxf(AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, props->flRoomRolloffFactor);
+ efxi(AL_EAXREVERB_DECAY_HFLIMIT, props->iDecayHFLimit);
+
+}
+
bool idEFXFile::ReadEffectOpenAL(idLexer &src, idSoundEffect *effect) {
idToken token;
@@ -288,47 +333,10 @@ bool idEFXFile::ReadEffectOpenAL(idLexer &src, idSoundEffect *effect) {
return false;
token.ToUpper();
- const EFXEAXREVERBPROPERTIES *props = NULL;
- int k = 0;
- for (k = 0; efxPresets[k].name[0]; k++)
- if (efxPresets[k].name == token) {
- props = &efxPresets[k].props;
- break;
- }
- if (!props && (token.type == TT_NUMBER)) {
- int idx = token.GetIntValue();
- if (idx >= 0 && idx < k)
- props = &efxPresets[idx].props;
- }
- if (!props) {
- src.Error("idEFXFile::ReadEffect: Unknown preset name %s", token.c_str());
+ if (!FindPreset(token, effect, err)) {
return false;
}
- efxf(AL_EAXREVERB_DENSITY, props->flDensity);
- efxf(AL_EAXREVERB_DIFFUSION, props->flDiffusion);
- efxf(AL_EAXREVERB_GAIN, props->flGain);
- efxf(AL_EAXREVERB_GAINHF, props->flGainHF);
- efxf(AL_EAXREVERB_GAINLF, props->flGainLF);
- efxf(AL_EAXREVERB_DECAY_TIME, props->flDecayTime);
- efxf(AL_EAXREVERB_DECAY_HFRATIO, props->flDecayHFRatio);
- efxf(AL_EAXREVERB_DECAY_LFRATIO, props->flDecayLFRatio);
- efxf(AL_EAXREVERB_REFLECTIONS_GAIN, props->flReflectionsGain);
- efxf(AL_EAXREVERB_REFLECTIONS_DELAY, props->flReflectionsDelay);
- efxfv(AL_EAXREVERB_REFLECTIONS_PAN, props->flReflectionsPan[0], props->flReflectionsPan[1], props->flReflectionsPan[2]);
- efxf(AL_EAXREVERB_LATE_REVERB_GAIN, props->flLateReverbGain);
- efxf(AL_EAXREVERB_LATE_REVERB_DELAY, props->flLateReverbDelay);
- efxfv(AL_EAXREVERB_LATE_REVERB_PAN, props->flLateReverbPan[0], props->flLateReverbPan[1], props->flLateReverbPan[2]);
- efxf(AL_EAXREVERB_ECHO_TIME, props->flEchoTime);
- efxf(AL_EAXREVERB_ECHO_DEPTH, props->flEchoDepth);
- efxf(AL_EAXREVERB_MODULATION_TIME, props->flModulationTime);
- efxf(AL_EAXREVERB_MODULATION_DEPTH, props->flModulationDepth);
- efxf(AL_EAXREVERB_AIR_ABSORPTION_GAINHF, props->flAirAbsorptionGainHF);
- efxf(AL_EAXREVERB_HFREFERENCE, props->flHFReference);
- efxf(AL_EAXREVERB_LFREFERENCE, props->flLFReference);
- efxf(AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, props->flRoomRolloffFactor);
- efxi(AL_EAXREVERB_DECAY_HFLIMIT, props->iDecayHFLimit);
-
} else if ( token == "DENSITY" ) {
efxf(AL_EAXREVERB_DENSITY, src.ParseFloat());
} else if ( token == "DIFFUSION" ) {
diff --git a/sound/snd_world.cpp b/sound/snd_world.cpp
index 4cc88fd02..5ab7195a1 100644
--- a/sound/snd_world.cpp
+++ b/sound/snd_world.cpp
@@ -515,9 +515,17 @@ void idSoundWorldLocal::MixLoopInternal( int current44kHz, int numSpeakers, floa
soundSystemLocal.alAuxiliaryEffectSlotf(listenerSlot, AL_EFFECTSLOT_GAIN, gain);
}
+ // Look for effect based on area index (1, 2, etc.)
bool found = soundSystemLocal.EFXDatabase.FindEffect(s, &effect);
+
+ // Look for effect based on area (location) name
if (!found) {
s = listenerAreaName;
+
+ if (!listenerAreaEfxPreset.IsEmpty()) {
+ ALenum err;
+ soundSystemLocal.EFXDatabase.FindPreset(s, &effect, err);
+ }
found = soundSystemLocal.EFXDatabase.FindEffect(s, &effect);
}
if (!found) {
@@ -526,6 +534,7 @@ void idSoundWorldLocal::MixLoopInternal( int current44kHz, int numSpeakers, floa
}
bool justReloaded = soundSystemLocal.EFXDatabase.IsAfterReload();
+
// only update if change in settings
if (listenerEffect != effect || justReloaded) {
common->Printf("Switching to EFX '%s' (#%u)\n", s.c_str(), effect);
From d6fad8648e77e6ab55d6de7b2c5a115a0d78c3dc Mon Sep 17 00:00:00 2001
From: FrostSalamander <108145197+FrostSalamander@users.noreply.github.com>
Date: Sat, 1 Jun 2024 23:30:12 +0100
Subject: [PATCH 03/10] wip
---
sound/efxlib.h | 4 +++-
sound/snd_efxfile.cpp | 51 +++++++++++++++++++++++++++++++++++--------
sound/snd_world.cpp | 9 +++++---
3 files changed, 51 insertions(+), 13 deletions(-)
diff --git a/sound/efxlib.h b/sound/efxlib.h
index 43cf971a7..e021fe9be 100644
--- a/sound/efxlib.h
+++ b/sound/efxlib.h
@@ -47,7 +47,6 @@ class idEFXFile {
~idEFXFile();
bool FindEffect(idStr &name, ALuint *effect);
- bool FindPreset(idToken token, idSoundEffect* effect, ALenum err);
bool LoadFile(const char *filename);
void Clear(void);
@@ -55,8 +54,11 @@ class idEFXFile {
bool Reload();
bool IsAfterReload();
+ bool AddOrUpdatePreset(idStr areaName, idStr efxPreset);
+
private:
bool ReadEffectLegacy(idLexer &lexer, idSoundEffect *effect);
+ bool AddPreset(idStr token, idSoundEffect* effect, ALenum err);
bool ReadEffectOpenAL(idLexer &lexer, idSoundEffect *effect);
//filename initially passed to LoadFile (or empty if LoadFile never called)
diff --git a/sound/snd_efxfile.cpp b/sound/snd_efxfile.cpp
index cb8efd944..9198a2557 100644
--- a/sound/snd_efxfile.cpp
+++ b/sound/snd_efxfile.cpp
@@ -29,7 +29,7 @@ static inline ALfloat _mB_to_gain(ALfloat millibels, ALfloat min, ALfloat max) {
}
idSoundEffect::idSoundEffect() :
-effect(0) {
+ effect(0) {
}
idSoundEffect::~idSoundEffect() {
@@ -252,17 +252,49 @@ bool idEFXFile::ReadEffectLegacy(idLexer &src, idSoundEffect *effect) {
return true;
}
-bool idEFXFile::FindPreset(idToken token, idSoundEffect* effect, ALenum err) {
+bool idEFXFile::AddOrUpdatePreset(idStr areaName, idStr efxPreset) {
+
+ ALuint* effect = AL_EFFECTSLOT_NULL;
+ const bool found = FindEffect(areaName, effect);
+
+ if (!found) {
+ // we need to add this preset
+
+ idSoundEffect* soundEffect = new idSoundEffect;
+
+ if (!soundEffect->alloc()) {
+ delete soundEffect;
+ Clear();
+ return false;
+ }
+
+ ALenum err{};
+ bool ok;
+ ok = AddPreset(efxPreset, soundEffect, err);
+
+ if (!ok) {
+ return false;
+ }
+
+ effects.Append(soundEffect);
+ }
+
+ return true;
+}
+
+bool idEFXFile::AddPreset(idStr preset, idSoundEffect* effect, ALenum err) {
const EFXEAXREVERBPROPERTIES* props = NULL;
int k = 0;
for (k = 0; efxPresets[k].name[0]; k++)
- if (efxPresets[k].name == token) {
+ if (efxPresets[k].name == preset) {
props = &efxPresets[k].props;
break;
}
- if (!props && (token.type == TT_NUMBER)) {
- int idx = token.GetIntValue();
+
+ // Reference the preset by index instead of name.
+ if (!props && idStr::IsNumeric(preset)) {
+ int idx = atoi(preset);
if (idx >= 0 && idx < k)
props = &efxPresets[idx].props;
}
@@ -312,7 +344,7 @@ bool idEFXFile::ReadEffectOpenAL(idLexer &src, idSoundEffect *effect) {
if (!src.ExpectTokenString("{"))
return false;
- ALenum err;
+ ALenum err{};
alGetError();
common->Printf("Loading EFX effect for location '%s' (#%u)\n", name.c_str(), effect->effect);
@@ -333,10 +365,9 @@ bool idEFXFile::ReadEffectOpenAL(idLexer &src, idSoundEffect *effect) {
return false;
token.ToUpper();
- if (!FindPreset(token, effect, err)) {
+ if (!AddPreset(token, effect, err)) {
return false;
}
-
} else if ( token == "DENSITY" ) {
efxf(AL_EAXREVERB_DENSITY, src.ParseFloat());
} else if ( token == "DIFFUSION" ) {
@@ -406,7 +437,9 @@ bool idEFXFile::LoadFile( const char *filename/*, bool OSPath*/ ) {
efxFilename = filename;
src.LoadFile( filename/*, OSPath*/ );
if ( !src.IsLoaded() ) {
- return false;
+
+ // Just return true if file doesn't exist, as EFX can now be specified on location entities
+ return true;
}
if ( !src.ExpectTokenString( "Version" ) ) {
diff --git a/sound/snd_world.cpp b/sound/snd_world.cpp
index 5ab7195a1..69b6215eb 100644
--- a/sound/snd_world.cpp
+++ b/sound/snd_world.cpp
@@ -504,6 +504,7 @@ void idSoundWorldLocal::MixLoopInternal( int current44kHz, int numSpeakers, floa
alListenerfv(AL_POSITION, listenerPosition);
alListenerfv(AL_ORIENTATION, listenerOrientation);
+ // TODO: remove this after checking it's definitely not needed
if (idSoundSystemLocal::useEFXReverb && soundSystemLocal.efxloaded) {
ALuint effect = AL_EFFECTSLOT_NULL;
idStr s(listenerArea);
@@ -515,18 +516,20 @@ void idSoundWorldLocal::MixLoopInternal( int current44kHz, int numSpeakers, floa
soundSystemLocal.alAuxiliaryEffectSlotf(listenerSlot, AL_EFFECTSLOT_GAIN, gain);
}
- // Look for effect based on area index (1, 2, etc.)
+ // Look for effect based on area index (1, 2, etc.). Does anyone actually do this?
bool found = soundSystemLocal.EFXDatabase.FindEffect(s, &effect);
// Look for effect based on area (location) name
if (!found) {
s = listenerAreaName;
+ // found = soundSystemLocal.EFXDatabase.FindEffect(s, &effect);
+
if (!listenerAreaEfxPreset.IsEmpty()) {
ALenum err;
- soundSystemLocal.EFXDatabase.FindPreset(s, &effect, err);
+ soundSystemLocal.EFXDatabase.AddOrUpdatePreset(s, listenerAreaEfxPreset);
}
- found = soundSystemLocal.EFXDatabase.FindEffect(s, &effect);
+
}
if (!found) {
s = "default";
From 2d0e04d80d00fa35170f3387f1bbba98371401ae Mon Sep 17 00:00:00 2001
From: FrostSalamander <108145197+FrostSalamander@users.noreply.github.com>
Date: Sun, 2 Jun 2024 12:10:43 +0100
Subject: [PATCH 04/10] update
---
sound/efxlib.h | 2 +-
sound/snd_efxfile.cpp | 5 +++--
sound/snd_world.cpp | 3 +--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/sound/efxlib.h b/sound/efxlib.h
index e021fe9be..224d808fa 100644
--- a/sound/efxlib.h
+++ b/sound/efxlib.h
@@ -54,7 +54,7 @@ class idEFXFile {
bool Reload();
bool IsAfterReload();
- bool AddOrUpdatePreset(idStr areaName, idStr efxPreset);
+ bool AddOrUpdatePreset(idStr areaName, idStr efxPreset, ALuint* effect);
private:
bool ReadEffectLegacy(idLexer &lexer, idSoundEffect *effect);
diff --git a/sound/snd_efxfile.cpp b/sound/snd_efxfile.cpp
index 9198a2557..61ccb5d4f 100644
--- a/sound/snd_efxfile.cpp
+++ b/sound/snd_efxfile.cpp
@@ -252,9 +252,8 @@ bool idEFXFile::ReadEffectLegacy(idLexer &src, idSoundEffect *effect) {
return true;
}
-bool idEFXFile::AddOrUpdatePreset(idStr areaName, idStr efxPreset) {
+bool idEFXFile::AddOrUpdatePreset(idStr areaName, idStr efxPreset, ALuint* effect) {
- ALuint* effect = AL_EFFECTSLOT_NULL;
const bool found = FindEffect(areaName, effect);
if (!found) {
@@ -268,6 +267,8 @@ bool idEFXFile::AddOrUpdatePreset(idStr areaName, idStr efxPreset) {
return false;
}
+ soundEffect->name = areaName;
+
ALenum err{};
bool ok;
ok = AddPreset(efxPreset, soundEffect, err);
diff --git a/sound/snd_world.cpp b/sound/snd_world.cpp
index 69b6215eb..d3553c61a 100644
--- a/sound/snd_world.cpp
+++ b/sound/snd_world.cpp
@@ -504,7 +504,6 @@ void idSoundWorldLocal::MixLoopInternal( int current44kHz, int numSpeakers, floa
alListenerfv(AL_POSITION, listenerPosition);
alListenerfv(AL_ORIENTATION, listenerOrientation);
- // TODO: remove this after checking it's definitely not needed
if (idSoundSystemLocal::useEFXReverb && soundSystemLocal.efxloaded) {
ALuint effect = AL_EFFECTSLOT_NULL;
idStr s(listenerArea);
@@ -527,7 +526,7 @@ void idSoundWorldLocal::MixLoopInternal( int current44kHz, int numSpeakers, floa
if (!listenerAreaEfxPreset.IsEmpty()) {
ALenum err;
- soundSystemLocal.EFXDatabase.AddOrUpdatePreset(s, listenerAreaEfxPreset);
+ found = soundSystemLocal.EFXDatabase.AddOrUpdatePreset(s, listenerAreaEfxPreset, &effect);
}
}
From b843b6163fa1123896442b739fa713345ea00c90 Mon Sep 17 00:00:00 2001
From: FrostSalamander <108145197+FrostSalamander@users.noreply.github.com>
Date: Mon, 3 Jun 2024 20:03:17 +0100
Subject: [PATCH 05/10] update
---
sound/efxlib.h | 3 ++-
sound/snd_efxfile.cpp | 33 +++++++++++++++++++++++++++++----
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/sound/efxlib.h b/sound/efxlib.h
index 224d808fa..b0d228d5b 100644
--- a/sound/efxlib.h
+++ b/sound/efxlib.h
@@ -58,7 +58,8 @@ class idEFXFile {
private:
bool ReadEffectLegacy(idLexer &lexer, idSoundEffect *effect);
- bool AddPreset(idStr token, idSoundEffect* effect, ALenum err);
+ bool AddPreset(idStr token, idSoundEffect *effect, ALenum err);
+ bool GetEffect(idStr& name, idSoundEffect * soundEffect);
bool ReadEffectOpenAL(idLexer &lexer, idSoundEffect *effect);
//filename initially passed to LoadFile (or empty if LoadFile never called)
diff --git a/sound/snd_efxfile.cpp b/sound/snd_efxfile.cpp
index 61ccb5d4f..77468a25b 100644
--- a/sound/snd_efxfile.cpp
+++ b/sound/snd_efxfile.cpp
@@ -104,6 +104,19 @@ bool idEFXFile::FindEffect(idStr &name, ALuint *effect) {
return false;
}
+bool idEFXFile::GetEffect(idStr& name, idSoundEffect *soundEffect) {
+ int i;
+
+ for (i = 0; i < effects.Num(); i++) {
+ if (effects[i]->name.Icmp(name) == 0) {
+ *soundEffect = *effects[i];
+ return true;
+ }
+ }
+
+ return false;
+}
+
#define efxi(param, value) \
do { \
ALint _v = value; \
@@ -254,12 +267,16 @@ bool idEFXFile::ReadEffectLegacy(idLexer &src, idSoundEffect *effect) {
bool idEFXFile::AddOrUpdatePreset(idStr areaName, idStr efxPreset, ALuint* effect) {
- const bool found = FindEffect(areaName, effect);
+ idSoundEffect* soundEffect = new idSoundEffect;
+
+ //ALuint effect = AL_EFFECTSLOT_NULL;
+ const bool found = GetEffect(areaName, soundEffect);
+ ALenum err{};
+ bool ok;
if (!found) {
- // we need to add this preset
- idSoundEffect* soundEffect = new idSoundEffect;
+ // we need to add this preset
if (!soundEffect->alloc()) {
delete soundEffect;
@@ -269,7 +286,7 @@ bool idEFXFile::AddOrUpdatePreset(idStr areaName, idStr efxPreset, ALuint* effec
soundEffect->name = areaName;
- ALenum err{};
+ //ALenum err{};
bool ok;
ok = AddPreset(efxPreset, soundEffect, err);
@@ -279,7 +296,15 @@ bool idEFXFile::AddOrUpdatePreset(idStr areaName, idStr efxPreset, ALuint* effec
effects.Append(soundEffect);
}
+ else {
+ ok = AddPreset(efxPreset, soundEffect, err);
+
+ if (!ok) {
+ return false;
+ }
+ }
+ *effect = soundEffect->effect;
return true;
}
From 5f6d3cc503f781da327852b8a751c75c409024a1 Mon Sep 17 00:00:00 2001
From: FrostSalamander <108145197+FrostSalamander@users.noreply.github.com>
Date: Mon, 3 Jun 2024 20:35:11 +0100
Subject: [PATCH 06/10] fix if spawnarg not included
---
sound/snd_world.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sound/snd_world.cpp b/sound/snd_world.cpp
index d3553c61a..564f0a636 100644
--- a/sound/snd_world.cpp
+++ b/sound/snd_world.cpp
@@ -522,12 +522,13 @@ void idSoundWorldLocal::MixLoopInternal( int current44kHz, int numSpeakers, floa
if (!found) {
s = listenerAreaName;
- // found = soundSystemLocal.EFXDatabase.FindEffect(s, &effect);
-
if (!listenerAreaEfxPreset.IsEmpty()) {
ALenum err;
found = soundSystemLocal.EFXDatabase.AddOrUpdatePreset(s, listenerAreaEfxPreset, &effect);
}
+ else {
+ found = soundSystemLocal.EFXDatabase.FindEffect(s, &effect);
+ }
}
if (!found) {
From 770c514fee62163ded7b5ea578b7447f6a379a71 Mon Sep 17 00:00:00 2001
From: FrostSalamander <108145197+FrostSalamander@users.noreply.github.com>
Date: Fri, 7 Jun 2024 20:46:01 +0100
Subject: [PATCH 07/10] add missing return and remove project file
---
MayaImport.vcxproj.user | 4 ----
1 file changed, 4 deletions(-)
delete mode 100644 MayaImport.vcxproj.user
diff --git a/MayaImport.vcxproj.user b/MayaImport.vcxproj.user
deleted file mode 100644
index 88a550947..000000000
--- a/MayaImport.vcxproj.user
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
From 2425cf83bb6dd0653fd4afe9597a750651e317e8 Mon Sep 17 00:00:00 2001
From: FrostSalamander <108145197+FrostSalamander@users.noreply.github.com>
Date: Fri, 7 Jun 2024 20:49:17 +0100
Subject: [PATCH 08/10] add missing return and add project file to .gitignore
---
.gitignore | 2 ++
sound/snd_efxfile.cpp | 2 ++
2 files changed, 4 insertions(+)
diff --git a/.gitignore b/.gitignore
index eff2cd08d..08176ffe7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,5 @@ ipch/
Darkmod.log
ThirdParty/artefacts/
+
+MayaImport.vcxproj.user
diff --git a/sound/snd_efxfile.cpp b/sound/snd_efxfile.cpp
index 77468a25b..c65b2d6c8 100644
--- a/sound/snd_efxfile.cpp
+++ b/sound/snd_efxfile.cpp
@@ -353,6 +353,8 @@ bool idEFXFile::AddPreset(idStr preset, idSoundEffect* effect, ALenum err) {
efxf(AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, props->flRoomRolloffFactor);
efxi(AL_EAXREVERB_DECAY_HFLIMIT, props->iDecayHFLimit);
+ return true;
+
}
bool idEFXFile::ReadEffectOpenAL(idLexer &src, idSoundEffect *effect) {
From 756a14261f07599116590d45a5c6bf49fd96f2fa Mon Sep 17 00:00:00 2001
From: FrostSalamander <108145197+FrostSalamander@users.noreply.github.com>
Date: Fri, 7 Jun 2024 21:25:12 +0100
Subject: [PATCH 09/10] account for map not using location system
---
game/PlayerView.cpp | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/game/PlayerView.cpp b/game/PlayerView.cpp
index e021c0b6e..fe5ac45c4 100644
--- a/game/PlayerView.cpp
+++ b/game/PlayerView.cpp
@@ -432,9 +432,15 @@ void idPlayerView::SingleView( idUserInterface *hud, const renderView_t *view, b
// place the sound origin for the player
// TODO: Support overriding the location area so that reverb settings can be applied for listening thru doors?
idVec3 p = player->GetPrimaryListenerLoc(); // grayman #4882
- idLocationEntity* currentLocation = player->GetLocation();
- idStr efxPreset = currentLocation->spawnArgs.GetString("efx_preset");
+ const idLocationEntity* currentLocation = player->GetLocation();
+ idStr efxPreset;
+
+ // The map might not be using the location system
+ if (currentLocation != NULL) {
+ efxPreset = currentLocation->spawnArgs.GetString("efx_preset");
+ }
+
gameSoundWorld->PlaceListener( p, view->viewaxis, player->entityNumber + 1, gameLocal.time, hud ? hud->State().GetString( "location" ) : "Undefined", efxPreset ); // grayman #4882
// gameSoundWorld->PlaceListener(player->GetListenerLoc(), view->viewaxis, player->entityNumber + 1, gameLocal.time, hud ? hud->State().GetString("location") : "Undefined");
From 9acbcaab9581ce03cb9f13d8877fe224242a7b8f Mon Sep 17 00:00:00 2001
From: FrostSalamander <108145197+FrostSalamander@users.noreply.github.com>
Date: Sun, 9 Jun 2024 13:50:21 +0100
Subject: [PATCH 10/10] refactor AddOrUpdatePreset to only call AddPreset once
---
sound/snd_efxfile.cpp | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/sound/snd_efxfile.cpp b/sound/snd_efxfile.cpp
index c65b2d6c8..e953e0497 100644
--- a/sound/snd_efxfile.cpp
+++ b/sound/snd_efxfile.cpp
@@ -265,19 +265,26 @@ bool idEFXFile::ReadEffectLegacy(idLexer &src, idSoundEffect *effect) {
return true;
}
+/*
+===============
+idEFXFile::AddOrUpdatePreset
+
+Checks the internal list of location:sound effect mappings to see if a mapping exists for this location.
+If it doesn't exist, create a new object and add to the list.
+If it does exist, use the existing sound effect mapping.
+In both cases, the EFX database gets updated with the current preset for the location
+===============
+*/
bool idEFXFile::AddOrUpdatePreset(idStr areaName, idStr efxPreset, ALuint* effect) {
idSoundEffect* soundEffect = new idSoundEffect;
- //ALuint effect = AL_EFFECTSLOT_NULL;
const bool found = GetEffect(areaName, soundEffect);
ALenum err{};
bool ok;
if (!found) {
- // we need to add this preset
-
if (!soundEffect->alloc()) {
delete soundEffect;
Clear();
@@ -285,26 +292,19 @@ bool idEFXFile::AddOrUpdatePreset(idStr areaName, idStr efxPreset, ALuint* effec
}
soundEffect->name = areaName;
-
- //ALenum err{};
- bool ok;
- ok = AddPreset(efxPreset, soundEffect, err);
-
- if (!ok) {
- return false;
- }
-
effects.Append(soundEffect);
}
- else {
- ok = AddPreset(efxPreset, soundEffect, err);
- if (!ok) {
- return false;
- }
+ // update EFX database
+ ok = AddPreset(efxPreset, soundEffect, err);
+
+ if (!ok) {
+ return false;
}
+ // update effect - this is what's checked for change later
*effect = soundEffect->effect;
+
return true;
}