Skip to content

Commit

Permalink
Merge pull request tgstation#29455
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Jul 28, 2017
2 parents fad1da7 + 71c7e1f commit 25c35c2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 38 deletions.
4 changes: 0 additions & 4 deletions code/__DEFINES/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ Will print: "/mob/living/carbon/human/death" (you can optionally embed it in a s
#define GAME_STATE_SETTING_UP 2
#define GAME_STATE_PLAYING 3
#define GAME_STATE_FINISHED 4
//SOUND:
#define SOUND_MINIMUM_PRESSURE 10
#define FALLOFF_SOUNDS 1
#define SURROUND_CAP 7

//FONTS:
// Used by Paper and PhotoCopier (and PaperBin once a year).
Expand Down
8 changes: 7 additions & 1 deletion code/__DEFINES/sound.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
#define CHANNEL_JUKEBOX 1021
#define CHANNEL_JUSTICAR_ARK 1020
#define CHANNEL_HEARTBEAT 1019 //sound channel for heartbeats
#define CHANNEL_AMBIENCE 1018
#define CHANNEL_BUZZ 1017
#define CHANNEL_BICYCLE 1016

//THIS SHOULD ALWAYS BE THE LOWEST ONE!
//KEEP IT UPDATED

#define CHANNEL_HIGHEST_AVAILABLE 1018
#define CHANNEL_HIGHEST_AVAILABLE 1015


#define SOUND_MINIMUM_PRESSURE 10
#define FALLOFF_SOUNDS 0.5
4 changes: 2 additions & 2 deletions code/game/area/areas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
52 changes: 26 additions & 26 deletions code/game/sound.dm
Original file line number Diff line number Diff line change
@@ -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/distance = get_dist(M, turf_source)

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, surround, channel, pressure_affected)
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, surround = 1, channel = 0, pressure_affected = TRUE)
/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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -146,6 +146,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)
6 changes: 3 additions & 3 deletions code/modules/client/preferences_toggles.dm
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ TOGGLE_CHECKBOX(/datum/verbs/menu/Settings/Sound, Toggle_Soundscape)()
to_chat(usr, "You will now hear ambient sounds.")
else
to_chat(usr, "You will no longer hear ambient sounds.")
usr << sound(null, repeat = 0, wait = 0, volume = 0, channel = 1)
usr << sound(null, repeat = 0, wait = 0, volume = 0, channel = 2)
usr.stop_sound_channel(CHANNEL_AMBIENCE)
usr.stop_sound_channel(CHANNEL_BUZZ)
SSblackbox.add_details("preferences_verb","Toggle Ambience|[usr.client.prefs.toggles & SOUND_AMBIENCE]") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
/datum/verbs/menu/Settings/Sound/Toggle_Soundscape/Get_checked(client/C)
return C.prefs.toggles & SOUND_AMBIENCE
Expand All @@ -191,7 +191,7 @@ TOGGLE_CHECKBOX(/datum/verbs/menu/Settings/Sound, toggle_ship_ambience)()
to_chat(usr, "You will now hear ship ambience.")
else
to_chat(usr, "You will no longer hear ship ambience.")
usr << sound(null, repeat = 0, wait = 0, volume = 0, channel = 2)
usr.stop_sound_channel(CHANNEL_BUZZ)
usr.client.ambience_playing = 0
SSblackbox.add_details("preferences_verb", "Toggle Ship Ambience|[usr.client.prefs.toggles & SOUND_SHIP_AMBIENCE]") //If you are copy-pasting this, I bet you read this comment expecting to see the same thing :^)
/datum/verbs/menu/Settings/Sound/toggle_ship_ambience/Get_checked(client/C)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/vehicles/bicycle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

/obj/vehicle/bicycle/buckle_mob(mob/living/M, force = 0, check_loc = 1)
if(prob(easter_egg_chance) || (SSevents.holidays && SSevents.holidays[APRIL_FOOLS]))
M << sound(pick(bike_music), repeat = 1, wait = 0, volume = 80, channel = 42)
M << sound(pick(bike_music), repeat = 1, wait = 0, volume = 80, channel = CHANNEL_BICYCLE)
. = ..()

/obj/vehicle/bicycle/unbuckle_mob(mob/living/buckled_mob,force = 0)
if(buckled_mob)
buckled_mob << sound(null, repeat = 0, wait = 0, volume = 80, channel = 42)
buckled_mob.stop_sound_channel(CHANNEL_BICYCLE)
. =..()

/obj/vehicle/bicycle/tesla_act() // :::^^^)))
Expand Down

0 comments on commit 25c35c2

Please sign in to comment.