From 3db9c9ddb770601fa7829385b6daad253ffca989 Mon Sep 17 00:00:00 2001 From: CitadelStationBot Date: Fri, 28 Jul 2017 09:02:21 -0500 Subject: [PATCH] Adds 3D Sound System --- code/__DEFINES/misc.dm | 4 -- code/__DEFINES/sound.dm.rej | 51 ++++++++++++++++++++ code/game/area/areas.dm | 4 +- code/game/sound.dm | 54 +++++++++++----------- code/game/sound.dm.rej | 9 ++++ code/modules/client/preferences_toggles.dm | 6 +-- code/modules/vehicles/bicycle.dm | 4 +- 7 files changed, 94 insertions(+), 38 deletions(-) create mode 100644 code/__DEFINES/sound.dm.rej create mode 100644 code/game/sound.dm.rej diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index dcad7f531e..e0ab84f832 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -167,10 +167,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). diff --git a/code/__DEFINES/sound.dm.rej b/code/__DEFINES/sound.dm.rej new file mode 100644 index 0000000000..c54b9b4b64 --- /dev/null +++ b/code/__DEFINES/sound.dm.rej @@ -0,0 +1,51 @@ +diff a/code/__DEFINES/sound.dm b/code/__DEFINES/sound.dm (rejected hunks) +@@ -5,42 +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 +- +-//BYOND Sound Environment defines +- +-#define SOUND_ENV_DEFAULT -1 +-#define SOUND_ENV_GENERIC 0 +-#define SOUND_ENV_PADDED_CELL 1 +-#define SOUND_ENV_ROOM 2 +-#define SOUND_ENV_BATHROOM 3 +-#define SOUND_ENV_LIVINGROOM 4 +-#define SOUND_ENV_STONEROOM 5 +-#define SOUND_ENV_AUDITORIUM 6 +-#define SOUND_ENV_CONCERT_HALL 7 +-#define SOUND_ENV_CAVE 8 +-#define SOUND_ENV_ARENA 9 +-#define SOUND_ENV_HANGAR 10 +-#define SOUND_ENV_CARPETTED_HALLWAY 11 +-#define SOUND_ENV_HALLWAY 12 +-#define SOUND_ENV_STONE_CORRIDOOR 13 +-#define SOUND_ENV_ALLEY 14 +-#define SOUND_ENV_FOREST 15 +-#define SOUND_ENV_CITY 16 +-#define SOUND_ENV_MOUNTAINS 17 +-#define SOUND_ENV_QUARRY 18 +-#define SOUND_ENV_PLAIN 19 +-#define SOUND_ENV_PARKING_LOT 20 +-#define SOUND_ENV_SEWER_PIPE 21 +-#define SOUND_ENV_UNDERWATER 22 +-#define SOUND_ENV_DRUGGED 23 +-#define SOUND_ENV_DIZZY 24 +-#define SOUND_ENV_PSYCHOTIC 25 +\ No newline at end of file ++#define FALLOFF_SOUNDS 0.5 +\ No newline at end of file diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index c71ea6a10f..a0f268344e 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -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) diff --git a/code/game/sound.dm b/code/game/sound.dm index 3cbe2893b7..adee6b39e2 100644 --- a/code/game/sound.dm +++ b/code/game/sound.dm @@ -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 diff --git a/code/game/sound.dm.rej b/code/game/sound.dm.rej new file mode 100644 index 0000000000..bf2bbbce69 --- /dev/null +++ b/code/game/sound.dm.rej @@ -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) diff --git a/code/modules/client/preferences_toggles.dm b/code/modules/client/preferences_toggles.dm index 943999aecc..d56b6e0619 100644 --- a/code/modules/client/preferences_toggles.dm +++ b/code/modules/client/preferences_toggles.dm @@ -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 @@ -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) diff --git a/code/modules/vehicles/bicycle.dm b/code/modules/vehicles/bicycle.dm index d51de5809c..2d9b3c8258 100644 --- a/code/modules/vehicles/bicycle.dm +++ b/code/modules/vehicles/bicycle.dm @@ -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() // :::^^^)))