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

Function AS_PlayAmbientSet

code/client/snd_ambient.cpp:1057–1090  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1055*/
1056
1057static void AS_PlayAmbientSet( vec3_t origin, const ambientSet_t *set, int *lastTime ) {
1058 //Make sure it's valid
1059 if ( !set ) {
1060 return;
1061 }
1062
1063 //Add the looping sound
1064 if ( set->loopedWave ) {
1065 S_AddAmbientLoopingSound( origin, (unsigned char) set->masterVolume, set->loopedWave );
1066 }
1067
1068 //Check the time to start another one-shot subwave
1069 int time = cls.realtime;
1070 if ( ( time - *lastTime ) < ( ( Q_irand( set->time_start, set->time_end ) ) * 1000 ) ) {
1071 return;
1072 }
1073
1074 //Update the time
1075 *lastTime = time;
1076
1077 //Scale the volume ranges for the subwaves based on the overall master volume
1078 float volScale = (float) set->masterVolume / (float) MAX_SET_VOLUME;
1079 unsigned char volume = Q_irand( (int)(volScale*set->volRange_start), (int)(volScale*set->volRange_end) );
1080
1081 //Allow for softer noises than the masterVolume, but not louder
1082 if ( volume > set->masterVolume ) {
1083 volume = set->masterVolume;
1084 }
1085
1086 //Add the random subwave
1087 if ( set->numSubWaves ) {
1088 S_StartAmbientSound( origin, 0, volume, set->subWaves[Q_irand( 0, set->numSubWaves-1)] );
1089 }
1090}
1091
1092/*
1093-------------------------

Callers 1

S_UpdateAmbientSetFunction · 0.70

Calls 3

Q_irandFunction · 0.85
S_AddAmbientLoopingSoundFunction · 0.70
S_StartAmbientSoundFunction · 0.70

Tested by

no test coverage detected