mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-25 08:34:23 +00: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 * Opacity refactor Co-authored-by: Rohesie <rohesie@gmail.com>
161 lines
4.8 KiB
Plaintext
161 lines
4.8 KiB
Plaintext
|
|
// The proc you should always use to set the light of this atom.
|
|
// Nonesensical value for l_color default, so we can detect if it gets set to null.
|
|
#define NONSENSICAL_VALUE -99999
|
|
/atom/proc/set_light(l_range, l_power, l_color = NONSENSICAL_VALUE)
|
|
if(l_range > 0 && l_range < MINIMUM_USEFUL_LIGHT_RANGE)
|
|
l_range = MINIMUM_USEFUL_LIGHT_RANGE //Brings the range up to 1.4, which is just barely brighter than the soft lighting that surrounds players.
|
|
if (l_power != null)
|
|
light_power = l_power
|
|
|
|
if (l_range != null)
|
|
light_range = l_range
|
|
|
|
if (l_color != NONSENSICAL_VALUE)
|
|
light_color = l_color
|
|
|
|
SEND_SIGNAL(src, COMSIG_ATOM_SET_LIGHT, l_range, l_power, l_color)
|
|
|
|
update_light()
|
|
|
|
#undef NONSENSICAL_VALUE
|
|
|
|
// Will update the light (duh).
|
|
// Creates or destroys it if needed, makes it update values, makes sure it's got the correct source turf...
|
|
/atom/proc/update_light()
|
|
set waitfor = FALSE
|
|
if (QDELETED(src))
|
|
return
|
|
|
|
if (!light_power || !light_range) // We won't emit light anyways, destroy the light source.
|
|
QDEL_NULL(light)
|
|
else
|
|
if (!ismovable(loc)) // We choose what atom should be the top atom of the light here.
|
|
. = src
|
|
else
|
|
. = loc
|
|
|
|
if (light) // Update the light or create it if it does not exist.
|
|
light.update(.)
|
|
else
|
|
light = new/datum/light_source(src, .)
|
|
|
|
|
|
/**
|
|
* 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
|
|
|
|
|
|
/atom/movable/set_opacity(new_opacity)
|
|
. = ..()
|
|
if(isnull(.) || !isturf(loc))
|
|
return
|
|
|
|
if(opacity)
|
|
AddElement(/datum/element/light_blocking)
|
|
else
|
|
RemoveElement(/datum/element/light_blocking)
|
|
|
|
|
|
/turf/set_opacity(new_opacity)
|
|
. = ..()
|
|
if(isnull(.))
|
|
return
|
|
recalculate_directional_opacity()
|
|
|
|
|
|
/atom/movable/Moved(atom/OldLoc, Dir)
|
|
. = ..()
|
|
var/datum/light_source/L
|
|
var/thing
|
|
for (thing in light_sources) // Cycle through the light sources on this atom and tell them to update.
|
|
L = thing
|
|
L.source_atom.update_light()
|
|
|
|
/atom/vv_edit_var(var_name, var_value)
|
|
switch (var_name)
|
|
if (NAMEOF(src, light_range))
|
|
set_light(l_range=var_value)
|
|
datum_flags |= DF_VAR_EDITED
|
|
return TRUE
|
|
|
|
if (NAMEOF(src, light_power))
|
|
set_light(l_power=var_value)
|
|
datum_flags |= DF_VAR_EDITED
|
|
return TRUE
|
|
|
|
if (NAMEOF(src, light_color))
|
|
set_light(l_color=var_value)
|
|
datum_flags |= DF_VAR_EDITED
|
|
return TRUE
|
|
|
|
return ..()
|
|
|
|
|
|
/atom/proc/flash_lighting_fx(_range = FLASH_LIGHT_RANGE, _power = FLASH_LIGHT_POWER, _color = COLOR_WHITE, _duration = FLASH_LIGHT_DURATION, _reset_lighting = TRUE)
|
|
return
|
|
|
|
/turf/flash_lighting_fx(_range = FLASH_LIGHT_RANGE, _power = FLASH_LIGHT_POWER, _color = COLOR_WHITE, _duration = FLASH_LIGHT_DURATION, _reset_lighting = TRUE)
|
|
if(!_duration)
|
|
stack_trace("Lighting FX obj created on a turf without a duration")
|
|
new /obj/effect/dummy/lighting_obj (src, _color, _range, _power, _duration)
|
|
|
|
/obj/flash_lighting_fx(_range = FLASH_LIGHT_RANGE, _power = FLASH_LIGHT_POWER, _color = COLOR_WHITE, _duration = FLASH_LIGHT_DURATION, _reset_lighting = TRUE)
|
|
var/temp_color
|
|
var/temp_power
|
|
var/temp_range
|
|
if(!_reset_lighting) //incase the obj already has a lighting color that you don't want cleared out after, ie computer monitors.
|
|
temp_color = light_color
|
|
temp_power = light_power
|
|
temp_range = light_range
|
|
set_light(_range, _power, _color)
|
|
addtimer(CALLBACK(src, /atom/proc/set_light, _reset_lighting ? initial(light_range) : temp_range, _reset_lighting ? initial(light_power) : temp_power, _reset_lighting ? initial(light_color) : temp_color), _duration, TIMER_OVERRIDE|TIMER_UNIQUE)
|
|
|
|
/mob/living/flash_lighting_fx(_range = FLASH_LIGHT_RANGE, _power = FLASH_LIGHT_POWER, _color = COLOR_WHITE, _duration = FLASH_LIGHT_DURATION, _reset_lighting = TRUE)
|
|
mob_light(_color, _range, _power, _duration)
|
|
|
|
/mob/living/proc/mob_light(_color, _range, _power, _duration)
|
|
var/obj/effect/dummy/lighting_obj/moblight/mob_light_obj = new (src, _color, _range, _power, _duration)
|
|
return mob_light_obj
|
|
|
|
|
|
/atom/proc/set_light_range(new_range)
|
|
if(new_range == light_range)
|
|
return
|
|
SEND_SIGNAL(src, COMSIG_ATOM_SET_LIGHT_RANGE, new_range)
|
|
. = light_range
|
|
light_range = new_range
|
|
|
|
|
|
/atom/proc/set_light_power(new_power)
|
|
if(new_power == light_power)
|
|
return
|
|
SEND_SIGNAL(src, COMSIG_ATOM_SET_LIGHT_POWER, new_power)
|
|
. = light_power
|
|
light_power = new_power
|
|
|
|
|
|
/atom/proc/set_light_color(new_color)
|
|
if(new_color == light_color)
|
|
return
|
|
SEND_SIGNAL(src, COMSIG_ATOM_SET_LIGHT_COLOR, new_color)
|
|
. = light_color
|
|
light_color = new_color
|
|
|
|
|
|
/atom/proc/set_light_on(new_value)
|
|
if(new_value == light_on)
|
|
return
|
|
SEND_SIGNAL(src, COMSIG_ATOM_SET_LIGHT_ON, new_value)
|
|
. = light_on
|
|
light_on = new_value
|