From 810ca147d071992a61e5b3cc627ba8b1de7f1b38 Mon Sep 17 00:00:00 2001 From: mwerezak Date: Sat, 12 Sep 2015 19:34:43 -0400 Subject: [PATCH] Fixes #10710 --- code/modules/lighting/light_source.dm | 48 ++++++++++++++++----------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/code/modules/lighting/light_source.dm b/code/modules/lighting/light_source.dm index 2acddb4d29..3675cd945c 100644 --- a/code/modules/lighting/light_source.dm +++ b/code/modules/lighting/light_source.dm @@ -1,3 +1,5 @@ +//So much copypasta in this file, supposedly in the name of performance. If you change anything make sure to consider other places where the code may have been copied. + /datum/light_source var/atom/top_atom var/atom/source_atom @@ -11,9 +13,10 @@ var/lum_g var/lum_b - var/tmp/old_lum_r - var/tmp/old_lum_g - var/tmp/old_lum_b + //hold onto the actual applied lum values so we can undo them when the lighting changes + var/tmp/applied_lum_r + var/tmp/applied_lum_g + var/tmp/applied_lum_b var/list/effect_str var/list/effect_turf @@ -107,11 +110,6 @@ if(light_range && light_power && !applied) . = 1 - if(. || source_atom.light_color != light_color)//Save the old lumcounts if we need to update, if the colour changed DO IT BEFORE we parse the colour and LOSE the old lumcounts! - old_lum_r = lum_r - old_lum_g = lum_g - old_lum_b = lum_b - if(source_atom.light_color != light_color) light_color = source_atom.light_color parse_light_color() @@ -149,6 +147,12 @@ /datum/light_source/proc/apply_lum() applied = 1 + + //Keep track of the last applied lum values so that the lighting can be reversed + applied_lum_r = lum_r + applied_lum_g = lum_g + applied_lum_b = lum_b + if(istype(source_turf)) FOR_DVIEW(var/turf/T, light_range, source_turf, INVISIBILITY_LIGHTING) if(T.lighting_overlay) @@ -164,9 +168,9 @@ effect_str += strength T.lighting_overlay.update_lumcount( - lum_r * strength, - lum_g * strength, - lum_b * strength + applied_lum_r * strength, + applied_lum_g * strength, + applied_lum_b * strength ) else @@ -188,7 +192,11 @@ if(T.lighting_overlay) var/str = effect_str[i] - T.lighting_overlay.update_lumcount(-str * old_lum_r, -str * old_lum_g, -str * old_lum_b) + T.lighting_overlay.update_lumcount( + -str * applied_lum_r, + -str * applied_lum_g, + -str * applied_lum_b + ) i++ @@ -218,9 +226,9 @@ effect_str += . T.lighting_overlay.update_lumcount( - lum_r * ., - lum_g * ., - lum_b * . + applied_lum_r * ., + applied_lum_g * ., + applied_lum_b * . ) else @@ -241,7 +249,7 @@ if(T.lighting_overlay) var/str = effect_str[idx] - T.lighting_overlay.update_lumcount(-str * lum_r, -str * lum_g, -str * lum_b) + T.lighting_overlay.update_lumcount(-str * applied_lum_r, -str * applied_lum_g, -str * applied_lum_b) effect_turf.Cut(idx, idx + 1) effect_str.Cut(idx, idx + 1) @@ -279,10 +287,12 @@ effect_str[idx] = . + //Since the applied_lum values are what are (later) removed by remove_lum. + //Anything we apply to the lighting overlays HAS to match what remove_lum uses. T.lighting_overlay.update_lumcount( - lum_r * ., - lum_g * ., - lum_b * . + applied_lum_r * ., + applied_lum_g * ., + applied_lum_b * . ) #undef LUM_FALLOFF