mirror of
https://github.com/yogstation13/Yogstation.git
synced 2025-02-26 09:04:50 +00:00
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
This commit is contained in:
committed by
duncathan salt
parent
24dc15930e
commit
585fc0615d
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user