diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 1758f4718..cfd58287f 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4980,13 +4980,15 @@ static void Gravity_OnChange(void) static void SoundTest_OnChange(void) { + INT32 sfxfreeint = (INT32)sfxfree; + if (cv_soundtest.value < 0) { - CV_SetValue(&cv_soundtest, NUMSFX-1); + CV_SetValue(&cv_soundtest, sfxfreeint-1); return; } - if (cv_soundtest.value >= NUMSFX) + if (cv_soundtest.value >= sfxfreeint) { CV_SetValue(&cv_soundtest, 0); return; diff --git a/src/sounds.c b/src/sounds.c index 3769bf65b..c011557bd 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -1007,39 +1007,47 @@ void S_InitRuntimeSounds(void) } } +sfxenum_t sfxfree = sfx_freeslot0; + // Add a new sound fx into a free sfx slot. // sfxenum_t S_AddSoundFx(const char *name, boolean singular, INT32 flags, boolean skinsound) { - sfxenum_t i, slot; + sfxenum_t i; if (skinsound) - slot = sfx_skinsoundslot0; - else - slot = sfx_freeslot0; - - const int precache = S_CacheSound(); - - for (i = slot; i < NUMSFX; i++) { - if (!S_sfx[i].priority) + for (i = sfx_skinsoundslot0; i < NUMSFX; i++) { - strncpy(freeslotnames[i-sfx_freeslot0], name, 6); - S_sfx[i].singularity = singular; - S_sfx[i].priority = 60; - S_sfx[i].pitch = flags; - S_sfx[i].lumpnum = LUMPERROR; - S_sfx[i].length = 0; - S_sfx[i].skinsound = -1; + if (S_sfx[i].priority) + continue; - if (precache == SOUNDCACHE_PRECACHE) - S_sfx[i].data = I_GetSfx(&S_sfx[i]); - else - S_sfx[i].data = NULL; - - return i; + break; } } + else + i = sfxfree; + + if (i < NUMSFX) + { + strncpy(freeslotnames[i-sfx_freeslot0], name, 6); + S_sfx[i].singularity = singular; + S_sfx[i].priority = 60; + S_sfx[i].pitch = flags; + S_sfx[i].lumpnum = LUMPERROR; + S_sfx[i].length = 0; + S_sfx[i].skinsound = -1; + + if (S_CacheSound() == SOUNDCACHE_PRECACHE) + S_sfx[i].data = I_GetSfx(&S_sfx[i]); + else + S_sfx[i].data = NULL; + + if (!skinsound) + sfxfree++; + + return i; + } I_Error("Out of Sound Freeslots while allocating \"%s\"\nLoad less addons to fix this.", name); return 0; diff --git a/src/sounds.h b/src/sounds.h index ea530da05..e8507f1cb 100644 --- a/src/sounds.h +++ b/src/sounds.h @@ -1051,6 +1051,7 @@ typedef enum void S_InitRuntimeSounds(void); sfxenum_t S_AddSoundFx(const char *name, boolean singular, INT32 flags, boolean skinsound); +extern sfxenum_t sfxfree; // sound test and slotting void S_RemoveSoundFx(sfxenum_t id); #endif