mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-23 03:57:13 +01:00
Lighting Optimizations (#13593)
* Lighting Optimizations * styling * styling * welp
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
GLOBAL_LIST_EMPTY(lighting_update_lights) // List of lighting sources queued for update.
|
||||
GLOBAL_LIST_EMPTY(lighting_update_corners) // List of lighting corners queued for update.
|
||||
GLOBAL_LIST_EMPTY(lighting_update_objects) // List of lighting objects queued for update.
|
||||
|
||||
SUBSYSTEM_DEF(lighting)
|
||||
name = "Lighting"
|
||||
wait = 2
|
||||
init_order = INIT_ORDER_LIGHTING
|
||||
flags = SS_TICKER
|
||||
offline_implications = "Lighting will no longer update. Shuttle call recommended."
|
||||
var/static/list/sources_queue = list() // List of 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.
|
||||
|
||||
/datum/controller/subsystem/lighting/stat_entry()
|
||||
..("L:[GLOB.lighting_update_lights.len]|C:[GLOB.lighting_update_corners.len]|O:[GLOB.lighting_update_objects.len]")
|
||||
..("L:[length(sources_queue)]|C:[length(corners_queue)]|O:[length(objects_queue)]")
|
||||
|
||||
/datum/controller/subsystem/lighting/Initialize(timeofday)
|
||||
if(!initialized)
|
||||
@@ -31,9 +30,10 @@ SUBSYSTEM_DEF(lighting)
|
||||
MC_SPLIT_TICK_INIT(3)
|
||||
if(!init_tick_checks)
|
||||
MC_SPLIT_TICK
|
||||
var/list/queue = sources_queue
|
||||
var/i = 0
|
||||
for(i in 1 to GLOB.lighting_update_lights.len)
|
||||
var/datum/light_source/L = GLOB.lighting_update_lights[i]
|
||||
for(i in 1 to length(queue))
|
||||
var/datum/light_source/L = queue[i]
|
||||
|
||||
L.update_corners()
|
||||
|
||||
@@ -44,14 +44,15 @@ SUBSYSTEM_DEF(lighting)
|
||||
else if(MC_TICK_CHECK)
|
||||
break
|
||||
if(i)
|
||||
GLOB.lighting_update_lights.Cut(1, i+1)
|
||||
queue.Cut(1, i + 1)
|
||||
i = 0
|
||||
|
||||
if(!init_tick_checks)
|
||||
MC_SPLIT_TICK
|
||||
|
||||
for (i in 1 to GLOB.lighting_update_corners.len)
|
||||
var/datum/lighting_corner/C = GLOB.lighting_update_corners[i]
|
||||
queue = corners_queue
|
||||
for(i in 1 to length(queue))
|
||||
var/datum/lighting_corner/C = queue[i]
|
||||
|
||||
C.update_objects()
|
||||
C.needs_update = FALSE
|
||||
@@ -60,15 +61,16 @@ SUBSYSTEM_DEF(lighting)
|
||||
else if(MC_TICK_CHECK)
|
||||
break
|
||||
if(i)
|
||||
GLOB.lighting_update_corners.Cut(1, i+1)
|
||||
queue.Cut(1, i + 1)
|
||||
i = 0
|
||||
|
||||
|
||||
if(!init_tick_checks)
|
||||
MC_SPLIT_TICK
|
||||
|
||||
for (i in 1 to GLOB.lighting_update_objects.len)
|
||||
var/atom/movable/lighting_object/O = GLOB.lighting_update_objects[i]
|
||||
queue = objects_queue
|
||||
for(i in 1 to length(queue))
|
||||
var/atom/movable/lighting_object/O = queue[i]
|
||||
|
||||
if(QDELETED(O))
|
||||
continue
|
||||
@@ -80,7 +82,7 @@ SUBSYSTEM_DEF(lighting)
|
||||
else if(MC_TICK_CHECK)
|
||||
break
|
||||
if(i)
|
||||
GLOB.lighting_update_objects.Cut(1, i+1)
|
||||
queue.Cut(1, i + 1)
|
||||
|
||||
|
||||
/datum/controller/subsystem/lighting/Recover()
|
||||
|
||||
@@ -265,15 +265,8 @@
|
||||
var/dest_z = (destturf ? destturf.z : null)
|
||||
if(old_z != dest_z)
|
||||
onTransitZ(old_z, dest_z)
|
||||
if(isturf(destination) && opacity)
|
||||
var/turf/new_loc = destination
|
||||
new_loc.reconsider_lights()
|
||||
|
||||
if(isturf(old_loc) && opacity)
|
||||
old_loc.reconsider_lights()
|
||||
|
||||
for(var/datum/light_source/L in light_sources)
|
||||
L.source_atom.update_light()
|
||||
Moved(old_loc, NONE)
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
@@ -163,6 +163,11 @@
|
||||
loopsanity--
|
||||
A.HasProximity(M, 1)
|
||||
|
||||
// If an opaque movable atom moves around we need to potentially update visibility.
|
||||
if(M.opacity)
|
||||
has_opaque_atom = TRUE // Make sure to do this before reconsider_lights(), incase we're on instant updates. Guaranteed to be on in this case.
|
||||
reconsider_lights()
|
||||
|
||||
/turf/proc/levelupdate()
|
||||
for(var/obj/O in src)
|
||||
if(O.level == 1)
|
||||
|
||||
@@ -25,7 +25,7 @@ GLOBAL_LIST_INIT(LIGHTING_CORNER_DIAGONAL, list(NORTHEAST, SOUTHEAST, SOUTHWEST,
|
||||
var/cache_b = LIGHTING_SOFT_THRESHOLD
|
||||
var/cache_mx = 0
|
||||
|
||||
/datum/lighting_corner/New(var/turf/new_turf, var/diagonal)
|
||||
/datum/lighting_corner/New(turf/new_turf, diagonal)
|
||||
. = ..()
|
||||
masters = list()
|
||||
masters[new_turf] = turn(diagonal, 180)
|
||||
@@ -79,15 +79,16 @@ GLOBAL_LIST_INIT(LIGHTING_CORNER_DIAGONAL, list(NORTHEAST, SOUTHEAST, SOUTHWEST,
|
||||
active = FALSE
|
||||
var/turf/T
|
||||
var/thing
|
||||
for (thing in masters)
|
||||
for(thing in masters)
|
||||
T = thing
|
||||
if(T.lighting_object)
|
||||
active = TRUE
|
||||
return
|
||||
|
||||
// God that was a mess, now to do the rest of the corner code! Hooray!
|
||||
/datum/lighting_corner/proc/update_lumcount(var/delta_r, var/delta_g, var/delta_b)
|
||||
/datum/lighting_corner/proc/update_lumcount(delta_r, delta_g, delta_b)
|
||||
|
||||
if((abs(delta_r)+abs(delta_g)+abs(delta_b)) == 0)
|
||||
if(!(delta_r || delta_g || delta_b)) // 0 is falsey ok
|
||||
return
|
||||
|
||||
lum_r += delta_r
|
||||
@@ -96,10 +97,10 @@ GLOBAL_LIST_INIT(LIGHTING_CORNER_DIAGONAL, list(NORTHEAST, SOUTHEAST, SOUTHWEST,
|
||||
|
||||
if(!needs_update)
|
||||
needs_update = TRUE
|
||||
GLOB.lighting_update_corners += src
|
||||
SSlighting.corners_queue += src
|
||||
|
||||
/datum/lighting_corner/proc/update_objects()
|
||||
// Cache these values a head of time so 4 individual lighting objects don't all calculate them individually.
|
||||
// Cache these values ahead of time so 4 individual lighting objects don't all calculate them individually.
|
||||
var/lum_r = src.lum_r
|
||||
var/lum_g = src.lum_g
|
||||
var/lum_b = src.lum_b
|
||||
@@ -122,19 +123,18 @@ GLOBAL_LIST_INIT(LIGHTING_CORNER_DIAGONAL, list(NORTHEAST, SOUTHEAST, SOUTHWEST,
|
||||
#endif
|
||||
cache_mx = round(mx, LIGHTING_ROUND_VALUE)
|
||||
|
||||
for (var/TT in masters)
|
||||
for(var/TT in masters)
|
||||
var/turf/T = TT
|
||||
if(T.lighting_object)
|
||||
if(!T.lighting_object.needs_update)
|
||||
T.lighting_object.needs_update = TRUE
|
||||
GLOB.lighting_update_objects += T.lighting_object
|
||||
if(T.lighting_object && !T.lighting_object.needs_update)
|
||||
T.lighting_object.needs_update = TRUE
|
||||
SSlighting.objects_queue += T.lighting_object
|
||||
|
||||
|
||||
/datum/lighting_corner/dummy/New()
|
||||
return
|
||||
|
||||
|
||||
/datum/lighting_corner/Destroy(var/force)
|
||||
/datum/lighting_corner/Destroy(force)
|
||||
if(!force)
|
||||
return QDEL_HINT_LETMELIVE
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
icon = LIGHTING_ICON
|
||||
icon_state = "transparent"
|
||||
color = LIGHTING_BASE_MATRIX
|
||||
color = null //we manually set color in init instead
|
||||
plane = LIGHTING_PLANE
|
||||
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
|
||||
layer = LIGHTING_LAYER
|
||||
@@ -18,6 +18,9 @@
|
||||
/atom/movable/lighting_object/Initialize(mapload)
|
||||
. = ..()
|
||||
verbs.Cut()
|
||||
//We avoid setting this in the base as if we do then the parent atom handling will add_atom_color it and that
|
||||
//is totally unsuitable for this object, as we are always changing it's colour manually
|
||||
color = LIGHTING_BASE_MATRIX
|
||||
|
||||
myturf = loc
|
||||
if(myturf.lighting_object)
|
||||
@@ -29,11 +32,11 @@
|
||||
S.update_starlight()
|
||||
|
||||
needs_update = TRUE
|
||||
GLOB.lighting_update_objects += src
|
||||
SSlighting.objects_queue += src
|
||||
|
||||
/atom/movable/lighting_object/Destroy(var/force)
|
||||
/atom/movable/lighting_object/Destroy(force)
|
||||
if(force)
|
||||
GLOB.lighting_update_objects -= src
|
||||
SSlighting.objects_queue -= src
|
||||
if(loc != myturf)
|
||||
var/turf/oldturf = get_turf(myturf)
|
||||
var/turf/newturf = get_turf(loc)
|
||||
@@ -143,6 +146,6 @@
|
||||
return
|
||||
|
||||
// Override here to prevent things accidentally moving around overlays.
|
||||
/atom/movable/lighting_object/forceMove(atom/destination, var/no_tp=FALSE, var/harderforce = FALSE)
|
||||
/atom/movable/lighting_object/forceMove(atom/destination, no_tp = FALSE, harderforce = FALSE)
|
||||
if(harderforce)
|
||||
. = ..()
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
var/needs_update = LIGHTING_NO_UPDATE // Whether we are queued for an update.
|
||||
|
||||
|
||||
/datum/light_source/New(var/atom/owner, var/atom/top)
|
||||
/datum/light_source/New(atom/owner, atom/top)
|
||||
source_atom = owner // Set our new owner.
|
||||
LAZYADD(source_atom.light_sources, src)
|
||||
top_atom = top
|
||||
@@ -56,7 +56,7 @@
|
||||
LAZYREMOVE(top_atom.light_sources, src)
|
||||
|
||||
if(needs_update)
|
||||
GLOB.lighting_update_lights -= src
|
||||
SSlighting.sources_queue -= src
|
||||
|
||||
. = ..()
|
||||
|
||||
@@ -65,13 +65,13 @@
|
||||
// Actually that'd be great if you could!
|
||||
#define EFFECT_UPDATE(level) \
|
||||
if(needs_update == LIGHTING_NO_UPDATE) \
|
||||
GLOB.lighting_update_lights += src; \
|
||||
SSlighting.sources_queue += src; \
|
||||
if(needs_update < level) \
|
||||
needs_update = level; \
|
||||
|
||||
|
||||
// This proc will cause the light source to update the top atom, and add itself to the update queue.
|
||||
/datum/light_source/proc/update(var/atom/new_top_atom)
|
||||
/datum/light_source/proc/update(atom/new_top_atom)
|
||||
// This top atom is different.
|
||||
if(new_top_atom && new_top_atom != top_atom)
|
||||
if(top_atom != source_atom && top_atom.light_sources) // Remove ourselves from the light sources of that top atom.
|
||||
@@ -141,7 +141,7 @@
|
||||
|
||||
effect_str = null
|
||||
|
||||
/datum/light_source/proc/recalc_corner(var/datum/lighting_corner/C)
|
||||
/datum/light_source/proc/recalc_corner(datum/lighting_corner/C)
|
||||
LAZYINITLIST(effect_str)
|
||||
if(effect_str[C]) // Already have one.
|
||||
REMOVE_CORNER(C)
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
C.active = TRUE
|
||||
|
||||
// Used to get a scaled lumcount.
|
||||
/turf/proc/get_lumcount(var/minlum = 0, var/maxlum = 1)
|
||||
/turf/proc/get_lumcount(minlum = 0, maxlum = 1)
|
||||
if(!lighting_object)
|
||||
return 1
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
recalc_atom_opacity() // Make sure to do this before reconsider_lights(), incase we're on instant updates.
|
||||
reconsider_lights()
|
||||
|
||||
/turf/proc/change_area(var/area/old_area, var/area/new_area)
|
||||
/turf/proc/change_area(area/old_area, area/new_area)
|
||||
if(SSlighting.initialized)
|
||||
if(new_area.dynamic_lighting != old_area.dynamic_lighting)
|
||||
if(new_area.dynamic_lighting)
|
||||
|
||||
@@ -14,3 +14,8 @@
|
||||
|
||||
/mob/camera/experience_pressure_difference()
|
||||
return
|
||||
|
||||
/mob/camera/forceMove(atom/destination)
|
||||
var/oldloc = loc
|
||||
loc = destination
|
||||
Moved(oldloc, NONE)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
onTransitZ(old_turf?.z, new_turf?.z)
|
||||
var/oldloc = loc
|
||||
loc = destination
|
||||
Moved(oldloc, NONE, TRUE)
|
||||
Moved(oldloc, NONE)
|
||||
|
||||
/mob/dead/onTransitZ(old_z,new_z)
|
||||
..()
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
var/turf/newT = get_turf(src)
|
||||
if(newT.z != oldT.z)
|
||||
onTransitZ(oldT.z, newT.z)
|
||||
if(light)
|
||||
update_light()
|
||||
if(rotation)
|
||||
shuttleRotate(rotation)
|
||||
forceMove(T1)
|
||||
|
||||
Reference in New Issue
Block a user