Files
MrMelbert 5146cfd403 Moves camera update handling to background subsystem, (maybe) fixing lag (#92208)
## About The Pull Request

When a camera update is triggered, it is instead added to a queue on a
background subsystem

An AI entering a camera chunk which is queued to update will force the
update immediately (bypassing the queue)

While the root problem of this is, ultimately, not addressed...

<img width="554" height="58"
alt="467828777-eff3f0e5-49d6-4997-b4d7-05eff6432155"
src="https://github.com/user-attachments/assets/c2d6a5f5-d958-463e-959f-116bd0dab475"
/>

...the change will ultimately prevent update spam from consuming all of
the server's resources - instead allocating updates to the backburner in
times of high server stress (or on multi-z maps)

## Changelog

🆑 Melbert
refactor: Refactored the way camera updates are handled to hopefully
reduce some lag. Report any oddities
/🆑
2025-11-08 01:43:48 +01:00

70 lines
2.0 KiB
Plaintext

/// Simple component to integrate a bodycam into a mob
/datum/component/simple_bodycam
dupe_mode = COMPONENT_DUPE_SELECTIVE
/// The actual camera, in our mob's contents
VAR_PRIVATE/obj/machinery/camera/bodycam
/// How fast we update
var/camera_update_time = 0.5 SECONDS
/datum/component/simple_bodycam/Initialize(
camera_name = "bodycam",
c_tag = capitalize(camera_name),
network = "ss13",
emp_proof = FALSE,
camera_update_time = 0.5 SECONDS,
)
if(!isliving(parent))
return COMPONENT_INCOMPATIBLE
src.camera_update_time = camera_update_time
bodycam = new(parent)
bodycam.network = list(network)
bodycam.name = camera_name
bodycam.c_tag = c_tag
if(emp_proof)
bodycam.AddElement(/datum/element/empprotection, EMP_PROTECT_ALL)
RegisterSignal(parent, COMSIG_MOVABLE_MOVED, PROC_REF(update_cam))
RegisterSignal(parent, COMSIG_ATOM_DIR_CHANGE, PROC_REF(rotate_cam))
RegisterSignals(bodycam, list(COMSIG_QDELETING, COMSIG_MOVABLE_MOVED), PROC_REF(camera_gone))
do_update_cam()
/datum/component/simple_bodycam/Destroy()
if(QDELETED(bodycam))
bodycam = null
else
QDEL_NULL(bodycam)
return ..()
/datum/component/simple_bodycam/CheckDupeComponent(
datum/component/simple_bodycam/new_bodycam, // will be null
camera_name,
c_tag,
network = "ss13",
emp_proof,
camera_update_time,
)
// Dupes are only allowed if we don't have a camera on that network already
return (network in bodycam.network)
/datum/component/simple_bodycam/proc/update_cam(datum/source, atom/old_loc, ...)
SIGNAL_HANDLER
if(get_turf(old_loc) != get_turf(parent))
do_update_cam()
/datum/component/simple_bodycam/proc/do_update_cam()
SScameras.update_portable_camera(bodycam, camera_update_time)
/datum/component/simple_bodycam/proc/rotate_cam(datum/source, old_dir, new_dir)
SIGNAL_HANDLER
// I don't actually think cameras care about dir but just in case
bodycam.setDir(new_dir)
/datum/component/simple_bodycam/proc/camera_gone(datum/source)
SIGNAL_HANDLER
if (!QDELETED(src))
qdel(src)