Speeds up /datum/light_source/proc/update_corners() by 16% or so (#51004)

About The Pull Request

Just moving /turf/proc/get_corners() into its only caller, slightly shuffled.

Also #defining /proc/GetRedPart() etc, which should flatten down to a copytext+text2num operation with #51005. Also defining parse_light_color() since it has two callers and does something trivial (splits #ff0000 into three luminance vars).

cl Naksu
code: Lighting corner updates are ever so slightly faster.
/cl
This commit is contained in:
vuonojenmustaturska
2020-05-11 02:33:28 +03:00
committed by GitHub
parent d010f09e34
commit 6455fb3be5
5 changed files with 36 additions and 40 deletions

View File

@@ -43,12 +43,10 @@
light_range = source_atom.light_range
light_color = source_atom.light_color
parse_light_color()
PARSE_LIGHT_COLOR(src)
update()
return ..()
/datum/light_source/Destroy(force)
remove_lum()
if (source_atom)
@@ -94,17 +92,6 @@
/datum/light_source/proc/vis_update()
EFFECT_UPDATE(LIGHTING_VIS_UPDATE)
// Decompile the hexadecimal colour into lumcounts of each perspective.
/datum/light_source/proc/parse_light_color()
if (light_color)
lum_r = GetRedPart (light_color) / 255
lum_g = GetGreenPart (light_color) / 255
lum_b = GetBluePart (light_color) / 255
else
lum_r = 1
lum_g = 1
lum_b = 1
// Macro that applies light to a new corner.
// It is a macro in the interest of speed, yet not having to copy paste it.
// If you're wondering what's with the backslashes, the backslashes cause BYOND to not automatically end the line.
@@ -163,6 +150,7 @@
APPLY_CORNER(C)
UNSETEMPTY(effect_str)
/datum/light_source/proc/update_corners()
var/update = FALSE
var/atom/source_atom = src.source_atom
@@ -212,7 +200,7 @@
if (source_atom.light_color != light_color)
light_color = source_atom.light_color
parse_light_color()
PARSE_LIGHT_COLOR(src)
update = TRUE
else if (applied_lum_r != lum_r || applied_lum_g != lum_g || applied_lum_b != lum_b)
@@ -229,11 +217,16 @@
var/thing
var/datum/lighting_corner/C
var/turf/T
if (source_turf)
var/oldlum = source_turf.luminosity
source_turf.luminosity = CEILING(light_range, 1)
for(T in view(CEILING(light_range, 1), source_turf))
for (thing in T.get_corners(source_turf))
if((!IS_DYNAMIC_LIGHTING(T) && !T.light_sources) || T.has_opaque_atom)
continue
if (!T.lighting_corners_initialised)
T.generate_missing_corners()
for (thing in T.corners)
C = thing
corners[C] = 0
turfs += T