// CONSIDER: if player in water state, autoset and underwater soundscape? void CEnvSoundscape::UpdateForPlayer( ss_update_t &update ) { if ( !IsEnabled() ) { if ( update.pCurrentSoundscape == this ) { update.pCurrentSoundscape = NULL; update.currentDistance = 0; update.bInRange = false; } return; } // calc range from sound entity to player Vector target = EarPosition(); float range = (update.playerPosition - target).Length(); if ( update.pCurrentSoundscape == this ) { update.currentDistance = range; update.bInRange = false; if ( m_flRadius > range || m_flRadius == -1 ) { trace_t tr; update.traceCount++; UTIL_TraceLine( target, update.playerPosition, MASK_SOLID_BRUSHONLY|MASK_WATER, update.pPlayer, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction == 1 && !tr.startsolid ) { update.bInRange = true; } } } else { if ( (!update.bInRange || range < update.currentDistance ) && (m_flRadius > range || m_flRadius == -1) ) { trace_t tr; update.traceCount++; UTIL_TraceLine( target, update.playerPosition, MASK_SOLID_BRUSHONLY|MASK_WATER, update.pPlayer, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction == 1 && !tr.startsolid ) { audioparams_t &audio = update.pPlayer->GetAudioParams(); WriteAudioParamsTo( audio ); update.pCurrentSoundscape = this; update.bInRange = true; update.currentDistance = range; } } } if ( soundscape_debug.GetBool() ) { // draw myself NDebugOverlay::Box(GetAbsOrigin(), Vector(-10,-10,-10), Vector(10,10,10), 255, 0, 255, 64, NDEBUG_PERSIST_TILL_NEXT_SERVER ); #ifdef SecobMod__Enable_Fixed_Multiplayer_AI CBasePlayer *pPlayer = UTIL_GetLocalPlayer(); #else // Don't use GetLocalPlayer(), because that prevents multiplayer games using this for testing with a single client in the game CBasePlayer *pPlayer = UTIL_PlayerByIndex(1); #endif //SecobMod__Enable_Fixed_Multiplayer_AI if ( update.pPlayer ) { audioparams_t &audio = update.pPlayer->GetAudioParams(); if ( audio.ent.Get() != this ) { if ( InRangeOfPlayer( update.pPlayer ) ) { NDebugOverlay::Line( GetAbsOrigin(), update.pPlayer->WorldSpaceCenter(), 255, 255, 255, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); } else { NDebugOverlay::Line( GetAbsOrigin(), update.pPlayer->WorldSpaceCenter(), 255, 0, 0, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); } } else { if ( InRangeOfPlayer( update.pPlayer ) ) { NDebugOverlay::Line( GetAbsOrigin(), update.pPlayer->WorldSpaceCenter(), 0, 255, 0, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); } else { NDebugOverlay::Line( GetAbsOrigin(), update.pPlayer->WorldSpaceCenter(), 255, 170, 0, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); } // also draw lines to each sound position. // we don't store the number of local sound positions, just a bitvector of which ones are on. unsigned int soundbits = audio.localBits.Get(); float periodic = 2.0f * sin((fmod(gpGlobals->curtime,2.0f) - 1.0f) * M_PI); // = -4f .. 4f for (int ii = 0 ; ii < NUM_AUDIO_LOCAL_SOUNDS ; ++ii ) { if ( soundbits & (1 << ii) ) { const Vector &soundLoc = audio.localSound.Get(ii); NDebugOverlay::Line( GetAbsOrigin(), soundLoc, 0, 32 , 255 , false, NDEBUG_PERSIST_TILL_NEXT_SERVER ); NDebugOverlay::Cross3D( soundLoc, 16.0f + periodic, 0, 0, 255, false, NDEBUG_PERSIST_TILL_NEXT_SERVER ); } } } } NDebugOverlay::EntityTextAtPosition( GetAbsOrigin(), 0, STRING(m_soundscapeName), NDEBUG_PERSIST_TILL_NEXT_SERVER ); } }
// CONSIDER: if player in water state, autoset and underwater soundscape? void CEnvSoundscape::Update() { bool bUpdated = UpdatePlayersInPVS(); if ( !IsEnabled() ) return; // Only update soundscapes in multiplayer when the PVS gets updated if ( g_pGameRules->IsMultiplayer() && !bUpdated && !soundscape_debug.GetBool() ) return; bool bDebugThis = soundscape_debug.GetInt() == 1; for ( int i=0; i < m_hPlayersInPVS.Count(); i++ ) { CBasePlayer *pPlayer = m_hPlayersInPVS[i]; if ( !pPlayer ) continue; if ( !InRangeOfPlayer( pPlayer ) ) continue; // check to see if this is the sound entity that is // currently affecting this player audioparams_t &audio = pPlayer->GetAudioParams(); // if we got this far, we're looking at an entity that is contending // for current player sound. the closest entity to player wins. CEnvSoundscape *pCurrent = (CEnvSoundscape *)audio.ent.Get(); if ( !pCurrent || !pCurrent->IsEnabled() || !pCurrent->InRangeOfPlayer( pPlayer ) ) { // The old one is obscured or out of range.. take over. WriteAudioParamsTo( audio ); } else if ( pCurrent && EarPosition().DistTo( pPlayer->EarPosition() ) < pCurrent->EarPosition().DistTo( pPlayer->EarPosition() ) ) { // new entity is closer to player, so it wins. WriteAudioParamsTo( audio ); } if ( !bDebugThis ) { bDebugThis = soundscape_debug.GetInt() == 2; } } if ( bDebugThis ) { // draw myself NDebugOverlay::Box(GetAbsOrigin(), Vector(-10,-10,-10), Vector(10,10,10), 255, 0, 255, 64, NDEBUG_PERSIST_TILL_NEXT_SERVER ); // Don't use GetLocalPlayer(), because that prevents multiplayer games using this for testing with a single client in the game CBasePlayer *pPlayer = UTIL_PlayerByIndex(1); if ( pPlayer ) { audioparams_t &audio = pPlayer->GetAudioParams(); if ( audio.ent.Get() != this ) { if ( InRangeOfPlayer( pPlayer ) ) { NDebugOverlay::Line( GetAbsOrigin(), pPlayer->WorldSpaceCenter(), 255, 255, 255, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); } else { NDebugOverlay::Line( GetAbsOrigin(), pPlayer->WorldSpaceCenter(), 255, 0, 0, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); } } else { if ( InRangeOfPlayer( pPlayer ) ) { NDebugOverlay::Line( GetAbsOrigin(), pPlayer->WorldSpaceCenter(), 0, 255, 0, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); } else { NDebugOverlay::Line( GetAbsOrigin(), pPlayer->WorldSpaceCenter(), 255, 170, 0, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); } // also draw lines to each sound position. // we don't store the number of local sound positions, just a bitvector of which ones are on. unsigned int soundbits = audio.localBits.Get(); float periodic = 2.0f * sin((fmod(gpGlobals->curtime,2.0f) - 1.0f) * M_PI); // = -4f .. 4f for (int ii = 0 ; ii < NUM_AUDIO_LOCAL_SOUNDS ; ++ii ) { if ( soundbits & (1 << ii) ) { const Vector &soundLoc = audio.localSound.Get(ii); NDebugOverlay::Line( GetAbsOrigin(), soundLoc, 0, 32 , 255 , false, NDEBUG_PERSIST_TILL_NEXT_SERVER ); NDebugOverlay::Cross3D( soundLoc, 16.0f + periodic, 0, 0, 255, false, NDEBUG_PERSIST_TILL_NEXT_SERVER ); } } } } NDebugOverlay::EntityTextAtPosition( GetAbsOrigin(), 0, STRING(m_soundscapeName), NDEBUG_PERSIST_TILL_NEXT_SERVER ); } }
// CONSIDER: if player in water state, autoset and underwater soundscape? void CEnvSoundscape::Update() { UpdatePlayersInPVS(); if ( !IsEnabled() ) return; for ( int i=0; i < m_hPlayersInPVS.Count(); i++ ) { CBasePlayer *pPlayer = m_hPlayersInPVS[i]; if ( !pPlayer ) continue; if ( !InRangeOfPlayer( pPlayer ) ) continue; // check to see if this is the sound entity that is // currently affecting this player audioparams_t &audio = pPlayer->GetAudioParams(); // if we got this far, we're looking at an entity that is contending // for current player sound. the closest entity to player wins. CEnvSoundscape *pCurrent = (CEnvSoundscape *)audio.ent.Get(); if ( !pCurrent || !pCurrent->IsEnabled() || !pCurrent->InRangeOfPlayer( pPlayer ) ) { // The old one is obscured or out of range.. take over. WriteAudioParamsTo( audio ); } else if ( pCurrent && EarPosition().DistTo( pPlayer->EarPosition() ) < pCurrent->EarPosition().DistTo( pPlayer->EarPosition() ) ) { // new entity is closer to player, so it wins. WriteAudioParamsTo( audio ); } } if ( soundscape_debug.GetBool() ) { CBasePlayer *pPlayer = UTIL_GetLocalPlayer(); if ( pPlayer ) { audioparams_t &audio = pPlayer->GetAudioParams(); if ( audio.ent.Get() != this ) { if ( InRangeOfPlayer( pPlayer ) ) { NDebugOverlay::Line( GetAbsOrigin(), pPlayer->WorldSpaceCenter(), 255, 255,255, true, 0.1 ); } else { NDebugOverlay::Line( GetAbsOrigin(), pPlayer->WorldSpaceCenter(), 255, 0,0, true, 0.1 ); } } else { if ( InRangeOfPlayer( pPlayer ) ) { NDebugOverlay::Line( GetAbsOrigin(), pPlayer->WorldSpaceCenter(), 0, 255,0, true, 0.1 ); } else { NDebugOverlay::Line( GetAbsOrigin(), pPlayer->WorldSpaceCenter(), 255, 170,0, true, 0.1 ); } } } } }