void CCollisionEvent::Friction( IPhysicsObject *pObject, float energy, int surfaceProps, int surfacePropsHit, IPhysicsCollisionData *pData ) { CallbackContext callback(this); if ( energy < 0.05f || surfaceProps < 0 ) return; //Get our friction information Vector vecPos, vecVel; pData->GetContactPoint( vecPos ); pObject->GetVelocityAtPoint( vecPos, &vecVel ); CBaseEntity *pEntity = reinterpret_cast<CBaseEntity *>(pObject->GetGameData()); if ( pEntity ) { friction_t *pFriction = g_Collisions.FindFriction( pEntity ); if ( (gpGlobals->maxClients > 1) && pFriction && pFriction->pObject) { // in MP mode play sound and effects once every 500 msecs, // no ongoing updates, takes too much bandwidth if ( (pFriction->flLastEffectTime + 0.5f) > gpGlobals->curtime) { pFriction->flLastUpdateTime = gpGlobals->curtime; return; } } PhysFrictionSound( pEntity, pObject, energy, surfaceProps, surfacePropsHit ); } PhysFrictionEffect( vecPos, vecVel, energy, surfaceProps, surfacePropsHit ); }
void PhysFrictionSound( CBaseEntity *pEntity, IPhysicsObject *pObject, float energy, int surfaceProps, int surfacePropsHit ) { if ( !pEntity || energy < 75.0f || surfaceProps < 0 ) return; // don't make noise for hidden/invisible/sky materials surfacedata_t *phit = physprops->GetSurfaceData( surfacePropsHit ); surfacedata_t *psurf = physprops->GetSurfaceData( surfaceProps ); if ( phit->game.material == 'X' || psurf->game.material == 'X' ) return; // rescale the incoming energy energy *= ENERGY_VOLUME_SCALE; // volume of scrape is proportional to square of energy (steeper rolloff at low energies) float volume = energy * energy; unsigned short soundName = psurf->sounds.scrapeRough; short *soundHandle = &psurf->soundhandles.scrapeRough; if ( psurf->sounds.scrapeSmooth && phit->audio.roughnessFactor < psurf->audio.roughThreshold ) { soundName = psurf->sounds.scrapeSmooth; soundHandle = &psurf->soundhandles.scrapeRough; } const char *pSoundName = physprops->GetString( soundName ); PhysFrictionSound( pEntity, pObject, pSoundName, *soundHandle, volume ); }