mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-07-21 12:56:10 +01:00
94d92803b4
Depends on #21458. Ports https://github.com/cmss13-devs/cmss13/pull/4229, with the original authors as: - https://github.com/tgstation/TerraGov-Marine-Corps/pull/1964 for the lighting controller (A-lexa) - https://github.com/tgstation/TerraGov-Marine-Corps/pull/4747 and https://github.com/tgstation/TerraGov-Marine-Corps/pull/7263 for the lighting (TiviPlus) - https://github.com/tgstation/tgstation/pull/54520 for the dir lighting component - https://github.com/tgstation/tgstation/pull/75018 for the out of bounds fix in lighting - https://github.com/tgstation/TerraGov-Marine-Corps/pull/6678 for the emissives (TiviPlus) The main driving reason behind this is that current lighting consumes way too much processing power, especially for things like odysseys/away sites where a billion light sources are processing/moving at once and the game slows down to a crawl. Hopefully this improves the situation by a good margin, but we will need some testmerging to confirm that. <img width="1349" height="1349" alt="image" src="https://github.com/user-attachments/assets/1059ba2b-c0c5-495a-9c76-2d75d0c42bf2" /> <img width="1349" height="1349" alt="image" src="https://github.com/user-attachments/assets/9704b0f6-4cf6-4dfd-a6cb-5702ad07d677" /> - [x] Resolve todos - [x] Look into open space fuckery (border objects) --------- Co-authored-by: Matt Atlas <liermattia@gmail.com> Co-authored-by: JohnWildkins <john.wildkins@gmail.com>
116 lines
4.0 KiB
Plaintext
116 lines
4.0 KiB
Plaintext
/datum/static_lighting_object
|
|
///the underlay we are currently applying to our turf to apply light
|
|
var/mutable_appearance/current_underlay
|
|
|
|
///whether we are already in the SSlighting.objects_queue list
|
|
var/needs_update = FALSE
|
|
|
|
///the turf that our light is applied to
|
|
var/turf/affected_turf
|
|
|
|
/datum/static_lighting_object/New(turf/source)
|
|
if(!isturf(source))
|
|
qdel(src, force=TRUE)
|
|
stack_trace("a lighting object was assigned to [source], a non turf! ")
|
|
return
|
|
..()
|
|
|
|
current_underlay = mutable_appearance(LIGHTING_ICON, "transparent", FLOAT_LAYER, LIGHTING_PLANE, 255, RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM)
|
|
|
|
affected_turf = source
|
|
if (affected_turf.static_lighting_object)
|
|
qdel(affected_turf.static_lighting_object, force = TRUE)
|
|
stack_trace("a lighting object was assigned to a turf that already had a lighting object!")
|
|
|
|
affected_turf.static_lighting_object = src
|
|
affected_turf.luminosity = 0
|
|
|
|
needs_update = TRUE
|
|
SSlighting.objects_queue += src
|
|
|
|
/datum/static_lighting_object/Destroy(force)
|
|
if (!force)
|
|
return QDEL_HINT_LETMELIVE
|
|
SSlighting.objects_queue -= src
|
|
if (isturf(affected_turf))
|
|
affected_turf.static_lighting_object = null
|
|
affected_turf.luminosity = 1
|
|
affected_turf.underlays -= current_underlay
|
|
affected_turf = null
|
|
return ..()
|
|
|
|
/datum/static_lighting_object/proc/update()
|
|
|
|
// To the future coder who sees this and thinks
|
|
// "Why didn't he just use a loop?"
|
|
// Well my man, it's because the loop performed like shit.
|
|
// And there's no way to improve it because
|
|
// without a loop you can make the list all at once which is the fastest you're gonna get.
|
|
// Oh it's also shorter line wise.
|
|
// Including with these comments.
|
|
|
|
var/static/datum/static_lighting_corner/dummy/dummy_lighting_corner = new
|
|
|
|
var/datum/static_lighting_corner/red_corner = affected_turf.lighting_corner_SW || dummy_lighting_corner
|
|
var/datum/static_lighting_corner/green_corner = affected_turf.lighting_corner_SE || dummy_lighting_corner
|
|
var/datum/static_lighting_corner/blue_corner = affected_turf.lighting_corner_NW || dummy_lighting_corner
|
|
var/datum/static_lighting_corner/alpha_corner = affected_turf.lighting_corner_NE || dummy_lighting_corner
|
|
|
|
var/max = max(red_corner.largest_color_luminosity, green_corner.largest_color_luminosity, blue_corner.largest_color_luminosity, alpha_corner.largest_color_luminosity)
|
|
|
|
var/rr = red_corner.cache_r
|
|
var/rg = red_corner.cache_g
|
|
var/rb = red_corner.cache_b
|
|
|
|
var/gr = green_corner.cache_r
|
|
var/gg = green_corner.cache_g
|
|
var/gb = green_corner.cache_b
|
|
|
|
var/br = blue_corner.cache_r
|
|
var/bg = blue_corner.cache_g
|
|
var/bb = blue_corner.cache_b
|
|
|
|
var/ar = alpha_corner.cache_r
|
|
var/ag = alpha_corner.cache_g
|
|
var/ab = alpha_corner.cache_b
|
|
|
|
#if LIGHTING_SOFT_THRESHOLD != 0
|
|
var/set_luminosity = max > LIGHTING_SOFT_THRESHOLD
|
|
#else
|
|
// Because of floating points�?, it won't even be a flat 0.
|
|
// This number is mostly arbitrary.
|
|
var/set_luminosity = max > 1e-6
|
|
#endif
|
|
|
|
if((rr & gr & br & ar) && (rg + gg + bg + ag + rb + gb + bb + ab == 8))
|
|
//anything that passes the first case is very likely to pass the second, and addition is a little faster in this case
|
|
affected_turf.underlays -= current_underlay
|
|
current_underlay.icon_state = "lighting_transparent"
|
|
current_underlay.color = null
|
|
affected_turf.underlays += current_underlay
|
|
else if(!set_luminosity)
|
|
affected_turf.underlays -= current_underlay
|
|
current_underlay.icon_state = "lighting_dark"
|
|
current_underlay.color = null
|
|
affected_turf.underlays += current_underlay
|
|
else
|
|
affected_turf.underlays -= current_underlay
|
|
current_underlay.icon_state = null
|
|
current_underlay.color = list(
|
|
rr, rg, rb, 00,
|
|
gr, gg, gb, 00,
|
|
br, bg, bb, 00,
|
|
ar, ag, ab, 00,
|
|
00, 00, 00, 01
|
|
)
|
|
|
|
affected_turf.underlays += current_underlay
|
|
|
|
var/area/A = affected_turf.loc
|
|
//We are luminous
|
|
if(set_luminosity)
|
|
affected_turf.luminosity = set_luminosity
|
|
//We are not lit by static light OR dynamic light.
|
|
else if(!LAZYLEN(affected_turf.hybrid_lights_affecting) && !A.base_lighting_alpha)
|
|
affected_turf.luminosity = 0
|