Files
LemonInTheDark 9d14e327b5 Begins Improving Sparks/Flares Somewhat, Adds Animatable Light Overlays (#95362)
## About The Pull Request

[Adds a visual tick helper, integrates it into SSmove and
such](https://github.com/tgstation/tgstation/commit/e97035f9f74fad5c67c5bf19d8d5d3bb4bd476b4)

Basically, if we do "stuff" during verb time then the next chance
clients have to actually see it is on the next visual tick (rather then
the normal "this tick"). This is cause clients get their next frame
during maptick, and maptick runs before verbs.

We want to be able to handle this properly because if you say, create an
object and then move it on the same VISUAL tick (NOT game tick), it will
just teleport instead of playing out the move. I don't want this for
stuff like sparks, so we need a way to work around it.

[Moves most users of the _FAST flag to
_INSTANT](https://github.com/tgstation/tgstation/commit/6f96daac00519c69adc7554f52114798a65f3ad5)

These are the kids that don't immediately spawn something and the move
it, and we want to allow them to move actually as soon as possible
(important for stuff like space)

[Improves basic effect systems, makes their products delete when they
stop
moving](https://github.com/tgstation/tgstation/commit/172cb25d80ed34e1ec523172a1677fb524239fba)

Moves some stuff out to getters or vars so children can better decide
how long effects should last/how fast they should move. Uses this to
clean up weird dupe code used by explosions.

Makes all these effects delete on contact with something that stops
them. I'm doing this because an effect just hanging in the air looks
really really odd. Does have consequences for sparks that are already
moving at a wall though, might need a better way to handle that.

Makes all these effects use _FAST loops so they don't just hang in the
air for a second on spawn

Adds a setter proc on sparks for their duration, gonna use this to
improve their effects some

[Refactors overlay lights, adds support for animating their
images](https://github.com/tgstation/tgstation/commit/3ad0083cf2b536df51a6d93dca40eac20c1d62d1)

Implements light_render_source and relevant setters, this allows us to
replace the components of an overlay light with basically whatever we
want

Refactors overlay lighting to handle its images more consistently,
allowing us to hook into an image being modified

Combining the two of these will allow us to consistently copy a light's
image, modify it in some way, and then relay that modification back
down. Allowing us to animate it or do more advanced effects painlessly

Also, fixes ranges of 1 or less not rendering at all on initial set
(thank you kapu)

[In which I get fed up and add a macro helper for UID
generation](https://github.com/tgstation/tgstation/commit/aab48b03d407104d4f9cf9acb034494237def911)

[adds vv hooking for all existing lighting
vars](https://github.com/tgstation/tgstation/commit/b81c6200a0d74c36b440aa3f4c1f22c422090a2d)

[Upgrade effect system's dir picking to avoid duplicates when
possible](https://github.com/tgstation/tgstation/commit/18b622586b509c6be4c4bca4e3e7c175ad75fe91)

[Uses the technique described above to animate spark's lights out as
they
move](https://github.com/tgstation/tgstation/commit/67ba177982213799984a70e89536c5efb3d17e14)

This is a decently nice effect imo, it allows us to bump their power
(read, alpha) since it'll get animated away. I try to sync the animation
to the actual icon state's flow (it's 0.7s long). I also sped them up
somewhat to hopefully have a nicer looking effect? we'll see.

[Abstracts away intercepting overlay lights into a holder
datum](https://github.com/tgstation/tgstation/pull/95362/commits/b3f1fe74f2c3bab1d8912ab8a666bd05677ad032)

This should make it far easier to reuse this pattern!

[Fixes overlay lights flashing to double intensity when picked up off
the
ground](https://github.com/tgstation/tgstation/pull/95362/commits/1d83f2031fa2b33312b2aea4359c0c37c9d04ac7)

We needed to clear out their underlays BEFORE the animation

[Adds a flickering effect to flares and their
children](https://github.com/tgstation/tgstation/pull/95362/commits/b7a858e04a607c58b6c7fbe1476ffe2239e63bde)

I'm still not 100% happy with this, I was trying to avoid it feeling
like a heartbeat with random noise and I.. THINK it worked? it's
honestly quite hard to tell

[Adds the same flickering to lighters, welding tools and life
candles](https://github.com/tgstation/tgstation/pull/95362/commits/3ec44027e17835ae96702cec5f0b12d1f4deb32b)

Also, updated light candles to mirror the appearance of normal candles
and use overlay lighting

EDIT:
I realized while working on flares that I accidentally double applied
color, so if you saw the sparks animations before now it was different
(less vibrant). IDK if I like this better or worse but it is RIGHT and
that's what matters.

## Why It's Good For The Game

I got mad about how bad these looked, and this is a start at improving
them.
Also, adds a framework for more dynamic effects applied to overlay
lights (you could use this to apply a sort of "emergency rotating"
effect, or flicker/buzz for example).

<details>
 <summary>Before</summary>


https://github.com/user-attachments/assets/66437f27-ee3c-4f14-a7ee-4a1c3e68533a


https://github.com/user-attachments/assets/ed14fff8-a7eb-47fe-bab5-9a490ac96629

</details>

<details>
 <summary>After</summary>


https://github.com/user-attachments/assets/fb24ff2e-c745-42a5-8e11-c8a1eeef35a5


https://github.com/user-attachments/assets/fd8c2116-cb92-4fe6-ad3e-786a6538e52a

</details>

## Changelog
🆑
add: Reworks how sparks render. They're now a bit brighter, will fade
out as they move/if they hit something, will stack with each other less
and also won't start hang in the air on spawn.
add: Added a flickering effect to lighters, welding tools, flares,
torches and candles (since they're flames).
fix: Overlay based lights (think flashlights) will no longer flash to
double intensity while being picked up.
refactor: Reworked how some effects (explosion particles, sparks, some
reagent stuff) function, report any bugs!
/🆑
2026-03-20 14:48:57 +13:00

161 lines
7.3 KiB
Plaintext

/// Allows us to intercept overlay lighting's well, light overlays
/// Normally these are static, but by giving them a render source and copying their base appearance
/// Animating this datum's child objects allows us to do SO much fun stuff
/datum/light_middleman
/// Owning parent we're interceeding for
/// Could in theory be a turf but lies to areas means we have to pick something to type it as
var/atom/movable/parent
/// The holder we are currently displaying our light on
var/atom/movable/light_holder
/// Holds the primary light source
var/obj/effect/abstract/light_middleman/primary_intercept
/// Exists to hold the cone so children can modify it if they want
var/obj/effect/abstract/light_middleman/cone_intercept
/// Are we overriding the light already?
var/overriding = FALSE
/// Weakref to the object we are displaying our effects on
var/datum/weakref/holder_ref
/datum/light_middleman/New(atom/parent, unique_string)
. = ..()
if(!IS_OVERLAY_LIGHT_SYSTEM(parent.light_system))
stack_trace("Attempted to create a light middleman with a parent [parent.type] that does not use overlay lighting! This will not work.")
if(isturf(parent))
stack_trace("Warning, becuase overlay lights are basically never used on turfs, since they don't move,\
vis contents replacement has not yet been implemented for them (see changeturf for why this is needed)!")
src.parent = parent
primary_intercept = new()
cone_intercept = new()
var/static/uuid = 0
uuid = WRAP_UID(uuid + 1)
primary_intercept.render_target = "*[unique_string]_[uuid]_target"
cone_intercept.render_target = "[primary_intercept.render_target]_cone" // made to mirror how overlay lights work
/datum/light_middleman/Destroy(force)
stop_overriding_light()
QDEL_NULL(primary_intercept)
QDEL_NULL(cone_intercept)
parent = null
light_holder = null
return ..()
/datum/light_middleman/proc/being_overriding_light(unique_string)
if(overriding)
return
overriding = TRUE
// We register here because our later set render source will always trigger a refresh and thus let us capture appearances properly
// Assuming there's an overlay light on the other side
RegisterSignal(parent, COMSIG_ATOM_OVERLAY_LIGHT_APPLIED, PROC_REF(light_applied))
RegisterSignal(parent, COMSIG_ATOM_OVERLAY_LIGHT_REMOVED, PROC_REF(light_removed))
parent.set_light_render_source(primary_intercept.render_target)
/datum/light_middleman/proc/stop_overriding_light()
if(!overriding)
return
overriding = FALSE
UnregisterSignal(parent, COMSIG_ATOM_OVERLAY_LIGHT_APPLIED)
UnregisterSignal(parent, COMSIG_ATOM_OVERLAY_LIGHT_REMOVED)
var/atom/movable/old_holder = holder_ref?.resolve()
if(old_holder)
old_holder.vis_contents -= primary_intercept
old_holder.vis_contents -= cone_intercept
holder_ref = null
parent.set_light_render_source("")
/datum/light_middleman/proc/light_applied(datum/source, image/visible_mask, image/cone, atom/movable/light_holder)
SIGNAL_HANDLER
var/atom/movable/old_holder = holder_ref?.resolve()
// If we were somewhere before, clean us out
if(old_holder)
old_holder.vis_contents -= primary_intercept
old_holder.vis_contents -= cone_intercept
holder_ref = null
// how we make sure we're in the client's view
light_holder.vis_contents += primary_intercept
// Avoids unneeded effects clientside
if(IS_OVERLAY_CONE_LIGHT_SYSTEM(parent.light_system))
light_holder.vis_contents += cone_intercept
old_holder = WEAKREF(light_holder)
var/old_target = primary_intercept.render_target
var/old_cone_target = cone_intercept.render_target
// This will halt any animations we have ongoing so if you care about that you've gotta react to it properly
primary_intercept.appearance = visible_mask
cone_intercept.appearance = cone
// set ourselves up to render back onto the visible mask
primary_intercept.render_source = ""
primary_intercept.render_target = old_target
cone_intercept.render_source = ""
cone_intercept.render_target = old_cone_target
// Dir is important I'm told
primary_intercept.vis_flags |= VIS_INHERIT_DIR
cone_intercept.vis_flags |= VIS_INHERIT_DIR
// Will double apply, here we go gang
primary_intercept.transform = null
cone_intercept.transform = null
primary_intercept.color = null
cone_intercept.color = null
primary_intercept.alpha = 255
cone_intercept.alpha = 255
// Sometimes can be BLEND_SUBTRACT, we don't want that
primary_intercept.blend_mode = BLEND_ADD
cone_intercept.blend_mode = BLEND_ADD
/// Allows users to hook into a refresh so they can remake their modifications to our intercepts
SEND_SIGNAL(src, COMSIG_LIGHT_MIDDLEMAN_UPDATED)
/datum/light_middleman/proc/light_removed(datum/source, atom/movable/light_holder)
SIGNAL_HANDLER
light_holder.vis_contents -= primary_intercept
light_holder.vis_contents -= cone_intercept
holder_ref = null
/// Just... cause it's better then not having a bespoke type
/obj/effect/abstract/light_middleman
// Procs for reuse on multiple types
/proc/fire_flicker_middleman(datum/light_middleman/middleman)
var/obj/effect/abstract/main_light = middleman.primary_intercept
// Just in case a subtype is wildin
var/obj/effect/abstract/cone_light = middleman.cone_intercept
/// Applies a nice random flicker to flares and their subtypes which will I hope sell the fire effect better
var/list/random_times = list()
for(var/i in 1 to 17)
// Makes a nice upside down U distribution
var/random_down = LERP(-0.075 SECONDS, 0.075 SECONDS, ANCHORED_INVERSE_CAUCHY(0.55))
var/random_bottom = LERP(-0.05 SECONDS, 0.05 SECONDS, ANCHORED_INVERSE_CAUCHY(0.55))
var/random_up = LERP(-0.075 SECONDS, 0.075 SECONDS, ANCHORED_INVERSE_CAUCHY(0.55))
// We want a potentially quite long "top end" so the flicker can be an actual flicker instead of a heartbeat (that's the goal at least)
var/random_top = LERP(-0.225 SECONDS, 0.225 SECONDS, ANCHORED_INVERSE_CAUCHY(0.55))
random_times += list(list(
0.125 SECONDS + random_down,
0 SECONDS + random_bottom,
0.125 SECONDS + random_up,
0.275 SECONDS + random_top,
))
// Going to loop our alpha high and low semi quickly to mimik a flickering fire/flare
var/list/first_time = random_times[1]
animate(main_light, alpha = 235, time = first_time[1], easing = CUBIC_EASING|EASE_OUT, loop = -1)
animate(alpha = 235, time = first_time[2])
animate(alpha = 255, time = first_time[3], easing = CUBIC_EASING|EASE_OUT)
animate(alpha = 255, time = first_time[4])
for(var/list/time in random_times - first_time)
animate(alpha = 235, time = time[1], easing = CUBIC_EASING|EASE_OUT)
animate(alpha = 235, time = first_time[2])
animate(alpha = 255, time = first_time[3], easing = CUBIC_EASING|EASE_OUT)
animate(alpha = 255, time = first_time[4])
// I'd really love to do both these in the same loop but parallel animations are the devil from the bible
// I don't think any of these are directional but just in case
animate(cone_light, alpha = 235, time = first_time[1], easing = CUBIC_EASING|EASE_OUT, loop = -1)
animate(alpha = 235, time = first_time[2])
animate(alpha = 255, time = first_time[3], easing = CUBIC_EASING|EASE_OUT)
animate(alpha = 255, time = first_time[4])
for(var/list/time in random_times - first_time)
animate(alpha = 235, time = time[1], easing = CUBIC_EASING|EASE_OUT)
animate(alpha = 235, time = first_time[2])
animate(alpha = 255, time = first_time[3], easing = CUBIC_EASING|EASE_OUT)
animate(alpha = 255, time = first_time[4])