Implements shared particle holders, re-adds slimed status particles using the new system (#87892)

## About The Pull Request

Partial revert of #86701
Implements a shared holder particle system, somewhat inspired by
https://github.com/Baystation12/Baystation12/pull/34014 (thanks Kapu).
Atoms can be assigned "shared" particles via add_shared_particles, with
an optional "alternate" key passed as a second arg if you're planning to
edit the returned particle holder (for example, color it like slimed
status does). Removing is done via remove_shared_particles with an
option to delete the shared holder if nothing is using it anymore (on by
default). This system should be prioritized over normal particle holders
when a lot of entities would be using a certain particle effect (like
fires) as it conserves a lot of clientside performance.

Burning, acid, decaying, firestacks and slimed status now use this
system which should help with clientside performance and amount of atoms
created/destroyed.

## Why It's Good For The Game

Less clientside lag.

## Changelog
🆑
refactor: Firestacks, burning/acid/decaying effects and (brought back
after being temporarily removed) slimed status effects now use a new
"shared" particles system, which should considerably improve client
performance when encountering a lot of burning/slimed entities.
/🆑

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
This commit is contained in:
SmArtKar
2024-11-20 13:46:00 +01:00
committed by GitHub
co-authored by Ghom
parent 27b5f28e54
commit bcb5c47571
10 changed files with 170 additions and 47 deletions
+13 -3
View File
@@ -25,8 +25,10 @@ GLOBAL_DATUM_INIT(acid_overlay, /mutable_appearance, mutable_appearance('icons/e
var/turf_acid_ignores_mobs = FALSE
/// The ambient sound of acid eating away at the parent [/atom].
var/datum/looping_sound/acid/sizzle
/// Particle holder for acid particles (sick)
/// Particle holder for acid particles (sick). Still utilized over shared holders because they're movable-only
var/obj/effect/abstract/particle_holder/particle_effect
/// Particle type we're using for cleaning up our shared holder
var/particle_type
/// The proc used to handle the parent [/atom] when processing. TODO: Unify damage and resistance flags so that this doesn't need to exist!
var/datum/callback/process_effect
@@ -68,8 +70,13 @@ GLOBAL_DATUM_INIT(acid_overlay, /mutable_appearance, mutable_appearance('icons/e
sizzle = new(atom_parent, TRUE)
if(acid_particles)
// acid particles look pretty bad when they stack on mobs, so that behavior is not wanted for items
particle_effect = new(atom_parent, acid_particles, isitem(atom_parent) ? NONE : PARTICLE_ATTACH_MOB)
if (ismovable(parent))
var/atom/movable/movable_parent = parent
movable_parent.add_shared_particles(acid_particles, "[acid_particles]_[isitem(parent)]", isitem(parent) ? NONE : PARTICLE_ATTACH_MOB)
particle_type = acid_particles
else
// acid particles look pretty bad when they stack on mobs, so that behavior is not wanted for items
particle_effect = new(atom_parent, acid_particles, isitem(atom_parent) ? NONE : PARTICLE_ATTACH_MOB)
START_PROCESSING(SSacid, src)
/datum/component/acid/Destroy(force)
@@ -78,6 +85,9 @@ GLOBAL_DATUM_INIT(acid_overlay, /mutable_appearance, mutable_appearance('icons/e
QDEL_NULL(sizzle)
if(particle_effect)
QDEL_NULL(particle_effect)
if (ismovable(parent) && particle_type)
var/atom/movable/movable_parent = parent
movable_parent.remove_shared_particles("[particle_type]_[isitem(parent)]")
process_effect = null
return ..()
+14 -4
View File
@@ -8,8 +8,10 @@ GLOBAL_DATUM_INIT(fire_overlay, /mutable_appearance, mutable_appearance('icons/e
/datum/component/burning
/// Fire overlay appearance we apply
var/fire_overlay
/// Particle holder for fire particles, if any
/// Particle holder for fire particles, if any. Still utilized over shared holders because they're movable-only
var/obj/effect/abstract/particle_holder/particle_effect
/// Particle type we're using for cleaning up our shared holder
var/particle_type
/datum/component/burning/Initialize(fire_overlay = GLOB.fire_overlay, fire_particles = /particles/smoke/burning)
if(!isatom(parent))
@@ -25,9 +27,14 @@ GLOBAL_DATUM_INIT(fire_overlay, /mutable_appearance, mutable_appearance('icons/e
return
src.fire_overlay = fire_overlay
if(fire_particles)
// burning particles look pretty bad when they stack on mobs, so that behavior is not wanted for items
particle_effect = new(atom_parent, fire_particles, isitem(atom_parent) ? NONE : PARTICLE_ATTACH_MOB)
if (fire_particles)
if(ismovable(parent))
var/atom/movable/movable_parent = parent
// burning particles look pretty bad when they stack on mobs, so that behavior is not wanted for items
movable_parent.add_shared_particles(fire_particles, "[fire_particles]_[isitem(parent)]", isitem(parent) ? NONE : PARTICLE_ATTACH_MOB)
particle_type = fire_particles
else
particle_effect = new(atom_parent, fire_particles)
START_PROCESSING(SSburning, src)
/datum/component/burning/Destroy(force)
@@ -35,6 +42,9 @@ GLOBAL_DATUM_INIT(fire_overlay, /mutable_appearance, mutable_appearance('icons/e
fire_overlay = null
if(particle_effect)
QDEL_NULL(particle_effect)
if (ismovable(parent) && particle_type)
var/atom/movable/movable_parent = parent
movable_parent.remove_shared_particles("[particle_type]_[isitem(parent)]")
return ..()
/datum/component/burning/RegisterWithParent()
+11 -14
View File
@@ -27,8 +27,6 @@
var/produce_ants = FALSE
/// Stink particle type, if we are supposed to create stink particles
var/stink_particles
/// Stink particle holder
var/obj/effect/abstract/particle_holder/particle_effect
/datum/component/decomposition/Initialize(mapload, decomp_req_handle, decomp_flags = NONE, decomp_result, ant_attracting = FALSE, custom_time = 0, stink_particles = /particles/stink)
if(!ismovable(parent) || !HAS_TRAIT(parent, TRAIT_GERM_SENSITIVE))
@@ -52,9 +50,11 @@
src.stink_particles = stink_particles
/datum/component/decomposition/Destroy()
. = ..()
if(particle_effect)
QDEL_NULL(particle_effect)
remove_timer()
if (stink_particles)
var/atom/movable/movable_parent = parent
movable_parent.remove_shared_particles("[stink_particles]_[isitem(parent)]")
return ..()
/datum/component/decomposition/RegisterWithParent()
RegisterSignal(parent, COMSIG_ATOM_GERM_EXPOSED, PROC_REF(start_timer))
@@ -78,17 +78,13 @@
// If all other checks fail, then begin decomposition.
decomp_timerid = addtimer(CALLBACK(src, PROC_REF(decompose)), time_remaining, TIMER_STOPPABLE | TIMER_UNIQUE)
// Also start the stinking timer, if have stink particles and aren't stinking yet
if(!stink_particles || particle_effect)
// Also start the stinking timer, if have stink particles
if(!stink_particles)
return
var/stink_time = max(0, time_remaining - (original_time * 0.5))
stink_timerid = addtimer(CALLBACK(src, PROC_REF(stink_up)), stink_time, TIMER_STOPPABLE | TIMER_UNIQUE)
/datum/component/decomposition/Destroy()
remove_timer()
return ..()
/// Returns the time remaining in decomp, either from our potential timer or our own value, whichever is more useful
/datum/component/decomposition/proc/get_time()
if(!decomp_timerid)
@@ -108,11 +104,12 @@
/datum/component/decomposition/proc/stink_up()
stink_timerid = null
// Neither should happen, but to be sure
if(particle_effect || !stink_particles)
// Shouldn't happen, but to be sure
if(!stink_particles)
return
// we don't want stink lines on mobs (even though it'd be quite funny)
particle_effect = new(parent, stink_particles, isitem(parent) ? NONE : PARTICLE_ATTACH_MOB)
var/atom/movable/movable_parent = parent
movable_parent.add_shared_particles(stink_particles, "[stink_particles]_[isitem(parent)]", isitem(parent) ? NONE : PARTICLE_ATTACH_MOB)
/datum/component/decomposition/proc/decompose()
decomp_timerid = null