Ambient generic: stop and toggle fix: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Made it more clear for anyone that wants to fix the sound bug.)
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Insert the code that is highlighted in red, into the <code>CAmbientGeneric::SendSound</code>, located in '''src/game/server/sound.cpp''' (Line 878) to overcome the Sound bug.
Insert the code that is highlighted, into the <code>CAmbientGeneric::SendSound( SoundFlags_t flags)</code>, located in '''src\game\server\sound.cpp''' (line 878) to overcome the Sound bug:
<source lang=cpp highlight=7,14-19,29>
if ( pSoundSource )
{
if ( flags == SND_STOP )
{
UTIL_EmitAmbientSound(pSoundSource->GetSoundSourceIndex(), pSoundSource->GetAbsOrigin(), szSoundFile,
0, SNDLVL_NONE, flags, 0);
m_fActive = false;
}
else
{
UTIL_EmitAmbientSound(pSoundSource->GetSoundSourceIndex(), pSoundSource->GetAbsOrigin(), szSoundFile,
(m_dpv.vol * 0.01), m_iSoundLevel, flags, m_dpv.pitch);


if ( pSoundSource )
// Only mark active if this is a looping sound.
{
// If not looping, each trigger will cause the sound to play.
if ( flags == SND_STOP )
// If the sound is still playing from a previous trigger press,  
{
// it will be shut off and then restarted.
UTIL_EmitAmbientSound(pSoundSource->GetSoundSourceIndex(), pSoundSource->GetAbsOrigin(), szSoundFile,
if ( m_fLooping )
0, SNDLVL_NONE, flags, 0);
m_fActive = true;
<span style="color:red">m_fActive = false;</span>
}
}
}
else
else
{
{
UTIL_EmitAmbientSound(pSoundSource->GetSoundSourceIndex(), pSoundSource->GetAbsOrigin(), szSoundFile,
if ( ( flags == SND_STOP ) &&  
(m_dpv.vol * 0.01), m_iSoundLevel, flags, m_dpv.pitch);
( m_nSoundSourceEntIndex != -1 ) )
{
<span style="color:red">// Only mark active if this is a looping sound. If not looping, each
UTIL_EmitAmbientSound(m_nSoundSourceEntIndex, GetAbsOrigin(), szSoundFile,  
// trigger will cause the sound to play. If the sound is still
0, SNDLVL_NONE, flags, 0);
// playing from a previous trigger press, it will be shut off
m_fActive = false;
// and then restarted.
}
}
if (m_fLooping)
</source>
m_fActive = true;</span>
}
}
else
{
if ( ( flags == SND_STOP ) &&  
( m_nSoundSourceEntIndex != -1 ) )
{
UTIL_EmitAmbientSound(m_nSoundSourceEntIndex, GetAbsOrigin(), szSoundFile,  
0, SNDLVL_NONE, flags, 0);
<span style="color:red">m_fActive = false;</span>
}
}


This moves the job of setting m_fActive to the very top of the chain, denying any ambient_generic function wriggle room to escape it! This opens up the use of the ''volume'' and ''pitch'' inputs, and allows you to safely start a sound with a map.
This moves the job of setting <code>m_fActive</code> to the very top of the chain, denying any [[ambient_generic]] function wriggle room to escape it!
 
This opens up the use of the '''volume''' and '''pitch''' inputs, and allows you to safely start a sound with a map.


== See also ==
== See also ==

Latest revision as of 19:49, 13 September 2020

Insert the code that is highlighted, into the CAmbientGeneric::SendSound( SoundFlags_t flags), located in src\game\server\sound.cpp (line 878) to overcome the Sound bug:

	if ( pSoundSource )
	{
		if ( flags == SND_STOP )
		{
			UTIL_EmitAmbientSound(pSoundSource->GetSoundSourceIndex(), pSoundSource->GetAbsOrigin(), szSoundFile, 
						0, SNDLVL_NONE, flags, 0);
			m_fActive = false;
		}
		else
		{
			UTIL_EmitAmbientSound(pSoundSource->GetSoundSourceIndex(), pSoundSource->GetAbsOrigin(), szSoundFile, 
				(m_dpv.vol * 0.01), m_iSoundLevel, flags, m_dpv.pitch);

			// Only mark active if this is a looping sound.
			// If not looping, each trigger will cause the sound to play.
			// If the sound is still playing from a previous trigger press, 
			// it will be shut off and then restarted.
			if ( m_fLooping )
				m_fActive = true;
		}
	}	
	else
	{
		if ( ( flags == SND_STOP ) && 
			( m_nSoundSourceEntIndex != -1 ) )
		{
			UTIL_EmitAmbientSound(m_nSoundSourceEntIndex, GetAbsOrigin(), szSoundFile, 
					0, SNDLVL_NONE, flags, 0);
			m_fActive = false;
		}
	}

This moves the job of setting m_fActive to the very top of the chain, denying any ambient_generic function wriggle room to escape it!

This opens up the use of the volume and pitch inputs, and allows you to safely start a sound with a map.

See also