Adds 3D Sound System

This commit is contained in:
CitadelStationBot
2017-07-28 09:02:21 -05:00
parent 3f8acbc2c4
commit 3db9c9ddb7
7 changed files with 94 additions and 38 deletions
+2 -2
View File
@@ -432,7 +432,7 @@ GLOBAL_LIST_EMPTY(teleportlocs)
// Ambience goes down here -- make sure to list each area seperately for ease of adding things in later, thanks! Note: areas adjacent to each other should have the same sounds to prevent cutoff when possible.- LastyScratch
if(L.client && !L.client.ambience_playing && L.client.prefs.toggles & SOUND_SHIP_AMBIENCE)
L.client.ambience_playing = 1
L << sound('sound/ambience/shipambience.ogg', repeat = 1, wait = 0, volume = 35, channel = 2)
L << sound('sound/ambience/shipambience.ogg', repeat = 1, wait = 0, volume = 35, channel = CHANNEL_BUZZ)
if(!(L.client && (L.client.prefs.toggles & SOUND_AMBIENCE)))
return //General ambience check is below the ship ambience so one can play without the other
@@ -441,7 +441,7 @@ GLOBAL_LIST_EMPTY(teleportlocs)
var/sound = pick(ambientsounds)
if(!L.client.played)
L << sound(sound, repeat = 0, wait = 0, volume = 25, channel = 1)
L << sound(sound, repeat = 0, wait = 0, volume = 25, channel = CHANNEL_AMBIENCE)
L.client.played = 1
sleep(600) //ewww - this is very very bad
if(L.&& L.client)
+27 -27
View File
@@ -1,40 +1,40 @@
/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
/proc/playsound(atom/source, soundin, vol as num, vary, extrarange as num, falloff, frequency = null, channel = 0, pressure_affected = TRUE)
if(isarea(source))
throw EXCEPTION("playsound(): source is an area")
return
if(isnull(frequency))
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 GLOB.player_list)
var/sound/S = sound(get_sfx(soundin))
var/maxdistance = (world.view + extrarange) * 3
for(var/P in GLOB.player_list)
var/mob/M = P
if(!M || !M.client)
continue
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, pressure_affected)
var/distance = get_dist(M, turf_source)
/mob/proc/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff, surround = 1, channel = 0, pressure_affected = TRUE)
if(distance <= maxdistance)
var/turf/T = get_turf(M)
if(T && T.z == turf_source.z)
M.playsound_local(turf_source, soundin, vol, vary, frequency, falloff, channel, pressure_affected, S)
/mob/proc/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff, channel = 0, pressure_affected = TRUE, sound/S)
if(!client || !can_hear())
return
soundin = get_sfx(soundin)
if(!S)
S = sound(get_sfx(soundin))
var/sound/S = sound(soundin)
S.wait = 0 //No queue
S.channel = channel || open_sound_channel()
S.volume = vol
if (vary)
if(vary)
if(frequency)
S.frequency = frequency
else
@@ -43,6 +43,11 @@
if(isturf(turf_source))
var/turf/T = get_turf(src)
//sound volume falloff with distance
var/distance = get_dist(T, turf_source)
S.volume -= max(distance - world.view, 0) * 2 //multiplicative falloff to add on top of natural audio falloff.
if(pressure_affected)
//Atmosphere affects sound
var/pressure_factor = 1
@@ -56,27 +61,22 @@
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
S.volume *= pressure_factor
//End Atmosphere affecting sound
if(S.volume <= 0)
return //No sound
// 3D sounds, the technology is here!
if (surround)
var/dx = turf_source.x - T.x // Hearing from the right/left
S.x = round(max(-SURROUND_CAP, min(SURROUND_CAP, dx)), 1)
var/dz = turf_source.y - T.y // Hearing from infront/behind
S.z = round(max(-SURROUND_CAP, min(SURROUND_CAP, dz)), 1)
if(S.volume <= 0)
return //No sound
var/dx = turf_source.x - T.x // Hearing from the right/left
S.x = dx
var/dz = turf_source.y - T.y // Hearing from infront/behind
S.z = dz
// The y value is for above your head, but there is no ceiling in 2d spessmens.
S.y = 1
S.falloff = falloff || FALLOFF_SOUNDS
S.falloff = (falloff ? falloff : FALLOFF_SOUNDS)
src << S
+9
View File
@@ -0,0 +1,9 @@
diff a/code/game/sound.dm b/code/game/sound.dm (rejected hunks)
@@ -154,6 +151,6 @@
soundin = pick('sound/effects/can_open1.ogg', 'sound/effects/can_open2.ogg', 'sound/effects/can_open3.ogg')
return soundin
-/proc/playsound_global(file, repeat=0, wait, channel, volume)
+/proc/playsound_global(file, repeat = 0, wait, channel, volume)
for(var/V in GLOB.clients)
V << sound(file, repeat, wait, channel, volume)