Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions code/datums/datumvars.dm
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
body += "<option value='?_src_=vars;toggle_aliasing=\ref[D]'>Toggle Transform Aliasing</option>"
if(istype(D,/obj/item/weapon/gun))
body += "<option value='?_src_=vars;projectile_edit=\ref[D]'>Edit Projectile Variables</option>"
if(has_initialized_sound_emitter(D))
if(istype(D, /atom/movable))
body += "<option value='?_src_=vars;halt_sound=\ref[D]'>Stop Sound</option>"


Expand Down Expand Up @@ -997,9 +997,9 @@ function loadPage(list) {
if (!check_rights(R_DEBUG))
return

var/atom/A = locate(href_list["halt_sound"])
if(!istype(A) || !has_initialized_sound_emitter(A))
to_chat(src, "This can only be done to atoms that have an initialized sound emitter")
var/atom/movable/A = locate(href_list["halt_sound"])
if(!istype(A) || (A.sound_emitter == null))
to_chat(src, "This can only be done to atom/movables that have an initialized sound emitter")
return

A.sound_emitter.stop()
Expand Down
10 changes: 7 additions & 3 deletions code/modules/sound/sound_emitter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
The subscription is driven by the SZM, which maintains a hashmap of sound_emitter locations.
*/

/atom
/atom/movable
var/datum/sound_emitter/sound_emitter

/atom/movable/Destroy()
qdel(sound_emitter)
return ..()

/atom/proc/setup_sound()
return

Expand Down Expand Up @@ -91,7 +95,7 @@
/datum/sound_emitter/Destroy()
sound_emitter_collection.remove(src)
sound_zone_manager.unregister_emitter(src)
deactivate();
deactivate()
if (sounds)
sounds.Cut()
sounds = null
Expand Down Expand Up @@ -219,7 +223,7 @@
// halt sounds to clients, unregister from dynamic updates
/datum/sound_emitter/proc/deactivate()
active_sound = null

INVOKE_EVENT(src, /event/sound_stopped, "emitter" = src)

/datum/sound_emitter/proc/update_env_effect()
Expand Down
23 changes: 11 additions & 12 deletions code/modules/sound/sound_listener_context/sound_listener_context.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@
var/mob/proxy = null
var/list/current_channels_by_emitter = list()
var/list/free_channels = list()
var/list/audible_emitters = list()
var/range = null

/datum/sound_listener_context/New(client/C, mob/P, hearing_range = world.view)
client = C
proxy = P
current_channels_by_emitter = list()
free_channels = list()
audible_emitters = list()
for (var/i = CHANNEL_RESERVABLE_MIN, i <= CHANNEL_RESERVABLE_MAX, i++)
free_channels += i
range = hearing_range
Expand All @@ -69,6 +71,9 @@
/datum/sound_listener_context/Destroy()
for (var/datum/sound_emitter/E in current_channels_by_emitter)
release(E)
for (var/datum/sound_emitter/E in audible_emitters)
unsubscribe_from(E)
audible_emitters.Cut()
free_channels.Cut()
current_channels_by_emitter.Cut()
sound_zone_manager.unregister_listener(src)
Expand Down Expand Up @@ -96,7 +101,7 @@
// which channel this client is using for this emitter
var/chan = current_channels_by_emitter[E]
if (!chan)
CRASH("listener_context attempted to release [E] with no channel, possible double-release or other fuckery")
return //no channel to release, no sound to stop (hopefully)
// flush it
var/sound/nullsound = sound(file = null)
nullsound.channel = chan
Expand All @@ -106,8 +111,6 @@
current_channels_by_emitter -= E
free_channels += chan

unsubscribe_from(E)

/datum/sound_listener_context/proc/reset_proxy(mob/P)
sound_zone_manager.unregister_listener(src)
proxy = P
Expand All @@ -131,7 +134,6 @@
E.register_event(/event/sound_stopped, src, nameof(src::stop_hearing()))
E.register_event(/event/sound_pushed, src, nameof(src::hear_once()))


/datum/sound_listener_context/proc/unsubscribe_from(datum/sound_emitter/E)
E.unregister_event(/event/sound_updated, src, nameof(src::on_sound_update()))
E.unregister_event(/event/sound_started, src, nameof(src::start_hearing()))
Expand Down Expand Up @@ -161,13 +163,7 @@
client << S

/datum/sound_listener_context/proc/stop_hearing(datum/sound_emitter/emitter)
var/chan = current_channels_by_emitter[emitter]
if (!chan)
return // already can't hear it (probably)
var/sound/nullsound = sound(file = null)
nullsound.channel = chan
nullsound.status = SOUND_UPDATE | SOUND_MUTE
client << nullsound
release(emitter)

/datum/sound_listener_context/proc/on_sound_update(datum/sound_emitter/emitter)
var/chan = current_channels_by_emitter[emitter]
Expand All @@ -184,6 +180,9 @@
/datum/sound_listener_context/proc/on_enter_range(datum/sound_emitter/E)
start_hearing(E) // this can throw if channel reservation fails, subscribe after its safe
subscribe_to(E)
audible_emitters |= E

/datum/sound_listener_context/proc/on_exit_range(datum/sound_emitter/E)
release(E)
stop_hearing(E)
unsubscribe_from(E)
audible_emitters -= E
4 changes: 2 additions & 2 deletions code/modules/sound/sound_zone_manager.dm
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var/global/datum/sound_zone_manager/sound_zone_manager = new
CRASH("Found a listener with no client or endpoint client")
var/datum/sound_listener_context/context = client.listener_context

if (E in context.current_channels_by_emitter)
if (E in context.audible_emitters)
if (!E.contains(listener))
context.on_exit_range(E)
else
Expand Down Expand Up @@ -197,7 +197,7 @@ var/global/datum/sound_zone_manager/sound_zone_manager = new
var/datum/sound_listener_context/context = receive_client.listener_context

var/list/current = list()
for (var/datum/sound_emitter/E in context.current_channels_by_emitter)
for (var/datum/sound_emitter/E in context.audible_emitters)
current[E] = TRUE
var/list/fresh = list()

Expand Down
Loading