From 798de9baf19d0c96293639745c26f40084cbae92 Mon Sep 17 00:00:00 2001 From: Ghom <42542238+Ghommie@users.noreply.github.com> Date: Tue, 9 Jun 2020 06:15:26 +0200 Subject: [PATCH] Porting "Speeds up /datum/light_source/proc/update_corners() by 16% or so" (#12496) --- code/__DEFINES/lighting.dm | 25 ++++++++++++++++++++++++ code/__HELPERS/game.dm | 16 --------------- code/modules/lighting/lighting_source.dm | 24 +++++------------------ 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/code/__DEFINES/lighting.dm b/code/__DEFINES/lighting.dm index 5ba696b274..3fba27ba52 100644 --- a/code/__DEFINES/lighting.dm +++ b/code/__DEFINES/lighting.dm @@ -88,3 +88,28 @@ #define EMISSIVE_BLOCK_GENERIC 1 /// Uses a dedicated render_target object to copy the entire appearance in real time to the blocking layer. For things that can change in appearance a lot from the base state, like humans. #define EMISSIVE_BLOCK_UNIQUE 2 + + +/// 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 75ac6a8b26..8d7941fdf8 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -544,22 +544,6 @@ var/obj/machinery/announcement_system/announcer = pick(GLOB.announcement_systems) announcer.announce("ARRIVAL", character.real_name, rank, list()) //make the list empty to make it announce it in common -/proc/GetHexColors(const/hexa) - return list( - GetRedPart(hexa)/ 255, - GetGreenPart(hexa)/ 255, - GetBluePart(hexa)/ 255 - ) - -/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)) diff --git a/code/modules/lighting/lighting_source.dm b/code/modules/lighting/lighting_source.dm index d97967dff9..324e6c1e99 100644 --- a/code/modules/lighting/lighting_source.dm +++ b/code/modules/lighting/lighting_source.dm @@ -9,7 +9,7 @@ var/turf/pixel_turf // The turf the top_atom appears to over. var/light_power // Intensity of the emitter light. var/light_range // The range of the emitted light. - var/light_color // The colour of the light, string, decomposed by parse_light_color() + var/light_color // The colour of the light, string, decomposed by PARSE_LIGHT_COLOR() // Variables for keeping track of the colour. var/lum_r @@ -48,12 +48,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) @@ -99,17 +97,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. @@ -224,7 +211,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) @@ -241,17 +228,16 @@ var/list/turf/turfs = list() var/thing 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)) turfs += T - if(!IS_DYNAMIC_LIGHTING(T) && !T.light_sources) + if((!IS_DYNAMIC_LIGHTING(T) && !T.light_sources) || T.has_opaque_atom ) continue if(!T.lighting_corners_initialised) T.generate_missing_corners() - if(T.has_opaque_atom) - continue corners[T.lc_topright] = 0 corners[T.lc_bottomright] = 0 corners[T.lc_bottomleft] = 0