From 3b371cac499864d0a915ba62621c2cd9294e83a4 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Sat, 11 May 2024 11:07:59 +0100 Subject: [PATCH] Proper luminosity usage (#10889) * Proper luminosity usage * Only perform updates where necessary * Removes some non-relevant things --- code/__DEFINES/lighting.dm | 8 ++++---- code/game/area/areas.dm | 4 ++-- code/game/atoms.dm | 20 +++++++++++++------ .../structures/crates_lockers/closets.dm | 7 ------- code/modules/lighting/lighting_object.dm | 4 ++-- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/code/__DEFINES/lighting.dm b/code/__DEFINES/lighting.dm index 3580a933297d4..f034dd4800f60 100644 --- a/code/__DEFINES/lighting.dm +++ b/code/__DEFINES/lighting.dm @@ -139,16 +139,16 @@ GLOBAL_DATUM_INIT(starlight_overlay, /image, create_starlight_overlay()) /// Add a luminosity source to a target #define ADD_LUM_SOURCE(target, em_source) \ -target._emissive_count |= em_source;\ -if (target._emissive_count == em_source)\ +UNLINT(target._emissive_count |= em_source);\ +if (UNLINT(target._emissive_count == em_source))\ {\ target.update_luminosity();\ } /// Remove a luminosity source to a target #define REMOVE_LUM_SOURCE(target, em_source) \ -target._emissive_count &= ~(em_source);\ -if (target._emissive_count == 0)\ +UNLINT(target._emissive_count &= ~(em_source));\ +if (UNLINT(target._emissive_count == 0))\ {\ target.update_luminosity();\ } diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 4eca7edafc33b..df6b03f7fdf85 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -207,7 +207,7 @@ GLOBAL_LIST_EMPTY(teleportlocs) if(dynamic_lighting == DYNAMIC_LIGHTING_IFSTARLIGHT) dynamic_lighting = CONFIG_GET(flag/starlight) ? DYNAMIC_LIGHTING_ENABLED : DYNAMIC_LIGHTING_DISABLED if(dynamic_lighting == DYNAMIC_LIGHTING_DISABLED) - base_luminosity = 1 + set_base_luminosity(src, 1) . = ..() @@ -246,7 +246,7 @@ GLOBAL_LIST_EMPTY(teleportlocs) update_lighting_overlay() //Areas with a lighting overlay should be fully visible, and the tiles adjacent to them should also //be luminous - luminosity = 1 + set_base_luminosity(src, 1) //Add the lighting overlay add_overlay(lighting_overlay) diff --git a/code/game/atoms.dm b/code/game/atoms.dm index 55d5fd7475f10..0705e3a4004e3 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -143,10 +143,12 @@ ///LazyList of all balloon alerts currently on this atom var/list/balloon_alerts - /// How much luminosity should we have by default? - var/base_luminosity = 0 + /// What is our default level of luminosity, if you want inherent luminosity + /// withing an atom's type, set luminosity instead and we will manage it for you. + /// Always use set_base_luminosity instead of directly modifying this + VAR_PRIVATE/base_luminosity = 0 /// DO NOT EDIT THIS, USE ADD_LUM_SOURCE INSTEAD - var/_emissive_count = 0 + VAR_PRIVATE/_emissive_count = 0 /** * Called when an atom is created in byond (built in engine proc) @@ -1912,10 +1914,16 @@ if (isnull(base_luminosity)) base_luminosity = initial(luminosity) - if (_emissive_count) - luminosity = max(max(base_luminosity, affecting_dynamic_lumi), 1) + if (UNLINT(_emissive_count)) + UNLINT(luminosity = max(max(base_luminosity, affecting_dynamic_lumi), 1)) else - luminosity = max(base_luminosity, affecting_dynamic_lumi) + UNLINT(luminosity = max(base_luminosity, affecting_dynamic_lumi)) + +#define set_base_luminosity(target, new_value)\ +if (UNLINT(target.base_luminosity != new_value)) {\ + UNLINT(target.base_luminosity = new_value);\ + target.update_luminosity();\ +} /atom/movable/proc/get_orbitable() return src diff --git a/code/game/objects/structures/crates_lockers/closets.dm b/code/game/objects/structures/crates_lockers/closets.dm index 71d88db88d179..55fb4fdb4881d 100644 --- a/code/game/objects/structures/crates_lockers/closets.dm +++ b/code/game/objects/structures/crates_lockers/closets.dm @@ -124,13 +124,6 @@ ADD_LUM_SOURCE(src, LUM_SOURCE_MANAGED_OVERLAY) . += locked ? icon_locked : icon_unlocked -/obj/structure/closet/update_appearance(updates=ALL) - . = ..() - if((opened || broken || !secure) || !imacrate) - luminosity = 0 - return - luminosity = 1 - /obj/structure/closet/proc/animate_door(var/closing = FALSE) if(!door_anim_time) return diff --git a/code/modules/lighting/lighting_object.dm b/code/modules/lighting/lighting_object.dm index 846c8a2387b31..664438d2a031e 100644 --- a/code/modules/lighting/lighting_object.dm +++ b/code/modules/lighting/lighting_object.dm @@ -23,7 +23,6 @@ if (myturf.lighting_object) qdel(myturf.lighting_object, force = TRUE) myturf.lighting_object = src - myturf.luminosity = 0 additive_underlay = mutable_appearance(LIGHTING_ICON, "light", FLOAT_LAYER, LIGHTING_PLANE_ADDITIVE, 255, RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM) additive_underlay.blend_mode = BLEND_ADD @@ -40,7 +39,6 @@ stack_trace("A lighting object was qdeleted with a different loc then it is suppose to have ([COORD(oldturf)] -> [COORD(newturf)])") if (isturf(myturf)) myturf.lighting_object = null - myturf.luminosity = initial(myturf.luminosity) myturf.underlays -= additive_underlay myturf = null @@ -148,6 +146,8 @@ else myturf.underlays -= additive_underlay + // Use luminosity directly because we are the lighting object + // and not the turf luminosity = set_luminosity if (myturf.above)