From 6ea8b19eb99e0dba34e0a93bc6c6e5a0bbeef966 Mon Sep 17 00:00:00 2001
From: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
Date: Mon, 22 Nov 2021 23:19:33 -0800
Subject: [PATCH] Add disabling footstep sounds and parallax to the lag switch
panel (#62999)
At the last Toolbox Tournament, @MrStonedOne pointed out some big performance consumers. Some are disablable through easy means, but others were not. This adds two easy ones to the mix.
---
code/__DEFINES/lag_switch.dm | 24 +++++++++++++++++-------
code/_onclick/hud/parallax.dm | 4 ++++
code/controllers/subsystem/lag_switch.dm | 15 ++++++++++++++-
code/datums/elements/footstep.dm | 12 +++++++++++-
code/modules/admin/verbs/admingame.dm | 4 +++-
5 files changed, 49 insertions(+), 10 deletions(-)
diff --git a/code/__DEFINES/lag_switch.dm b/code/__DEFINES/lag_switch.dm
index fd1fc579a63..2115ce4a5dd 100644
--- a/code/__DEFINES/lag_switch.dm
+++ b/code/__DEFINES/lag_switch.dm
@@ -1,10 +1,20 @@
// All of the possible Lag Switch lag mitigation measures
// If you add more do not forget to update MEASURES_AMOUNT accordingly
-#define DISABLE_DEAD_KEYLOOP 1 // Stops ghosts flying around freely, they can still jump and orbit, staff exempted
-#define DISABLE_GHOST_ZOOM_TRAY 2 // Stops ghosts using zoom/t-ray verbs and resets their view if zoomed out, staff exempted
-#define DISABLE_RUNECHAT 3 // Disable runechat and enable the bubbles, speaking mobs with TRAIT_BYPASS_MEASURES exempted
-#define DISABLE_USR_ICON2HTML 4 // Disable icon2html procs from verbs like examine, mobs calling with TRAIT_BYPASS_MEASURES exempted
-#define DISABLE_NON_OBSJOBS 5 // Prevents anyone from joining the game as anything but observer
-#define SLOWMODE_SAY 6 // Limit IC/dchat spam to one message every x seconds per client, TRAIT_BYPASS_MEASURES exempted
+/// Stops ghosts flying around freely, they can still jump and orbit, staff exempted
+#define DISABLE_DEAD_KEYLOOP 1
+/// Stops ghosts using zoom/t-ray verbs and resets their view if zoomed out, staff exempted
+#define DISABLE_GHOST_ZOOM_TRAY 2
+/// Disable runechat and enable the bubbles, speaking mobs with TRAIT_BYPASS_MEASURES exempted
+#define DISABLE_RUNECHAT 3
+/// Disable icon2html procs from verbs like examine, mobs calling with TRAIT_BYPASS_MEASURES exempted
+#define DISABLE_USR_ICON2HTML 4
+/// Prevents anyone from joining the game as anything but observer
+#define DISABLE_NON_OBSJOBS 5
+/// Limit IC/dchat spam to one message every x seconds per client, TRAIT_BYPASS_MEASURES exempted
+#define SLOWMODE_SAY 6
+/// Disables parallax, as if everyone had disabled their preference, TRAIT_BYPASS_MEASURES exempted
+#define DISABLE_PARALLAX 7
+/// Disables footsteps, TRAIT_BYPASS_MEASURES exempted
+#define DISABLE_FOOTSTEPS 8
-#define MEASURES_AMOUNT 6 // The total number of switches defined above
+#define MEASURES_AMOUNT 8 // The total number of switches defined above
diff --git a/code/_onclick/hud/parallax.dm b/code/_onclick/hud/parallax.dm
index 1d09819f986..5bd240bf6b5 100755
--- a/code/_onclick/hud/parallax.dm
+++ b/code/_onclick/hud/parallax.dm
@@ -46,6 +46,10 @@
/datum/hud/proc/apply_parallax_pref(mob/viewmob)
var/mob/screenmob = viewmob || mymob
+
+ if (SSlag_switch.measures[DISABLE_PARALLAX] && !HAS_TRAIT(viewmob, TRAIT_BYPASS_MEASURES))
+ return FALSE
+
var/client/C = screenmob.client
if(C.prefs)
var/pref = C.prefs.read_preference(/datum/preference/choiced/parallax)
diff --git a/code/controllers/subsystem/lag_switch.dm b/code/controllers/subsystem/lag_switch.dm
index 4a2be78e908..0c3780750ea 100644
--- a/code/controllers/subsystem/lag_switch.dm
+++ b/code/controllers/subsystem/lag_switch.dm
@@ -10,7 +10,7 @@ SUBSYSTEM_DEF(lag_switch)
/// List of bools corresponding to code/__DEFINES/lag_switch.dm
var/static/list/measures[MEASURES_AMOUNT]
/// List of measures that toggle automatically
- var/list/auto_measures = list(DISABLE_GHOST_ZOOM_TRAY, DISABLE_RUNECHAT, DISABLE_USR_ICON2HTML)
+ var/list/auto_measures = list(DISABLE_GHOST_ZOOM_TRAY, DISABLE_RUNECHAT, DISABLE_USR_ICON2HTML, DISABLE_PARALLAX, DISABLE_FOOTSTEPS)
/// Timer ID for the automatic veto period
var/veto_timer_id
/// Cooldown between say verb uses when slowmode is enabled
@@ -111,6 +111,19 @@ SUBSYSTEM_DEF(lag_switch)
to_chat(world, span_boldannounce("Slowmode for IC/dead chat has been disabled by an admin."))
if(DISABLE_NON_OBSJOBS)
world.update_status()
+ if(DISABLE_PARALLAX)
+ if (state)
+ to_chat(world, span_boldannounce("Parallax has been disabled for performance concerns."))
+ else
+ to_chat(world, span_boldannounce("Parallax has been re-enabled."))
+
+ for (var/mob/mob as anything in GLOB.mob_list)
+ mob.hud_used?.update_parallax_pref()
+ if (DISABLE_FOOTSTEPS)
+ if (state)
+ to_chat(world, span_boldannounce("Footstep sounds have been disabled for performance concerns."))
+ else
+ to_chat(world, span_boldannounce("Footstep sounds have been re-enabled."))
return TRUE
diff --git a/code/datums/elements/footstep.dm b/code/datums/elements/footstep.dm
index 0c07ea30b96..e47c03a813c 100644
--- a/code/datums/elements/footstep.dm
+++ b/code/datums/elements/footstep.dm
@@ -1,3 +1,5 @@
+#define SHOULD_DISABLE_FOOTSTEPS(source) ((SSlag_switch.measures[DISABLE_FOOTSTEPS] && !(HAS_TRAIT(source, TRAIT_BYPASS_MEASURES))) || HAS_TRAIT(source, TRAIT_SILENT_FOOTSTEPS))
+
///Footstep element. Plays footsteps at parents location when it is appropriate.
/datum/element/footstep
element_flags = ELEMENT_DETACH|ELEMENT_BESPOKE
@@ -92,6 +94,9 @@
/datum/element/footstep/proc/play_simplestep(mob/living/source)
SIGNAL_HANDLER
+ if (SHOULD_DISABLE_FOOTSTEPS(source))
+ return
+
var/turf/open/source_loc = prepare_step(source)
if(!source_loc)
return
@@ -115,7 +120,7 @@
/datum/element/footstep/proc/play_humanstep(mob/living/carbon/human/source)
SIGNAL_HANDLER
- if(HAS_TRAIT(source, TRAIT_SILENT_FOOTSTEPS))
+ if (SHOULD_DISABLE_FOOTSTEPS(source))
return
var/volume_multiplier = 1
@@ -149,7 +154,12 @@
/datum/element/footstep/proc/play_simplestep_machine(atom/movable/source)
SIGNAL_HANDLER
+ if (SHOULD_DISABLE_FOOTSTEPS(source))
+ return
+
var/turf/open/source_loc = get_turf(source)
if(!istype(source_loc))
return
playsound(source_loc, footstep_sounds, 50, falloff_distance = 1, vary = sound_vary)
+
+#undef SHOULD_DISABLE_FOOTSTEPS
diff --git a/code/modules/admin/verbs/admingame.dm b/code/modules/admin/verbs/admingame.dm
index 399ea9bcb23..2152160993d 100644
--- a/code/modules/admin/verbs/admingame.dm
+++ b/code/modules/admin/verbs/admingame.dm
@@ -477,5 +477,7 @@ Traitors and the like can also be revived with the previous role mostly intact.
dat += "Slowmode say verb (informs world): [SSlag_switch.measures[SLOWMODE_SAY] ? "On" : "Off"]
"
dat += "Disable runechat: [SSlag_switch.measures[DISABLE_RUNECHAT] ? "On" : "Off"] - trait applies to speaker
"
dat += "Disable examine icons: [SSlag_switch.measures[DISABLE_USR_ICON2HTML] ? "On" : "Off"] - trait applies to examiner
"
+ dat += "Disable parallax: [SSlag_switch.measures[DISABLE_PARALLAX] ? "On" : "Off"] - trait applies to character
"
+ dat += "Disable footsteps: [SSlag_switch.measures[DISABLE_FOOTSTEPS] ? "On" : "Off"] - trait applies to character
"
dat += "