Skip to content

Commit

Permalink
feat(light): optimizing light
Browse files Browse the repository at this point in the history
  • Loading branch information
kreeperHLC committed Oct 14, 2023
1 parent be9b609 commit 22f1209
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
12 changes: 9 additions & 3 deletions code/game/turfs/turf_changing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions code/modules/lighting/lighting_atom.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions code/modules/lighting/lighting_overlay.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/lighting/lighting_source.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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++

Expand Down

0 comments on commit 22f1209

Please sign in to comment.