From 7af014de84a4399322dde8c9755bb759acc4c548 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sat, 25 Mar 2017 18:54:04 -0400 Subject: [PATCH] Add support for specific sound channels and stopping them (#25455) --- code/__DEFINES/sound.dm | 2 ++ code/game/sound.dm | 14 +++++++------- code/modules/client/preferences.dm | 6 +++--- code/modules/client/preferences_toggles.dm | 3 +-- code/modules/holiday/holidays.dm | 1 - code/modules/mob/dead/new_player/new_player.dm | 4 ++-- code/modules/mob/transform_procs.dm | 2 +- tgstation.dme | 1 + 8 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 code/__DEFINES/sound.dm diff --git a/code/__DEFINES/sound.dm b/code/__DEFINES/sound.dm new file mode 100644 index 00000000000..155f599d899 --- /dev/null +++ b/code/__DEFINES/sound.dm @@ -0,0 +1,2 @@ +//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 \ No newline at end of file diff --git a/code/game/sound.dm b/code/game/sound.dm index 91b016d061d..9493e729abd 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) +/proc/playsound(atom/source, soundin, vol as num, vary, extrarange as num, falloff, surround = 1, frequency = null, channel = 0) soundin = get_sfx(soundin) // same sound for everyone @@ -18,15 +18,15 @@ 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) + M.playsound_local(turf_source, soundin, vol, vary, frequency, falloff, surround, channel) -/atom/proc/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff, surround = 1) +/atom/proc/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff, surround = 1, channel = 0) soundin = get_sfx(soundin) var/sound/S = sound(soundin) S.wait = 0 //No queue - S.channel = 0 //Any channel + S.channel = channel S.volume = vol if (vary) @@ -79,14 +79,14 @@ return ..() -/mob/proc/stopLobbySound() - src << sound(null, repeat = 0, wait = 0, volume = 85, channel = 1) +/mob/proc/stop_sound_channel(chan) + src << sound(null, repeat = 0, wait = 0, channel = chan) /client/proc/playtitlemusic() UNTIL(ticker.login_music) //wait for ticker init to set the login music if(prefs && (prefs.toggles & SOUND_LOBBY)) - src << sound(ticker.login_music, repeat = 0, wait = 0, volume = 85, channel = 1) // MAD JAMS + src << sound(ticker.login_music, repeat = 0, wait = 0, volume = 85, channel = CHANNEL_LOBBYMUSIC) // MAD JAMS /proc/get_rand_frequency() return rand(32000, 55000) //Frequency stuff only works with 45kbps oggs. diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index 35cf9111aad..30bc303fd44 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -1181,10 +1181,10 @@ var/list/preferences_datums = list() if("lobby_music") toggles ^= SOUND_LOBBY - if(toggles & SOUND_LOBBY) - user << sound(ticker.login_music, repeat = 0, wait = 0, volume = 85, channel = 1) + if((toggles & SOUND_LOBBY) && user.client) + user.client.playtitlemusic() else - user.stopLobbySound() + user.stop_sound_channel(CHANNEL_LOBBYMUSIC) if("ghost_ears") chat_toggles ^= CHAT_GHOSTEARS diff --git a/code/modules/client/preferences_toggles.dm b/code/modules/client/preferences_toggles.dm index 963da256330..8a82649d6b7 100644 --- a/code/modules/client/preferences_toggles.dm +++ b/code/modules/client/preferences_toggles.dm @@ -147,8 +147,7 @@ playtitlemusic() else to_chat(src, "You will no longer hear music in the game lobby.") - if(isnewplayer(mob)) - mob.stopLobbySound() + mob.stop_sound_channel(CHANNEL_LOBBYMUSIC) feedback_add_details("admin_verb","TLobby") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! /client/verb/togglemidis() diff --git a/code/modules/holiday/holidays.dm b/code/modules/holiday/holidays.dm index 27c178e466f..89e4ebafcc7 100644 --- a/code/modules/holiday/holidays.dm +++ b/code/modules/holiday/holidays.dm @@ -146,7 +146,6 @@ ticker.login_music = 'sound/ambience/clown.ogg' for(var/mob/dead/new_player/P in mob_list) if(P.client) - P.stopLobbySound() P.client.playtitlemusic() /datum/holiday/fourtwenty diff --git a/code/modules/mob/dead/new_player/new_player.dm b/code/modules/mob/dead/new_player/new_player.dm index 7a01f7209f1..894751b6e61 100644 --- a/code/modules/mob/dead/new_player/new_player.dm +++ b/code/modules/mob/dead/new_player/new_player.dm @@ -141,7 +141,7 @@ observer.real_name = observer.client.prefs.real_name observer.name = observer.real_name observer.update_icon() - observer.stopLobbySound() + observer.stop_sound_channel(CHANNEL_LOBBYMUSIC) qdel(mind) qdel(src) @@ -471,7 +471,7 @@ . = new_character if(.) new_character.key = key //Manually transfer the key to log them in - new_character.stopLobbySound() + new_character.stop_sound_channel(CHANNEL_LOBBYMUSIC) /mob/dead/new_player/proc/ViewManifest() var/dat = "" diff --git a/code/modules/mob/transform_procs.dm b/code/modules/mob/transform_procs.dm index 73a197b6b9f..943fba19529 100644 --- a/code/modules/mob/transform_procs.dm +++ b/code/modules/mob/transform_procs.dm @@ -308,7 +308,7 @@ /mob/proc/AIize(transfer_after = TRUE) if(client) - stopLobbySound() + stop_sound_channel(CHANNEL_LOBBYMUSIC) var/turf/loc_landmark for(var/obj/effect/landmark/start/sloc in landmarks_list) diff --git a/tgstation.dme b/tgstation.dme index e12e05da73a..4a0965d22ee 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -55,6 +55,7 @@ #include "code\__DEFINES\say.dm" #include "code\__DEFINES\shuttles.dm" #include "code\__DEFINES\sight.dm" +#include "code\__DEFINES\sound.dm" #include "code\__DEFINES\stat.dm" #include "code\__DEFINES\status_effects.dm" #include "code\__DEFINES\tgui.dm"