diff --git a/code/modules/lighting/__lighting_docs.dm b/code/modules/lighting/__lighting_docs.dm index 6ad0e32cdbc..5ac5897eb53 100644 --- a/code/modules/lighting/__lighting_docs.dm +++ b/code/modules/lighting/__lighting_docs.dm @@ -51,7 +51,7 @@ turf: (lighting_turf.dm) - proc/lighting_clear_overlays(): - Delete (manual GC) all light overlays on this turf, used when changing turf to space - proc/lighting_build_overlays(): - - Create lighting overlays for this turf + - Create lighting overlays for this turf. Called by ChangeTurf in case the turf is being changed to use dynamic lighting. atom/movable/lighting_overlay: (lighting_overlay.dm) diff --git a/code/modules/lighting/light_source.dm b/code/modules/lighting/light_source.dm index 73a65f064fc..2acddb4d298 100644 --- a/code/modules/lighting/light_source.dm +++ b/code/modules/lighting/light_source.dm @@ -246,6 +246,45 @@ effect_turf.Cut(idx, idx + 1) effect_str.Cut(idx, idx + 1) +//Whoop yet not another copy pasta because speed ~~~~BYOND. +//Calculates and applies lighting for a single turf. This is intended for when a turf switches to +//using dynamic lighting when it was not doing so previously (when constructing a floor on space, for example). +//Assumes the turf is visible and such. +//For the love of god don't call this proc when it's not needed! Lighting artifacts WILL happen! +/datum/light_source/proc/calc_turf(var/turf/T) + var/idx = effect_turf.Find(T) + if(!idx) + return //WHY. + + if(T.lighting_overlay) + #if LIGHTING_FALLOFF == 1 // circular + . = (T.lighting_overlay.x - source_turf.x)**2 + (T.lighting_overlay.y - source_turf.y)**2 + LIGHTING_HEIGHT + #if LIGHTING_LAMBERTIAN == 1 + . = CLAMP01((1 - CLAMP01(sqrt(.) / light_range)) * (1 / (sqrt(. + 1)))) + #else + . = 1 - CLAMP01(sqrt(.) / light_range) + #endif + + #elif LIGHTING_FALLOFF == 2 // square + . = abs(T.lighting_overlay.x - source_turf.x) + abs(T.lighting_overlay.y - source_turf.y) + LIGHTING_HEIGHT + #if LIGHTING_LAMBERTIAN == 1 + . = CLAMP01((1 - CLAMP01(. / light_range)) * (1 / (sqrt(.)**2 + ))) + #else + . = 1 - CLAMP01(. / light_range) + #endif + #endif + . *= light_power + + . = round(., LIGHTING_ROUND_VALUE) + + effect_str[idx] = . + + T.lighting_overlay.update_lumcount( + lum_r * ., + lum_g * ., + lum_b * . + ) + #undef LUM_FALLOFF #undef LUM_DISTANCE #undef LUM_ATTENUATION diff --git a/code/modules/lighting/lighting_turf.dm b/code/modules/lighting/lighting_turf.dm index e261931c41c..f8f0a5ab102 100644 --- a/code/modules/lighting/lighting_turf.dm +++ b/code/modules/lighting/lighting_turf.dm @@ -17,6 +17,10 @@ var/atom/movable/lighting_overlay/O = PoolOrNew(/atom/movable/lighting_overlay, src) lighting_overlay = O + //Make the light sources recalculate us so the lighting overlay updates immediately + for(var/datum/light_source/L in affecting_lights) + L.calc_turf(src) + /turf/Entered(atom/movable/obj) . = ..() if(obj && obj.opacity)