ISound* CCE3SoundWrapper::GetPreferredSound()
    {
        // Return last preferred sound if he is still consistent, else search a new one
        ISound* pPreferredSound = NULL;
        ISound* pFallbackSound = NULL; // better then nothing...

        // last preferred source still there?
        if ( gEnv && gEnv->pSoundSystem )
        {
            pPreferredSound = gEnv->pSoundSystem->GetSound( m_nPreferredDataSource );
        }

        // is his playback state still consistent?
        if ( pPreferredSound && pPreferredSound->IsLoaded() && pPreferredSound->IsInitialized() && PLAYSTATE_CONSISTENT( pPreferredSound ) )
        {
            goto success;
        }

        // If not the check the 2d sound
        if ( Is2DSoundActive() && PLAYSTATE_CONSISTENT( m_p2DSound ) )
        {
            m_nPreferredDataSource = m_p2DSound->GetId();
            pPreferredSound = m_p2DSound;
            goto success;
        }

        pFallbackSound = m_p2DSound; // better then nothing...

        // Or one from the proxies
        for ( tEntitySoundProxyMap::iterator iterSound = m_SoundProxies.begin(); iterSound != m_SoundProxies.end(); ++iterSound )
        {
            if ( iterSound->second.IsActive() && PLAYSTATE_CONSISTENT( iterSound->second.GetSound() ) )
            {
                pPreferredSound = iterSound->second.GetSound();
                m_nPreferredDataSource = pPreferredSound->GetId();

                goto success;
            }

            // better then nothing...
            if ( !pFallbackSound && iterSound->second.IsExisting() )
            {
                pFallbackSound = iterSound->second.GetSound();
            }
        }

        // if nothing reliable was found
        m_nPreferredDataSource = INVALID_SOUNDID;

        if ( pFallbackSound )
        {
            return pFallbackSound;
        }

        return NULL;
success:
        // RefreshMaxDuration( pPreferredSound );
        return pPreferredSound;
    }
Пример #2
0
//------------------------------------------------------------------------
void CProjectile::RicochetSound(const Vec3 &pos, const Vec3 &dir)
{
	if (!m_pAmmoParams->pRicochet)
		return;

	ISound *pSound = gEnv->pSoundSystem->CreateSound(m_pAmmoParams->pRicochet->sound, FLAG_SOUND_DEFAULT_3D|FLAG_SOUND_SELFMOVING);
	if (pSound)
	{
		pSound->GetId();
		pSound->SetSemantic(eSoundSemantic_Projectile);
		pSound->SetPosition(pos);
		pSound->SetDirection(dir*m_pAmmoParams->pRicochet->speed);
		pSound->Play();
	}
}
Пример #3
0
// add enum of sound you want to play, and add command to game code at appropiate spot
void CGameAudio::PlaySound(EGameAudioSounds eSound, IEntity *pEntity, float param, bool stopSound)
{
	int soundFlag = 0; //localActor will get 2D sounds
	ESoundSemantic eSemantic = eSoundSemantic_None;
	ISound *pSound = NULL;
	bool	setParam = false;
	static string soundName;
	soundName.resize(0);

	switch(eSound)
	{
	case EGameAudioSound_NOSOUND:
		break;

	case EGameAudioSound_LAST:
		break;

	default:
		break;
	}

	//if(!force3DSound && m_pOwner == m_pGameFramework->GetClientActor() && !m_pOwner->IsThirdPerson() && soundName.size())
	//{
	//	if (bAppendPostfix)
	//		soundName.append("_fp");
	//}

	IEntitySoundProxy *pSoundProxy = pEntity ? (IEntitySoundProxy *)pEntity->CreateProxy(ENTITY_PROXY_SOUND) : NULL;

	if(soundName.size() && eSound < EGameAudioSound_LAST)		//get / create or stop sound
	{
		if(m_sounds[eSound].ID != INVALID_SOUNDID)
		{
			if(pSoundProxy)
				pSound = pSoundProxy->GetSound(m_sounds[eSound].ID);
			else
				pSound = gEnv->pSoundSystem->GetSound(m_sounds[eSound].ID);

			if(stopSound)
			{
				if(pSound)
					pSound->Stop();

				m_sounds[eSound].ID = INVALID_SOUNDID;
				return;
			}
		}

		if(!pSound && !stopSound)
		{
			pSound = gEnv->pSoundSystem->CreateSound(soundName, soundFlag);

			if(pSound)
			{
				pSound->SetSemantic(eSemantic);
				//float fTemp = 0.0f;
				m_sounds[eSound].ID = pSound->GetId();
				m_sounds[eSound].bLooping = (pSound->GetFlags() & FLAG_SOUND_LOOP) != 0;
				m_sounds[eSound].b3D = (pSound->GetFlags() & FLAG_SOUND_3D) != 0;
				//m_sounds[eSound].nMassIndex = pSound->GetParam("mass", &fTemp, false);
				//m_sounds[eSound].nSpeedIndex = pSound->GetParam("speed", &fTemp, false);
				//m_sounds[eSound].nStrengthIndex = pSound->GetParam("strength", &fTemp, false);
			}
		}
	}

	if(pSound)		//set params and play
	{
		//pSound->SetPosition(m_pOwner->GetEntity()->GetWorldPos());

		if(setParam)
		{
			//if (m_sounds[eSound].nMassIndex != -1)
			//	pSound->SetParam(m_sounds[sound].nMassIndex, param);

			//if (m_sounds[eSound].nSpeedIndex != -1)
			//	pSound->SetParam(m_sounds[sound].nSpeedIndex, param);

			//if (m_sounds[eSound].nStrengthIndex != -1)
			//	pSound->SetParam(m_sounds[sound].nStrengthIndex, param);
		}

		if(!(m_sounds[eSound].bLooping && pSound->IsPlaying()))
		{
			if(pSoundProxy)
				pSoundProxy->PlaySound(pSound);
			else
				pSound->Play();
		}
	}
}