@@ -788,10 +788,8 @@ AS_AddPrecacheEntry
788
788
-------------------------
789
789
*/
790
790
791
- void AS_AddPrecacheEntry ( const char *name )
792
- {
793
- if (!pMap) // s_initsound 0 probably
794
- {
791
+ void AS_AddPrecacheEntry ( const char *name ) {
792
+ if ( !pMap ) { // s_initsound 0 probably
795
793
return ;
796
794
}
797
795
if (!Q_stricmp (name," #clear" ))
@@ -816,10 +814,10 @@ Called on the client side to load and precache all the ambient sound sets
816
814
817
815
void AS_ParseSets ( void )
818
816
{
819
- cvar_t *cv = Cvar_Get (" s_initsound" , " 1" , 0 );
820
- if ( !cv->integer ) {
817
+ if ( !s_initsound->integer ) {
821
818
return ;
822
819
}
820
+
823
821
AS_Init ();
824
822
825
823
// Parse all the sets
@@ -913,47 +911,47 @@ Fades volumes up or down depending on the action being taken on them.
913
911
-------------------------
914
912
*/
915
913
916
- static void AS_UpdateSetVolumes ( void )
917
- {
918
- ambientSet_t *old, *current;
919
- float scale;
920
- int deltaTime;
914
+ static void AS_UpdateSetVolumes ( void ) {
915
+ if ( !aSets ) {
916
+ return ;
917
+ }
921
918
922
919
// Get the sets and validate them
923
- current = aSets->GetSet ( currentSet );
924
-
925
- if ( current == NULL )
920
+ ambientSet_t *current = aSets->GetSet ( currentSet );
921
+ if ( !current ) {
926
922
return ;
923
+ }
927
924
928
- if ( current->masterVolume < MAX_SET_VOLUME )
929
- {
925
+ float scale;
926
+ int deltaTime;
927
+ if ( current->masterVolume < MAX_SET_VOLUME ) {
930
928
deltaTime = cls.realtime - current->fadeTime ;
931
929
scale = ((float )(deltaTime)/(float )(crossDelay));
932
930
current->masterVolume = (int )((scale) * (float )MAX_SET_VOLUME);
933
931
}
934
932
935
- if ( current->masterVolume > MAX_SET_VOLUME )
933
+ if ( current->masterVolume > MAX_SET_VOLUME ) {
936
934
current->masterVolume = MAX_SET_VOLUME;
935
+ }
937
936
938
937
// Only update the old set if it's still valid
939
- if ( oldSet == -1 )
938
+ if ( oldSet == -1 ) {
940
939
return ;
940
+ }
941
941
942
- old = aSets->GetSet ( oldSet );
943
-
944
- if ( old == NULL )
942
+ ambientSet_t *old = aSets->GetSet ( oldSet );
943
+ if ( !old ) {
945
944
return ;
945
+ }
946
946
947
947
// Update the volumes
948
- if ( old->masterVolume > 0 )
949
- {
948
+ if ( old->masterVolume > 0 ) {
950
949
deltaTime = cls.realtime - old->fadeTime ;
951
950
scale = ((float )(deltaTime)/(float )(crossDelay));
952
951
old->masterVolume = MAX_SET_VOLUME - (int )((scale) * (float )MAX_SET_VOLUME);
953
952
}
954
953
955
- if ( old->masterVolume <= 0 )
956
- {
954
+ if ( old->masterVolume <= 0 ) {
957
955
old->masterVolume = 0 ;
958
956
oldSet = -1 ;
959
957
}
@@ -967,26 +965,25 @@ Does internal maintenance to keep track of changing sets.
967
965
-------------------------
968
966
*/
969
967
970
- static void AS_UpdateCurrentSet ( int id )
971
- {
972
- ambientSet_t *old, *current;
968
+ static void AS_UpdateCurrentSet ( int id ) {
969
+ if ( !aSets ) {
970
+ return ;
971
+ }
973
972
974
973
// Check for a change
975
- if ( id != currentSet )
976
- {
974
+ if ( id != currentSet ) {
977
975
// This is new, so start the fading
978
976
oldSet = currentSet;
979
977
currentSet = id;
980
978
981
- old = aSets->GetSet ( oldSet );
982
- current = aSets->GetSet ( currentSet );
979
+ ambientSet_t *current = aSets->GetSet ( currentSet );
983
980
// Ste, I just put this null check in for now, not sure if there's a more graceful way to exit this function - dmv
984
- if ( !current )
985
- {
981
+ if ( !current ) {
986
982
return ;
987
983
}
988
- if ( old )
989
- {
984
+
985
+ ambientSet_t *old = aSets->GetSet ( oldSet );
986
+ if ( old ) {
990
987
old->masterVolume = MAX_SET_VOLUME;
991
988
old->fadeTime = cls.realtime ;
992
989
}
@@ -1010,42 +1007,42 @@ Alters lastTime to reflect the time updates.
1010
1007
-------------------------
1011
1008
*/
1012
1009
1013
- static void AS_PlayLocalSet ( vec3_t listener_origin, vec3_t origin, ambientSet_t *set, int entID, int *lastTime )
1014
- {
1015
- unsigned char volume;
1016
- vec3_t dir;
1017
- float volScale, dist, distScale;
1018
- int time = cl.serverTime ;
1019
-
1010
+ static void AS_PlayLocalSet ( vec3_t listener_origin, vec3_t origin, const ambientSet_t *set, int entID, int *lastTime ) {
1020
1011
// Make sure it's valid
1021
- if ( set == NULL )
1012
+ if ( ! set ) {
1022
1013
return ;
1014
+ }
1023
1015
1016
+ vec3_t dir;
1024
1017
VectorSubtract ( origin, listener_origin, dir );
1025
- dist = VectorLength ( dir );
1018
+ float dist = VectorLength ( dir );
1026
1019
1027
1020
// Determine the volume based on distance (NOTE: This sits on top of what SpatializeOrigin does)
1028
- distScale = ( dist < ( set->radius * 0 .5f ) ) ? 1 : ( set->radius - dist ) / ( set->radius * 0 .5f );
1029
- volume = ( distScale > 1 .0f || distScale < 0 .0f ) ? 0 : (unsigned char ) ( set->masterVolume * distScale );
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 );
1030
1023
1031
1024
// Add the looping sound
1032
- if ( set->loopedWave )
1025
+ if ( set->loopedWave ) {
1033
1026
S_AddAmbientLoopingSound ( origin, volume, set->loopedWave );
1027
+ }
1034
1028
1035
1029
// Check the time to start another one-shot subwave
1036
- if ( ( time - *lastTime ) < ( ( Q_irand ( set->time_start , set->time_end ) ) * 1000 ) )
1030
+ int time = cl.serverTime ;
1031
+ if ( ( time - *lastTime ) < ( ( Q_irand ( set->time_start , set->time_end ) ) * 1000 ) ) {
1037
1032
return ;
1033
+ }
1038
1034
1039
1035
// Update the time
1040
1036
*lastTime = time;
1041
1037
1042
1038
// Scale the volume ranges for the subwaves based on the overall master volume
1043
- volScale = (float ) volume / (float ) MAX_SET_VOLUME;
1039
+ float volScale = (float ) volume / (float ) MAX_SET_VOLUME;
1044
1040
volume = (unsigned char ) Q_irand ( (int )(volScale*set->volRange_start ), (int )(volScale*set->volRange_end ) );
1045
1041
1046
1042
// Add the random subwave
1047
- if ( set->numSubWaves )
1043
+ if ( set->numSubWaves ) {
1048
1044
S_StartAmbientSound ( origin, entID, volume, set->subWaves [Q_irand ( 0 , set->numSubWaves -1 )] );
1045
+ }
1049
1046
}
1050
1047
1051
1048
/*
@@ -1057,38 +1054,39 @@ Alters lastTime to reflect the time updates.
1057
1054
-------------------------
1058
1055
*/
1059
1056
1060
- static void AS_PlayAmbientSet ( vec3_t origin, ambientSet_t *set, int *lastTime )
1061
- {
1062
- unsigned char volume;
1063
- float volScale;
1064
- int time = cls.realtime ;
1065
-
1057
+ static void AS_PlayAmbientSet ( vec3_t origin, const ambientSet_t *set, int *lastTime ) {
1066
1058
// Make sure it's valid
1067
- if ( set == NULL )
1059
+ if ( ! set ) {
1068
1060
return ;
1061
+ }
1069
1062
1070
1063
// Add the looping sound
1071
- if ( set->loopedWave )
1064
+ if ( set->loopedWave ) {
1072
1065
S_AddAmbientLoopingSound ( origin, (unsigned char ) set->masterVolume , set->loopedWave );
1066
+ }
1073
1067
1074
1068
// Check the time to start another one-shot subwave
1075
- if ( ( time - *lastTime ) < ( ( Q_irand ( set->time_start , set->time_end ) ) * 1000 ) )
1069
+ int time = cls.realtime ;
1070
+ if ( ( time - *lastTime ) < ( ( Q_irand ( set->time_start , set->time_end ) ) * 1000 ) ) {
1076
1071
return ;
1072
+ }
1077
1073
1078
1074
// Update the time
1079
1075
*lastTime = time;
1080
1076
1081
1077
// Scale the volume ranges for the subwaves based on the overall master volume
1082
- volScale = (float ) set->masterVolume / (float ) MAX_SET_VOLUME;
1083
- volume = Q_irand ( (int )(volScale*set->volRange_start ), (int )(volScale*set->volRange_end ) );
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 ) );
1084
1080
1085
1081
// Allow for softer noises than the masterVolume, but not louder
1086
- if ( volume > set->masterVolume )
1082
+ if ( volume > set->masterVolume ) {
1087
1083
volume = set->masterVolume ;
1084
+ }
1088
1085
1089
1086
// Add the random subwave
1090
- if ( set->numSubWaves )
1087
+ if ( set->numSubWaves ) {
1091
1088
S_StartAmbientSound ( origin, 0 , volume, set->subWaves [Q_irand ( 0 , set->numSubWaves -1 )] );
1089
+ }
1092
1090
}
1093
1091
1094
1092
/*
@@ -1099,29 +1097,28 @@ Does maintenance and plays the ambient sets (two if crossfading)
1099
1097
-------------------------
1100
1098
*/
1101
1099
1102
- void S_UpdateAmbientSet ( const char *name, vec3_t origin )
1103
- {
1104
- ambientSet_t *current, *old;
1105
- if (aSets == NULL )
1106
- {
1100
+ void S_UpdateAmbientSet ( const char *name, vec3_t origin ) {
1101
+ if ( !aSets ) {
1107
1102
return ;
1108
1103
}
1109
- ambientSet_t *set = aSets->GetSet ( name );
1110
1104
1111
- if ( set == NULL )
1105
+ const ambientSet_t *set = aSets->GetSet ( name );
1106
+ if ( !set ) {
1112
1107
return ;
1108
+ }
1113
1109
1114
1110
// Update the current and old set for crossfading
1115
1111
AS_UpdateCurrentSet ( set->id );
1116
1112
1117
- current = aSets->GetSet ( currentSet );
1118
- old = aSets->GetSet ( oldSet );
1119
-
1120
- if ( current )
1113
+ const ambientSet_t *current = aSets->GetSet ( currentSet );
1114
+ if ( current ) {
1121
1115
AS_PlayAmbientSet ( origin, set, ¤tSetTime );
1116
+ }
1122
1117
1123
- if ( old )
1118
+ const ambientSet_t *old = aSets->GetSet ( oldSet );
1119
+ if ( old ) {
1124
1120
AS_PlayAmbientSet ( origin, old, &oldSetTime );
1121
+ }
1125
1122
}
1126
1123
1127
1124
/*
@@ -1130,20 +1127,18 @@ S_AddLocalSet
1130
1127
-------------------------
1131
1128
*/
1132
1129
1133
- int S_AddLocalSet ( const char *name, vec3_t listener_origin, vec3_t origin, int entID, int time )
1134
- {
1135
- ambientSet_t *set;
1136
- int currentTime = 0 ;
1137
-
1138
- set = aSets->GetSet ( name );
1139
-
1140
- if ( set == NULL )
1130
+ int S_AddLocalSet ( const char *name, vec3_t listener_origin, vec3_t origin, int entID, int time ) {
1131
+ if ( !aSets ) {
1141
1132
return cl.serverTime ;
1133
+ }
1142
1134
1143
- currentTime = time;
1135
+ const ambientSet_t *set = aSets->GetSet ( name );
1136
+ if ( !set ) {
1137
+ return cl.serverTime ;
1138
+ }
1144
1139
1140
+ int currentTime = time;
1145
1141
AS_PlayLocalSet ( listener_origin, origin, set, entID, ¤tTime );
1146
-
1147
1142
return currentTime;
1148
1143
}
1149
1144
@@ -1153,18 +1148,16 @@ AS_GetBModelSound
1153
1148
-------------------------
1154
1149
*/
1155
1150
1156
- sfxHandle_t AS_GetBModelSound ( const char *name, int stage )
1157
- {
1158
- ambientSet_t *set;
1159
-
1160
- set = aSets->GetSet ( name );
1161
-
1162
- if ( set == NULL )
1151
+ sfxHandle_t AS_GetBModelSound ( const char *name, int stage ) {
1152
+ if ( !aSets ) {
1163
1153
return -1 ;
1154
+ }
1164
1155
1165
1156
// Stage must be within a valid range
1166
- if ( ( stage > ( set->numSubWaves - 1 ) ) || ( stage < 0 ) )
1157
+ const ambientSet_t *set = aSets->GetSet ( name );
1158
+ if ( !set || stage < 0 || stage > (set->numSubWaves - 1 ) ) {
1167
1159
return -1 ;
1160
+ }
1168
1161
1169
- return set->subWaves [ stage ];
1162
+ return set->subWaves [stage];
1170
1163
}
0 commit comments