MCPcopy Create free account
hub / github.com/JACoders/OpenJK / AS_PlayLocalSet

Function AS_PlayLocalSet

code/client/snd_ambient.cpp:1010–1046  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1008*/
1009
1010static void AS_PlayLocalSet( vec3_t listener_origin, vec3_t origin, const ambientSet_t *set, int entID, int *lastTime ) {
1011 //Make sure it's valid
1012 if ( !set ) {
1013 return;
1014 }
1015
1016 vec3_t dir;
1017 VectorSubtract( origin, listener_origin, dir );
1018 float dist = VectorLength( dir );
1019
1020 //Determine the volume based on distance (NOTE: This sits on top of what SpatializeOrigin does)
1021 float distScale = ( dist < ( set->radius * 0.5f ) ) ? 1 : ( set->radius - dist ) / ( set->radius * 0.5f );
1022 unsigned char volume = ( distScale > 1.0f || distScale < 0.0f ) ? 0 : (unsigned char) ( set->masterVolume * distScale );
1023
1024 //Add the looping sound
1025 if ( set->loopedWave ) {
1026 S_AddAmbientLoopingSound( origin, volume, set->loopedWave );
1027 }
1028
1029 //Check the time to start another one-shot subwave
1030 int time = cl.serverTime;
1031 if ( ( time - *lastTime ) < ( ( Q_irand( set->time_start, set->time_end ) ) * 1000 ) ) {
1032 return;
1033 }
1034
1035 //Update the time
1036 *lastTime = time;
1037
1038 //Scale the volume ranges for the subwaves based on the overall master volume
1039 float volScale = (float) volume / (float) MAX_SET_VOLUME;
1040 volume = (unsigned char) Q_irand( (int)(volScale*set->volRange_start), (int)(volScale*set->volRange_end) );
1041
1042 //Add the random subwave
1043 if ( set->numSubWaves ) {
1044 S_StartAmbientSound( origin, entID, volume, set->subWaves[Q_irand( 0, set->numSubWaves-1)] );
1045 }
1046}
1047
1048/*
1049-------------------------

Callers 1

S_AddLocalSetFunction · 0.70

Calls 5

VectorSubtractFunction · 0.85
VectorLengthFunction · 0.85
Q_irandFunction · 0.85
S_AddAmbientLoopingSoundFunction · 0.70
S_StartAmbientSoundFunction · 0.70

Tested by

no test coverage detected