Ambient generic: stop and toggle fix

From Valve Developer Community
Revision as of 18:51, 2 March 2008 by TomEdwards (talk | contribs) (fix code)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Insert code in red into CAmbientGeneric::SendSound to overcome "unstoppable sound" issues:

	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