From 585fc0615d23cef3d9ec9647cce47d63e2ef1eab Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Wed, 5 Apr 2017 14:57:23 -0400 Subject: [PATCH] Sound tweaks (#25876) * Port ai vox channel to new system * Add playsound_direct * Add pressure_affected parameter * Channel allocation * Default pressure_affected to FALSE for ps_direct * Can't wait to get rid of this shitty fucking proc --- code/__DEFINES/sound.dm | 5 ++ code/controllers/subsystem/garbage.dm | 1 - code/game/sound.dm | 56 ++++++++++++++--------- code/modules/mob/living/silicon/ai/say.dm | 3 +- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/code/__DEFINES/sound.dm b/code/__DEFINES/sound.dm index 1d8f7d2f89c..8055d7337ed 100644 --- a/code/__DEFINES/sound.dm +++ b/code/__DEFINES/sound.dm @@ -1,3 +1,8 @@ //max channel is 1024. Only go lower from here, because byond tends to pick the first availiable channel to play sounds on #define CHANNEL_LOBBYMUSIC 1024 #define CHANNEL_ADMIN 1023 +#define CHANNEL_VOX 1022 + +//THIS SHOULD ALWAYS BE THE LOWEST ONE! +//KEEP IT UPDATED +#define CHANNEL_HIGHEST_AVAILABLE 1021 \ No newline at end of file diff --git a/code/controllers/subsystem/garbage.dm b/code/controllers/subsystem/garbage.dm index a97a7b70150..f851abcad5e 100644 --- a/code/controllers/subsystem/garbage.dm +++ b/code/controllers/subsystem/garbage.dm @@ -919,7 +919,6 @@ SUBSYSTEM_DEF(garbage) SearchVar(plasmaman_on_fire) SearchVar(ai_list) SearchVar(announcing_vox) - SearchVar(VOX_CHANNEL) SearchVar(VOX_DELAY) SearchVar(vox_sounds) SearchVar(CHUNK_SIZE) diff --git a/code/game/sound.dm b/code/game/sound.dm index c82a67fd74f..5b0a7738220 100644 --- a/code/game/sound.dm +++ b/code/game/sound.dm @@ -1,4 +1,4 @@ -/proc/playsound(atom/source, soundin, vol as num, vary, extrarange as num, falloff, surround = 1, frequency = null, channel = 0) +/proc/playsound(atom/source, soundin, vol as num, vary, extrarange as num, falloff, surround = 1, frequency = null, channel = 0, pressure_affected = TRUE) soundin = get_sfx(soundin) // same sound for everyone @@ -10,6 +10,9 @@ frequency = get_rand_frequency() // Same frequency for everybody var/turf/turf_source = get_turf(source) + //allocate a channel if necessary now so its the same for everyone + channel = channel || open_sound_channel() + // Looping through the player list has the added bonus of working for mobs inside containers for (var/P in player_list) var/mob/M = P @@ -18,15 +21,17 @@ if(get_dist(M, turf_source) <= world.view + extrarange) var/turf/T = get_turf(M) if(T && T.z == turf_source.z) - M.playsound_local(turf_source, soundin, vol, vary, frequency, falloff, surround, channel) + M.playsound_local(turf_source, soundin, vol, vary, frequency, falloff, surround, channel, pressure_affected) +/atom/proc/playsound_direct(soundin, vol as num, vary, frequency, falloff, surround = TRUE, channel = 0, pressure_affected = FALSE) + playsound_local(get_turf(src), soundin, vol, vary, frequency, falloff, surround, channel) -/atom/proc/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff, surround = 1, channel = 0) +/atom/proc/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff, surround = 1, channel = 0, pressure_affected = TRUE) soundin = get_sfx(soundin) var/sound/S = sound(soundin) S.wait = 0 //No queue - S.channel = channel + S.channel = channel || open_sound_channel() S.volume = vol if (vary) @@ -38,27 +43,28 @@ if(isturf(turf_source)) var/turf/T = get_turf(src) - //Atmosphere affects sound - var/pressure_factor = 1 - var/datum/gas_mixture/hearer_env = T.return_air() - var/datum/gas_mixture/source_env = turf_source.return_air() + if(pressure_affected) + //Atmosphere affects sound + var/pressure_factor = 1 + var/datum/gas_mixture/hearer_env = T.return_air() + var/datum/gas_mixture/source_env = turf_source.return_air() - if(hearer_env && source_env) - var/pressure = min(hearer_env.return_pressure(), source_env.return_pressure()) - if(pressure < ONE_ATMOSPHERE) - pressure_factor = max((pressure - SOUND_MINIMUM_PRESSURE)/(ONE_ATMOSPHERE - SOUND_MINIMUM_PRESSURE), 0) - else //space - pressure_factor = 0 + if(hearer_env && source_env) + var/pressure = min(hearer_env.return_pressure(), source_env.return_pressure()) + if(pressure < ONE_ATMOSPHERE) + pressure_factor = max((pressure - SOUND_MINIMUM_PRESSURE)/(ONE_ATMOSPHERE - SOUND_MINIMUM_PRESSURE), 0) + else //space + pressure_factor = 0 - var/distance = get_dist(T, turf_source) - if(distance <= 1) - pressure_factor = max(pressure_factor, 0.15) //touching the source of the sound + var/distance = get_dist(T, turf_source) + if(distance <= 1) + pressure_factor = max(pressure_factor, 0.15) //touching the source of the sound - S.volume *= pressure_factor - //End Atmosphere affecting sound + S.volume *= pressure_factor + //End Atmosphere affecting sound - if(S.volume <= 0) - return //No sound + if(S.volume <= 0) + return //No sound // 3D sounds, the technology is here! if (surround) @@ -74,11 +80,17 @@ src << S -/mob/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff, surround = 1, channel = 0) +/mob/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff, surround = 1, channel = 0, pressure_affected = TRUE) if(!client || ear_deaf > 0) return ..() +/proc/open_sound_channel() + var/static/next_channel = 1 //loop through the available 1024 - (the ones we reserve) channels and pray that its not still being used + . = ++next_channel + if(next_channel > CHANNEL_HIGHEST_AVAILABLE) + next_channel = 1 + /mob/proc/stop_sound_channel(chan) src << sound(null, repeat = 0, wait = 0, channel = chan) diff --git a/code/modules/mob/living/silicon/ai/say.dm b/code/modules/mob/living/silicon/ai/say.dm index 60b8e3040ba..39daec41055 100644 --- a/code/modules/mob/living/silicon/ai/say.dm +++ b/code/modules/mob/living/silicon/ai/say.dm @@ -59,7 +59,6 @@ #ifdef AI_VOX var/announcing_vox = 0 // Stores the time of the last announcement -var/const/VOX_CHANNEL = 200 var/const/VOX_DELAY = 600 /mob/living/silicon/ai/verb/announcement_help() @@ -149,7 +148,7 @@ var/const/VOX_DELAY = 600 if(vox_sounds[word]) var/sound_file = vox_sounds[word] - var/sound/voice = sound(sound_file, wait = 1, channel = VOX_CHANNEL) + var/sound/voice = sound(sound_file, wait = 1, channel = CHANNEL_VOX) voice.status = SOUND_STREAM // If there is no single listener, broadcast to everyone in the same z level