mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-21 20:20:33 +01:00
Opacity refactor (#52881)
Moves all opacity var manipulation to a proc which sends a signal.
light_blocker element for movable opaque atoms made, which tracks its movement and updates the affected turfs for proper lighting updates.
has_opaque_atom boolean replaced by the opacity_sources lazylist to keep track of the sources, and a directional_opacity which serves a similar function but also allows for future expansion with on-border opaque objects (not yet implemented).
Some opacity-related sight procs optimized as a result of this.
Some variables moved to the object's definition.
A define or two added into the mix for clarity.
Some code cleaning, like turning booleans into their defines.
One file renamed for clarity.
Changelog
cl
balance: Mechs no longer block sight. It's a non-trivial cost for the lighting system with little to no gain.
/cl
This commit is contained in:
@@ -41,25 +41,36 @@
|
||||
light = new/datum/light_source(src, .)
|
||||
|
||||
|
||||
// Should always be used to change the opacity of an atom.
|
||||
// It notifies (potentially) affected light sources so they can update (if needed).
|
||||
/**
|
||||
* Updates the atom's opacity value.
|
||||
*
|
||||
* This exists to act as a hook for associated behavior.
|
||||
* It notifies (potentially) affected light sources so they can update (if needed).
|
||||
*/
|
||||
/atom/proc/set_opacity(new_opacity)
|
||||
if (new_opacity == opacity)
|
||||
return
|
||||
|
||||
SEND_SIGNAL(src, COMSIG_ATOM_SET_OPACITY, new_opacity)
|
||||
. = opacity
|
||||
opacity = new_opacity
|
||||
var/turf/T = loc
|
||||
if (!isturf(T))
|
||||
|
||||
|
||||
/atom/movable/set_opacity(new_opacity)
|
||||
. = ..()
|
||||
if(isnull(.) || !isturf(loc))
|
||||
return
|
||||
|
||||
if (new_opacity == TRUE)
|
||||
T.has_opaque_atom = TRUE
|
||||
T.reconsider_lights()
|
||||
if(opacity)
|
||||
AddElement(/datum/element/light_blocking)
|
||||
else
|
||||
var/old_has_opaque_atom = T.has_opaque_atom
|
||||
T.recalc_atom_opacity()
|
||||
if (old_has_opaque_atom != T.has_opaque_atom)
|
||||
T.reconsider_lights()
|
||||
RemoveElement(/datum/element/light_blocking)
|
||||
|
||||
|
||||
/turf/set_opacity(new_opacity)
|
||||
. = ..()
|
||||
if(isnull(.))
|
||||
return
|
||||
recalculate_directional_opacity()
|
||||
|
||||
|
||||
/atom/movable/Moved(atom/OldLoc, Dir)
|
||||
|
||||
@@ -224,7 +224,7 @@
|
||||
for(T in view(CEILING(light_range, 1), source_turf))
|
||||
if((!IS_DYNAMIC_LIGHTING(T) && !T.light_sources))
|
||||
continue
|
||||
if(!T.has_opaque_atom)
|
||||
if(!IS_OPAQUE_TURF(T))
|
||||
if (!T.lighting_corners_initialised)
|
||||
T.generate_missing_corners()
|
||||
for (thing in T.corners)
|
||||
|
||||
@@ -1,14 +1,3 @@
|
||||
/turf
|
||||
var/dynamic_lighting = TRUE
|
||||
luminosity = 1
|
||||
|
||||
var/tmp/lighting_corners_initialised = FALSE
|
||||
|
||||
var/tmp/list/datum/light_source/affecting_lights // List of light sources affecting this turf.
|
||||
var/tmp/atom/movable/lighting_object/lighting_object // Our lighting object.
|
||||
var/tmp/list/datum/lighting_corner/corners
|
||||
var/tmp/has_opaque_atom = FALSE // Not to be confused with opacity, this will be TRUE if there's any opaque atom on the tile.
|
||||
|
||||
// Causes any affecting light sources to be queued for a visibility update, for example a door got opened.
|
||||
/turf/proc/reconsider_lights()
|
||||
var/datum/light_source/L
|
||||
@@ -86,21 +75,42 @@
|
||||
|
||||
return !lighting_object.luminosity
|
||||
|
||||
// Can't think of a good name, this proc will recalculate the has_opaque_atom variable.
|
||||
/turf/proc/recalc_atom_opacity()
|
||||
has_opaque_atom = opacity
|
||||
if (!has_opaque_atom)
|
||||
for (var/atom/A in src.contents) // Loop through every movable atom on our tile PLUS ourselves (we matter too...)
|
||||
if (A.opacity)
|
||||
has_opaque_atom = TRUE
|
||||
break
|
||||
|
||||
/turf/Exited(atom/movable/Obj, atom/newloc)
|
||||
. = ..()
|
||||
///Proc to add movable sources of opacity on the turf and let it handle lighting code.
|
||||
/turf/proc/add_opacity_source(atom/movable/new_source)
|
||||
LAZYADD(opacity_sources, new_source)
|
||||
if(opacity)
|
||||
return
|
||||
recalculate_directional_opacity()
|
||||
|
||||
|
||||
///Proc to remove movable sources of opacity on the turf and let it handle lighting code.
|
||||
/turf/proc/remove_opacity_source(atom/movable/old_source)
|
||||
LAZYREMOVE(opacity_sources, old_source)
|
||||
if(opacity) //Still opaque, no need to worry on updating.
|
||||
return
|
||||
recalculate_directional_opacity()
|
||||
|
||||
|
||||
///Calculate on which directions this turfs block view.
|
||||
/turf/proc/recalculate_directional_opacity()
|
||||
. = directional_opacity
|
||||
if(opacity)
|
||||
directional_opacity = ALL_CARDINALS
|
||||
if(. != directional_opacity)
|
||||
reconsider_lights()
|
||||
return
|
||||
directional_opacity = NONE
|
||||
for(var/am in opacity_sources)
|
||||
var/atom/movable/opacity_source = am
|
||||
if(opacity_source.flags_1 & ON_BORDER_1)
|
||||
directional_opacity |= opacity_source.dir
|
||||
else //If fulltile and opaque, then the whole tile blocks view, no need to continue checking.
|
||||
directional_opacity = ALL_CARDINALS
|
||||
break
|
||||
if(. != directional_opacity && (. == ALL_CARDINALS || directional_opacity == ALL_CARDINALS))
|
||||
reconsider_lights() //The lighting system only cares whether the tile is fully concealed from all directions or not.
|
||||
|
||||
if (Obj && Obj.opacity)
|
||||
recalc_atom_opacity() // Make sure to do this before reconsider_lights(), incase we're on instant updates.
|
||||
reconsider_lights()
|
||||
|
||||
/turf/proc/change_area(area/old_area, area/new_area)
|
||||
if(SSlighting.initialized)
|
||||
|
||||
Reference in New Issue
Block a user