From 83229034da61e83d845a06d3d859eef5e84eb308 Mon Sep 17 00:00:00 2001
From: Luc <89928798+lewcc@users.noreply.github.com>
Date: Sun, 23 Jul 2023 15:32:35 -0700
Subject: [PATCH] Significantly reduce volume of disposals machinery when
processing a ton of items (#21700)
* Reduce volume of recycler when consuming a ton of items
* Quiets up the rest of disposals machinery
* Defines, not magic numbers
* Apply suggestions from code review
Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com>
---------
Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com>
---
code/game/machinery/recycler.dm | 8 +++++-
code/modules/recycling/disposal.dm | 32 ++++++++++++++++++----
code/modules/recycling/sortingmachinery.dm | 4 ++-
3 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/code/game/machinery/recycler.dm b/code/game/machinery/recycler.dm
index 79dd4d22008..478821874eb 100644
--- a/code/game/machinery/recycler.dm
+++ b/code/game/machinery/recycler.dm
@@ -1,4 +1,5 @@
#define SAFETY_COOLDOWN 100
+#define SOUND_COOLDOWN (0.5 SECONDS)
/obj/machinery/recycler
name = "recycler"
@@ -19,6 +20,8 @@
var/item_recycle_sound = 'sound/machines/recycler.ogg'
/// For admin fun, var edit always_gib to TRUE (1)
var/always_gib = FALSE
+ /// The last time we played a consumption sound.
+ var/last_consumption_sound
/obj/machinery/recycler/Initialize(mapload)
. = ..()
@@ -137,8 +140,9 @@
playsound(loc, 'sound/machines/buzz-sigh.ogg', 50, 0)
AM.forceMove(loc)
- if(items_recycled && sound)
+ if(items_recycled && sound && (last_consumption_sound + SOUND_COOLDOWN) < world.time)
playsound(loc, item_recycle_sound, 100, 0)
+ last_consumption_sound = world.time
/obj/machinery/recycler/proc/recycle_item(obj/item/I)
I.forceMove(loc)
@@ -243,3 +247,5 @@
/obj/item/paper/recycler
name = "paper - 'garbage duty instructions'"
info = "
New Assignment
You have been assigned to collect garbage from trash bins, located around the station. The crewmembers will put their trash into it and you will collect the said trash.
There is a recycling machine near your closet, inside maintenance; use it to recycle the trash for a small chance to get useful minerals. Then deliver these minerals to cargo or engineering. You are our last hope for a clean station, do not screw this up!"
+
+#undef SOUND_COOLDOWN
diff --git a/code/modules/recycling/disposal.dm b/code/modules/recycling/disposal.dm
index 2cb3c2e8ea4..843204359f7 100644
--- a/code/modules/recycling/disposal.dm
+++ b/code/modules/recycling/disposal.dm
@@ -6,6 +6,8 @@
// Can hold items and human size things, no other draggables
// Toilets are a type of disposal bin for small objects only and work on magic. By magic, I mean torque rotation
#define SEND_PRESSURE 0.05*ONE_ATMOSPHERE
+/// How frequently disposals can make sounds, to prevent huge sound stacking
+#define DISPOSAL_SOUND_COOLDOWN (0.1 SECONDS)
/obj/machinery/disposal
name = "disposal unit"
@@ -464,7 +466,7 @@
H.tomail = 1
sleep(10)
- if(last_sound < world.time + 1)
+ if(last_sound + DISPOSAL_SOUND_COOLDOWN < world.time)
playsound(src, 'sound/machines/disposalflush.ogg', 50, 0, 0)
last_sound = world.time
sleep(5) // wait for animation to finish
@@ -499,7 +501,10 @@
/obj/machinery/disposal/proc/expel(obj/structure/disposalholder/H)
var/turf/target
- playsound(src, 'sound/machines/hiss.ogg', 50, 0, 0)
+ if(last_sound + DISPOSAL_SOUND_COOLDOWN < world.time)
+ playsound(src, 'sound/machines/hiss.ogg', 50, 0, FALSE)
+ last_sound = world.time
+
if(H) // Somehow, someone managed to flush a window which broke mid-transit and caused the disposal to go in an infinite loop trying to expel null, hopefully this fixes it
for(var/atom/movable/AM in H)
target = get_offset_target_turf(src.loc, rand(5)-rand(5), rand(5)-rand(5))
@@ -733,6 +738,8 @@
plane = FLOOR_PLANE
layer = DISPOSAL_PIPE_LAYER // slightly lower than wires and other pipes
base_icon_state // initial icon state on map
+ /// The last time a sound was played from this
+ var/last_sound
// new pipe, set the icon_state as on map
/obj/structure/disposalpipe/Initialize(mapload)
@@ -841,7 +848,10 @@
else // otherwise limit to 10 tiles
target = get_ranged_target_turf(T, direction, 10)
- playsound(src, 'sound/machines/hiss.ogg', 50, 0, 0)
+ if(last_sound + DISPOSAL_SOUND_COOLDOWN < world.time)
+ playsound(src, 'sound/machines/hiss.ogg', 50, 0, FALSE)
+ last_sound = world.time
+
if(H)
for(var/atom/movable/AM in H)
AM.forceMove(T)
@@ -856,7 +866,9 @@
else // no specified direction, so throw in random direction
- playsound(src, 'sound/machines/hiss.ogg', 50, 0, 0)
+ if(last_sound + DISPOSAL_SOUND_COOLDOWN < world.time)
+ playsound(src, 'sound/machines/hiss.ogg', 50, 0, FALSE)
+ last_sound = world.time
if(H)
for(var/atom/movable/AM in H)
target = get_offset_target_turf(T, rand(5)-rand(5), rand(5)-rand(5))
@@ -1378,6 +1390,8 @@
var/turf/target // this will be where the output objects are 'thrown' to.
var/obj/structure/disposalpipe/trunk/linkedtrunk
var/mode = FALSE // Is the maintenance panel open? Different than normal disposal's mode
+ /// The last time a sound was played
+ var/last_sound
/obj/structure/disposaloutlet/Initialize(mapload)
. = ..()
@@ -1401,9 +1415,15 @@
/obj/structure/disposaloutlet/proc/expel(animation = TRUE)
if(animation)
flick("outlet-open", src)
- playsound(src, 'sound/machines/warning-buzzer.ogg', 50, 0, 0)
+ var/play_sound = FALSE
+ if(last_sound + DISPOSAL_SOUND_COOLDOWN < world.time)
+ play_sound = TRUE
+ last_sound = world.time
+ if(play_sound)
+ playsound(src, 'sound/machines/warning-buzzer.ogg', 50, 0, FALSE)
sleep(20) //wait until correct animation frame
- playsound(src, 'sound/machines/hiss.ogg', 50, 0, 0)
+ if(play_sound)
+ playsound(src, 'sound/machines/hiss.ogg', 50, 0, FALSE)
for(var/atom/movable/AM in contents)
AM.forceMove(loc)
AM.pipe_eject(dir)
diff --git a/code/modules/recycling/sortingmachinery.dm b/code/modules/recycling/sortingmachinery.dm
index 0b27a453fc5..b6a66781525 100644
--- a/code/modules/recycling/sortingmachinery.dm
+++ b/code/modules/recycling/sortingmachinery.dm
@@ -317,7 +317,9 @@
H.destinationTag = 1
sleep(10)
- playsound(src, 'sound/machines/disposalflush.ogg', 50, 0, 0)
+ if(last_sound + DISPOSAL_SOUND_COOLDOWN < world.time)
+ playsound(src, 'sound/machines/disposalflush.ogg', 50, 0, FALSE)
+ last_sound = world.time
sleep(5) // wait for animation to finish
H.init(src) // copy the contents of disposer to holder