Skip to content

Commit

Permalink
Proper luminosity usage (#10889)
Browse files Browse the repository at this point in the history
* Proper luminosity usage

* Only perform updates where necessary

* Removes some non-relevant things
  • Loading branch information
PowerfulBacon authored May 11, 2024
1 parent f0280ed commit 3b371ca
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
8 changes: 4 additions & 4 deletions code/__DEFINES/lighting.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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();\
}
4 changes: 2 additions & 2 deletions code/game/area/areas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)

. = ..()

Expand Down Expand Up @@ -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)

Expand Down
20 changes: 14 additions & 6 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
7 changes: 0 additions & 7 deletions code/game/objects/structures/crates_lockers/closets.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions code/modules/lighting/lighting_object.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3b371ca

Please sign in to comment.