From 10a7b897a641c72a4761f556b62fcc3e6ce4234a Mon Sep 17 00:00:00 2001 From: Fox McCloud Date: Wed, 20 May 2020 02:21:16 -0400 Subject: [PATCH] Lighting Performance Improvement (#13436) --- code/__DEFINES/lighting.dm | 24 ++++++++++++++++++++++++ code/__HELPERS/game.dm | 17 ----------------- code/modules/lighting/lighting_source.dm | 23 +++++++---------------- code/modules/lighting/lighting_turf.dm | 11 ----------- 4 files changed, 31 insertions(+), 44 deletions(-) diff --git a/code/__DEFINES/lighting.dm b/code/__DEFINES/lighting.dm index 01dbc2f1c2b..34528090e86 100644 --- a/code/__DEFINES/lighting.dm +++ b/code/__DEFINES/lighting.dm @@ -90,3 +90,27 @@ #define FLASH_LIGHT_DURATION 2 #define FLASH_LIGHT_POWER 3 #define FLASH_LIGHT_RANGE 3.8 + +/// Returns the red part of a #RRGGBB hex sequence as number +#define GETREDPART(hexa) hex2num(copytext(hexa, 2, 4)) + +/// Returns the green part of a #RRGGBB hex sequence as number +#define GETGREENPART(hexa) hex2num(copytext(hexa, 4, 6)) + +/// Returns the blue part of a #RRGGBB hex sequence as number +#define GETBLUEPART(hexa) hex2num(copytext(hexa, 6, 8)) + +/// Parse the hexadecimal color into lumcounts of each perspective. +#define PARSE_LIGHT_COLOR(source) \ +do { \ + if (source.light_color) { \ + var/__light_color = source.light_color; \ + source.lum_r = GETREDPART(__light_color) / 255; \ + source.lum_g = GETGREENPART(__light_color) / 255; \ + source.lum_b = GETBLUEPART(__light_color) / 255; \ + } else { \ + source.lum_r = 1; \ + source.lum_g = 1; \ + source.lum_b = 1; \ + }; \ +} while (FALSE) diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index 8de2f30ad2f..2217271a2e7 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -417,16 +417,6 @@ return 0 return 1 - -/proc/GetRedPart(const/hexa) - return hex2num(copytext(hexa, 2, 4)) - -/proc/GetGreenPart(const/hexa) - return hex2num(copytext(hexa, 4, 6)) - -/proc/GetBluePart(const/hexa) - return hex2num(copytext(hexa, 6, 8)) - /proc/lavaland_equipment_pressure_check(turf/T) . = FALSE if(!istype(T)) @@ -438,13 +428,6 @@ if(pressure <= LAVALAND_EQUIPMENT_EFFECT_PRESSURE) . = TRUE -/proc/GetHexColors(const/hexa) - return list( - GetRedPart(hexa), - GetGreenPart(hexa), - GetBluePart(hexa), - ) - /proc/MinutesToTicks(var/minutes as num) return minutes * 60 * 10 diff --git a/code/modules/lighting/lighting_source.dm b/code/modules/lighting/lighting_source.dm index 8e54531f901..fc87a855dc4 100644 --- a/code/modules/lighting/lighting_source.dm +++ b/code/modules/lighting/lighting_source.dm @@ -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. @@ -212,7 +199,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) @@ -233,7 +220,11 @@ 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 diff --git a/code/modules/lighting/lighting_turf.dm b/code/modules/lighting/lighting_turf.dm index c2198cea650..f368ff5ac4b 100644 --- a/code/modules/lighting/lighting_turf.dm +++ b/code/modules/lighting/lighting_turf.dm @@ -110,16 +110,6 @@ else lighting_clear_overlay() -/turf/proc/get_corners() - if(!IS_DYNAMIC_LIGHTING(src) && !light_sources) - return null - if(!lighting_corners_initialised) - generate_missing_corners() - if(has_opaque_atom) - return null // Since this proc gets used in a for loop, null won't be looped though. - - return corners - /turf/proc/generate_missing_corners() if(!IS_DYNAMIC_LIGHTING(src) && !light_sources) return @@ -132,4 +122,3 @@ continue corners[i] = new/datum/lighting_corner(src, GLOB.LIGHTING_CORNER_DIAGONAL[i]) -