From 22f12099196d97757a959532e2a57a891d5108d0 Mon Sep 17 00:00:00 2001 From: kreeperHLC Date: Sat, 14 Oct 2023 22:17:21 +0300 Subject: [PATCH] feat(light): optimizing light --- code/game/turfs/turf_changing.dm | 12 +++++++++--- code/modules/lighting/lighting_atom.dm | 14 +++++++------- code/modules/lighting/lighting_overlay.dm | 4 ++-- code/modules/lighting/lighting_source.dm | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/code/game/turfs/turf_changing.dm b/code/game/turfs/turf_changing.dm index f6231e1b810..074cc050836 100644 --- a/code/game/turfs/turf_changing.dm +++ b/code/game/turfs/turf_changing.dm @@ -104,12 +104,18 @@ if(lighting_overlays_initialised) lighting_overlay = old_lighting_overlay + if (lighting_overlay && lighting_overlay.loc != src) + // This is a hack, but I can't figure out why the fuck they're not on the correct turf in the first place. + lighting_overlay.forceMove(src) + affecting_lights = old_affecting_lights corners = old_corners - if((old_opacity != opacity) || (dynamic_lighting != old_dynamic_lighting)) + + if ((old_opacity != opacity) || (dynamic_lighting != old_dynamic_lighting) || force_lighting_update) reconsider_lights() - if(dynamic_lighting != old_dynamic_lighting) - if(dynamic_lighting) + + if (dynamic_lighting != old_dynamic_lighting) + if (dynamic_lighting) lighting_build_overlay() else lighting_clear_overlay() diff --git a/code/modules/lighting/lighting_atom.dm b/code/modules/lighting/lighting_atom.dm index 229f70c4d43..2c85c341250 100644 --- a/code/modules/lighting/lighting_atom.dm +++ b/code/modules/lighting/lighting_atom.dm @@ -12,29 +12,29 @@ #define NONSENSICAL_VALUE -99999 #define DEFAULT_FALLOFF_CURVE (2) /atom/proc/set_light(l_max_bright, l_inner_range, l_outer_range, l_falloff_curve = NONSENSICAL_VALUE, l_color = NONSENSICAL_VALUE) - . = 0 //make it less costly if nothing's changed + . = FALSE // don't update if nothing changed if(l_max_bright != null && l_max_bright != light_max_bright) light_max_bright = l_max_bright - . = 1 + . = TRUE if(l_outer_range != null && l_outer_range != light_outer_range) light_outer_range = l_outer_range - . = 1 + . = TRUE if(l_inner_range != null && l_inner_range != light_inner_range) if(light_inner_range >= light_outer_range) light_inner_range = light_outer_range / 4 else light_inner_range = l_inner_range - . = 1 + . = TRUE if(l_falloff_curve != NONSENSICAL_VALUE) if(!l_falloff_curve || l_falloff_curve <= 0) light_falloff_curve = DEFAULT_FALLOFF_CURVE if(l_falloff_curve != light_falloff_curve) light_falloff_curve = l_falloff_curve - . = 1 + . = TRUE if(l_color != NONSENSICAL_VALUE && l_color != light_color) light_color = l_color - . = 1 + . = TRUE if(.) update_light() @@ -62,7 +62,7 @@ light.update(.) else light = new /datum/light_source(src, .) - + SEND_SIGNAL(src, SIGNAL_LIGHT_UPDATED, src) SEND_GLOBAL_SIGNAL(SIGNAL_LIGHT_UPDATED, src) diff --git a/code/modules/lighting/lighting_overlay.dm b/code/modules/lighting/lighting_overlay.dm index 6f61e2ad72d..2c2a8d806c0 100644 --- a/code/modules/lighting/lighting_overlay.dm +++ b/code/modules/lighting/lighting_overlay.dm @@ -97,8 +97,8 @@ 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 + // If all channels are full lum, there's no point showing the overlay. + if(rr + rg + rb + gr + gg + gb + br + bg + bb + ar + ag + ab >= 12) icon_state = "transparent" color = null else if(!set_luminosity) diff --git a/code/modules/lighting/lighting_source.dm b/code/modules/lighting/lighting_source.dm index 0d5a3a9babe..70aa1e81aac 100644 --- a/code/modules/lighting/lighting_source.dm +++ b/code/modules/lighting/lighting_source.dm @@ -239,7 +239,7 @@ //Do subprocessing for open turfs for(T = O.below; !isnull(T); T = process_the_turf(T,update_gen)); - + END_FOR_DVIEW update_gen++