Fix for hang on exit.

Also change fmod to not load if cl_ambientsoun is 0 and made this cvar 0-100 to match the music volume cvar.
This commit is contained in:
pierow 2023-09-07 14:28:49 -04:00
parent 3d5cb0bc6d
commit a4970388ef
4 changed files with 31 additions and 23 deletions

View file

@ -90,28 +90,28 @@ void AvHAmbientSound::UpdateVolume(const Vector& inListenerPosition)
{ {
if(this->mInitialized) if(this->mInitialized)
{ {
Vector theDistanceVector = inListenerPosition - this->mPosition; Vector theDistanceVector = inListenerPosition - this->mPosition;
float theDistance = sqrt(theDistanceVector[0]*theDistanceVector[0] + theDistanceVector[1]*theDistanceVector[1] + theDistanceVector[2]*theDistanceVector[2]); float theDistance = sqrt(theDistanceVector[0]*theDistanceVector[0] + theDistanceVector[1]*theDistanceVector[1] + theDistanceVector[2]*theDistanceVector[2]);
//FSOUND_SetPan(this->mChannel, FSOUND_STEREOPAN); //FSOUND_SetPan(this->mChannel, FSOUND_STEREOPAN);
int theVolume = this->mVolume; int theVolume = this->mVolume;
if(this->mFadeDistance > 0) if(this->mFadeDistance > 0)
{ {
theVolume = this->mVolume - this->mVolume*(theDistance/(float)this->mFadeDistance); theVolume = this->mVolume - this->mVolume*(theDistance/(float)this->mFadeDistance);
} }
float ambientscale = (CVAR_GET_FLOAT("cl_ambientsound")); float ambientscale = CVAR_GET_FLOAT("cl_ambientsound") * 0.01f;
ambientscale = min(max(0, ambientscale), 1); ambientscale = min(max(0, ambientscale), 1);
theVolume = min(max(0, theVolume), 255); theVolume = min(max(0, theVolume), 255);
theVolume *= ambientscale; theVolume *= ambientscale;
FMOD_INSTANCE* theFMOD = gHUD.GetFMOD(); FMOD_INSTANCE* theFMOD = gHUD.GetFMOD();
if (theFMOD) if (theFMOD)
{ {
theFMOD->FSOUND_SetVolume(this->mChannel, theVolume); theFMOD->FSOUND_SetVolume(this->mChannel, theVolume);
} }
} }
} }

View file

@ -6524,7 +6524,9 @@ void AvHHud::UpdateAmbientSounds()
for(AmbientSoundListType::iterator theIter = this->mAmbientSounds.begin(); theIter != this->mAmbientSounds.end(); theIter++) for(AmbientSoundListType::iterator theIter = this->mAmbientSounds.begin(); theIter != this->mAmbientSounds.end(); theIter++)
{ {
theIter->StartPlayingIfNot(); if (CVAR_GET_FLOAT("cl_ambientsound") != 0)
theIter->StartPlayingIfNot();
theIter->UpdateVolume(theListenerPosition); theIter->UpdateVolume(theListenerPosition);
} }
} }

View file

@ -530,7 +530,8 @@ int UIHud::Redraw(float flTime, int intermission)
} }
// Initialize music the first time through // Initialize music the first time through
this->InitializeSound(); if (CVAR_GET_FLOAT("cl_ambientsound") != 0)
this->InitializeSound();
} }
string theErrorString; string theErrorString;
@ -568,9 +569,10 @@ void UIHud::ShutdownMusic(void)
this->StopInternetStream(); this->StopInternetStream();
mFMOD->FSOUND_Close(); ////Commented out to fix the dreaded hang on exit! Let HL and the OS take care of it.
//mFMOD->FSOUND_Close();
FMOD_FreeInstance(mFMOD); //
//FMOD_FreeInstance(mFMOD);
mFMOD = NULL; mFMOD = NULL;
this->mSoundInitialized = false; this->mSoundInitialized = false;
@ -623,13 +625,17 @@ void UIHud::ToggleMouse(void)
bool UIHud::Update(float inCurrentTime, string& outError) bool UIHud::Update(float inCurrentTime, string& outError)
{ {
this->mManager.Update(inCurrentTime); this->mManager.Update(inCurrentTime);
this->UpdateMusic(inCurrentTime); bool theSuccess = true;
if (CVAR_GET_FLOAT("cl_ambientsound") != 0) {
this->UpdateMusic(inCurrentTime);
bool theSuccess = this->UpdateInternetStream(inCurrentTime, outError); //bool theSuccess = this->UpdateInternetStream(inCurrentTime, outError);
theSuccess = this->UpdateInternetStream(inCurrentTime, outError);
}
return theSuccess; return theSuccess;
} }
int UIHud::UpdateClientData(client_data_t *cdata, float time) int UIHud::UpdateClientData(client_data_t *cdata, float time)

View file

@ -50,7 +50,7 @@ DESCRIPTION INFO_OPTIONS
"cl_ambientsound" "cl_ambientsound"
{ {
"Ambient sound volume (0 to 1)" "Ambient sound volume (0 to 100)"
{ NUMBER 0.000000 1.000000 } { NUMBER 0.000000 1.000000 }
{ "0.000000" } { "0.000000" }
} }