Files
Matt Atlas 94d92803b4 Replaces our lighting system with CM's. (#21465)
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>
2025-11-04 21:27:42 +00:00

124 lines
3.3 KiB
Plaintext

SUBSYSTEM_DEF(lighting)
name = "Lighting"
wait = 2
init_order = INIT_ORDER_LIGHTING
//debug var for tracking updates before init is complete
var/duplicate_shadow_updates_in_init = 0
///Total times shadows were updated, debug
var/total_shadow_calculations = 0
///Whether the SS has begun setting up yet
var/started = FALSE
var/static/list/static_sources_queue = list() //! List of static lighting sources queued for update.
var/static/list/corners_queue = list() //! List of lighting corners queued for update.
var/static/list/objects_queue = list() //! List of lighting objects queued for update.
var/static/list/mask_queue = list() //! List of hybrid lighting sources queued for update.
/datum/controller/subsystem/lighting/Initialize(timeofday)
started = TRUE
if(!initialized)
//Handle static lightnig
create_all_lighting_objects()
fire(FALSE, TRUE)
return SS_INIT_SUCCESS
/datum/controller/subsystem/lighting/stat_entry()
. = ..("ShCalcs:[total_shadow_calculations]|SourcQ:[length(static_sources_queue)]|CcornQ:[length(corners_queue)]|ObjQ:[length(objects_queue)]|HybrQ:[length(mask_queue)]")
/datum/controller/subsystem/lighting/fire(resumed, init_tick_checks)
MC_SPLIT_TICK_INIT(3)
if(!init_tick_checks)
MC_SPLIT_TICK
var/updators_num = 0
while(updators_num < length(static_sources_queue))
updators_num += 1
var/datum/static_light_source/L = static_sources_queue[updators_num]
L.update_corners()
if(!QDELETED(L))
L.needs_update = LIGHTING_NO_UPDATE
else
updators_num -= 1
if(init_tick_checks)
if(!TICK_CHECK)
continue
static_sources_queue.Cut(1, updators_num + 1)
updators_num = 0
stoplag()
else if (MC_TICK_CHECK)
break
if(updators_num)
static_sources_queue.Cut(1, updators_num + 1)
updators_num = 0
if(!init_tick_checks)
MC_SPLIT_TICK
while(updators_num < length(corners_queue))
updators_num += 1
var/datum/static_lighting_corner/C = corners_queue[updators_num]
C.needs_update = FALSE //update_objects() can call qdel if the corner is storing no data
C.update_objects()
if(init_tick_checks)
if(!TICK_CHECK)
continue
corners_queue.Cut(1, updators_num + 1)
updators_num = 0
stoplag()
else if (MC_TICK_CHECK)
break
if(updators_num)
corners_queue.Cut(1, updators_num + 1)
updators_num = 0
if(!init_tick_checks)
MC_SPLIT_TICK
while(updators_num < length(objects_queue))
updators_num += 1
var/datum/static_lighting_object/O = objects_queue[updators_num]
if (QDELETED(O))
continue
O.update()
O.needs_update = FALSE
if(init_tick_checks)
if(!TICK_CHECK)
continue
objects_queue.Cut(1, updators_num + 1)
updators_num = 0
else if (MC_TICK_CHECK)
break
if(updators_num)
objects_queue.Cut(1, updators_num + 1)
updators_num = 0
if(!init_tick_checks)
MC_SPLIT_TICK
while(updators_num > length(mask_queue))
updators_num += 1
var/atom/movable/lighting_mask/mask_to_update = mask_queue[updators_num]
mask_to_update.calculate_lighting_shadows()
if(init_tick_checks)
if(!TICK_CHECK)
continue
mask_queue.Cut(1, updators_num + 1)
updators_num = 0
stoplag()
else if (MC_TICK_CHECK)
break
if(updators_num)
mask_queue.Cut(1, updators_num + 1)
/datum/controller/subsystem/lighting/Recover()
initialized = SSlighting.initialized
return ..()