Skip to content

Commit

Permalink
Lighting refactor (#801)
Browse files Browse the repository at this point in the history
* Adds a visualizer for lighting object updating. Optimizes the same (#67678)

It occured to me, we didn't have a good way to "see" what turfs were actually being updated
Figured I'd fix that

I've also added some debug vars on SSlighting to make testing with/without some checks easier

Speaking of which, I've added a second check to lighting corner updating
Basically, if our past and current cached rgb values are the same, there's no point updating

This is possible because static lighting is relative. If you've got a
TON of blue, it'll outweight the red and green you have in smaller amounts

We also do some rounding to ensure values look right

Similarly, if you've got roughly the same lighting, and a bit of something you already have a lot of is added, you're not likely to actually enter a new "bracket" of color

Anyway uh, it's hard to profile this, but I've seen it help quite a bit, mostly with things like emergency lighting that updates lighting in small amounts often, and in constricted spaces.

To some extent just comes down to map design

* .

* tgstation/tgstation#69838

* tgstation/tgstation#81423
  • Loading branch information
Kapu1178 authored Feb 26, 2024
1 parent 24a2227 commit 6263519
Show file tree
Hide file tree
Showing 63 changed files with 286 additions and 311 deletions.
8 changes: 4 additions & 4 deletions code/__DEFINES/lighting.dm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
///Object doesn't use any of the light systems. Should be changed to add a light source to the object.
#define NO_LIGHT_SUPPORT 0
///Light made with the lighting datums, applying a matrix.
#define STATIC_LIGHT 1
#define COMPLEX_LIGHT 1
///Light made by masking the lighting darkness plane.
#define MOVABLE_LIGHT 2
#define OVERLAY_LIGHT 2
///Light made by masking the lighting darkness plane, and is directional.
#define MOVABLE_LIGHT_DIRECTIONAL 3
#define OVERLAY_LIGHT_DIRECTIONAL 3

///Is a movable light source attached to another movable (its loc), meaning that the lighting component should go one level deeper.
/// Is our overlay light source attached to another movable (its loc), meaning that the lighting component should go one level deeper.
#define LIGHT_ATTACHED (1<<0)

//Bay lighting engine shit, not in /code/modules/lighting because BYOND is being shit about it
Expand Down
1 change: 1 addition & 0 deletions code/__DEFINES/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
* * callback the callback to call on timer finish
* * wait deciseconds to run the timer for
* * flags flags for this timer, see: code\__DEFINES\subsystems.dm
* * timer_subsystem the subsystem to insert this timer into
*/
#define addtimer(args...) _addtimer(args, file = __FILE__, line = __LINE__)

Expand Down
8 changes: 5 additions & 3 deletions code/_compile_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
///Be warned, this increases timer creation cost by 5x
// #define TIMER_DEBUG

// Displays static object lighting updates
// Also enables some debug vars on sslighting that can be used to modify
// How extensively we prune lighting corners to update
// #define VISUALIZE_LIGHT_UPDATES

///If this is uncommented, force our verb processing into just the 2% of a tick
///We normally reserve for it
///NEVER run this on live, it's for simulating highpop only
Expand Down Expand Up @@ -145,9 +150,6 @@

/////////////////////// ZMIMIC

///Enables Multi-Z lighting
#define ZMIMIC_LIGHT_BLEED

///Enables multi-z speech
#define ZMIMIC_MULTIZ_SPEECH

Expand Down
4 changes: 4 additions & 0 deletions code/controllers/subsystem/lighting.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ SUBSYSTEM_DEF(lighting)
var/static/list/sources_queue = list() // List of lighting sources queued for update.
var/static/list/corners_queue = list() // List of lighting corners queued for update.
var/static/list/objects_queue = list() // List of lighting objects queued for update.
#ifdef VISUALIZE_LIGHT_UPDATES
var/allow_duped_values = FALSE
var/allow_duped_corners = FALSE
#endif

/datum/controller/subsystem/lighting/PreInit()
. = ..()
Expand Down
1 change: 1 addition & 0 deletions code/controllers/subsystem/timer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ SUBSYSTEM_DEF(timer)
* * callback the callback to call on timer finish
* * wait deciseconds to run the timer for
* * flags flags for this timer, see: code\__DEFINES\subsystems.dm
* * timer_subsystem the subsystem to insert this timer into
*/
/proc/_addtimer(datum/callback/callback, wait = 0, flags = 0, datum/controller/subsystem/timer/timer_subsystem, file, line)
if (!callback)
Expand Down
4 changes: 2 additions & 2 deletions code/datums/components/overlay_lighting.dm
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
return COMPONENT_INCOMPATIBLE

var/atom/movable/movable_parent = parent
if(movable_parent.light_system != MOVABLE_LIGHT && movable_parent.light_system != MOVABLE_LIGHT_DIRECTIONAL)
stack_trace("[type] added to [parent], with [movable_parent.light_system] value for the light_system var. Use [MOVABLE_LIGHT] or [MOVABLE_LIGHT_DIRECTIONAL] instead.")
if(movable_parent.light_system != OVERLAY_LIGHT && movable_parent.light_system != OVERLAY_LIGHT_DIRECTIONAL)
stack_trace("[type] added to [parent], with [movable_parent.light_system] value for the light_system var. Use [OVERLAY_LIGHT] or [OVERLAY_LIGHT_DIRECTIONAL] instead.")
return COMPONENT_INCOMPATIBLE

. = ..()
Expand Down
2 changes: 1 addition & 1 deletion code/datums/elements/light_eaten.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/// Because the lighting system does not like movable lights getting set_light() called.
switch(atom_target.light_system)
if(STATIC_LIGHT)
if(COMPLEX_LIGHT)
target.set_light(0, 0, null, FALSE)
else
target.set_light_power(0)
Expand Down
12 changes: 6 additions & 6 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
var/material_modifier = 1

///Light systems, both shouldn't be active at the same time.
var/light_system = STATIC_LIGHT
var/light_system = COMPLEX_LIGHT
///Range of the maximum brightness of light in tiles. Zero means no light.
var/light_inner_range = 0
///Range where light begins to taper into darkness in tiles.
Expand Down Expand Up @@ -250,7 +250,7 @@
if(color)
add_atom_colour(color, FIXED_COLOUR_PRIORITY)

if (light_system == STATIC_LIGHT && light_power && (light_inner_range || light_outer_range))
if (light_system == COMPLEX_LIGHT && light_power && (light_inner_range || light_outer_range))
update_light()

if(uses_integrity)
Expand Down Expand Up @@ -1198,23 +1198,23 @@
/atom/vv_edit_var(var_name, var_value)
switch(var_name)
if(NAMEOF(src, light_inner_range))
if(light_system == STATIC_LIGHT)
if(light_system == COMPLEX_LIGHT)
set_light(l_inner_range = var_value)
. = TRUE
if(NAMEOF(src, light_outer_range))
if(light_system == STATIC_LIGHT)
if(light_system == COMPLEX_LIGHT)
set_light(l_outer_range = var_value)
else
set_light_range(var_value)
. = TRUE
if(NAMEOF(src, light_power))
if(light_system == STATIC_LIGHT)
if(light_system == COMPLEX_LIGHT)
set_light(l_power = var_value)
else
set_light_power(var_value)
. = TRUE
if(NAMEOF(src, light_color))
if(light_system == STATIC_LIGHT)
if(light_system == COMPLEX_LIGHT)
set_light(l_color = var_value)
else
set_light_color(var_value)
Expand Down
4 changes: 2 additions & 2 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@
if(opacity)
AddElement(/datum/element/light_blocking)
switch(light_system)
if(MOVABLE_LIGHT)
if(OVERLAY_LIGHT)
AddComponent(/datum/component/overlay_lighting)
if(MOVABLE_LIGHT_DIRECTIONAL)
if(OVERLAY_LIGHT_DIRECTIONAL)
AddComponent(/datum/component/overlay_lighting, is_directional = TRUE)

/atom/movable/Destroy(force)
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/flasher.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/flasher, 26)
strength = 80
anchored = FALSE
density = TRUE
light_system = MOVABLE_LIGHT //Used as a flash here.
light_system = OVERLAY_LIGHT //Used as a flash here.
light_outer_range = FLASH_LIGHT_RANGE
light_on = FALSE
///Proximity monitor associated with this atom, needed for proximity checks.
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/effects/effect_system/effects_sparks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
name = "sparks"
icon_state = "sparks"
anchored = TRUE
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = 2
light_power = 0.5
light_color = LIGHT_COLOR_FIRE
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/effects/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
name = "lighting fx obj"
desc = "Tell a coder if you're seeing this."
icon_state = "nothing"
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = MINIMUM_USEFUL_LIGHT_RANGE
light_color = COLOR_WHITE
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/cigs_lighters.dm
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ CIGARETTE PACKETS ARE IN FANCY.DM
resistance_flags = FIRE_PROOF
grind_results = list(/datum/reagent/iron = 1, /datum/reagent/fuel = 5, /datum/reagent/fuel/oil = 5)
custom_price = PAYCHECK_ASSISTANT * 1.1
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = 2
light_power = 0.6
light_color = LIGHT_COLOR_FIRE
Expand Down
20 changes: 10 additions & 10 deletions code/game/objects/items/devices/flashlight.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
slot_flags = ITEM_SLOT_BELT
custom_materials = list(/datum/material/iron=50, /datum/material/glass=20)
actions_types = list(/datum/action/item_action/toggle_light)
light_system = MOVABLE_LIGHT_DIRECTIONAL
light_system = OVERLAY_LIGHT_DIRECTIONAL
light_outer_range = 4
light_power = 0.3
light_on = FALSE
Expand All @@ -33,7 +33,7 @@
else
icon_state = initial(icon_state)
set_light_on(on)
if(light_system == STATIC_LIGHT)
if(light_system == COMPLEX_LIGHT)
update_light()


Expand Down Expand Up @@ -237,7 +237,7 @@
force = 10
light_outer_range = 3.5
light_power = 0.9
light_system = STATIC_LIGHT
light_system = COMPLEX_LIGHT
light_color = LIGHT_COLOR_FAINT_BLUE
w_class = WEIGHT_CLASS_BULKY
flags_1 = CONDUCT_1
Expand Down Expand Up @@ -286,7 +286,7 @@
var/produce_heat = 1500
heat = 1000
light_color = LIGHT_COLOR_FLARE
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
grind_results = list(/datum/reagent/sulfur = 15)

/obj/item/flashlight/flare/Initialize(mapload)
Expand Down Expand Up @@ -369,7 +369,7 @@
righthand_file = 'icons/mob/inhands/equipment/mining_righthand.dmi'
desc = "A mining lantern."
light_outer_range = 6 // luminosity when on
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT

/obj/item/flashlight/lantern/heirloom_moth
name = "old lantern"
Expand Down Expand Up @@ -400,7 +400,7 @@
slot_flags = ITEM_SLOT_BELT
custom_materials = null
light_outer_range = 7 //luminosity when on
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT

/obj/item/flashlight/emp
var/emp_max_charges = 4
Expand Down Expand Up @@ -465,7 +465,7 @@
custom_price = PAYCHECK_PRISONER
w_class = WEIGHT_CLASS_SMALL
light_outer_range = 4
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
color = LIGHT_COLOR_GREEN
icon_state = "glowstick"
base_icon_state = "glowstick"
Expand Down Expand Up @@ -574,7 +574,7 @@
name = "disco light"
desc = "Groovy..."
icon_state = null
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = 4
light_power = 10
alpha = 0
Expand Down Expand Up @@ -604,7 +604,7 @@
desc = "A strange device manufactured with mysterious elements that somehow emits darkness. Or maybe it just sucks in light? Nobody knows for sure."
icon_state = "flashdark"
inhand_icon_state = "flashdark"
light_system = STATIC_LIGHT //The overlay light component is not yet ready to produce darkness.
light_system = COMPLEX_LIGHT //The overlay light component is not yet ready to produce darkness.
light_outer_range = 0
///Variable to preserve old lighting behavior in flashlights, to handle darkness.
var/dark_light_range = 2.5
Expand All @@ -623,7 +623,7 @@
/obj/item/flashlight/eyelight
name = "eyelight"
desc = "This shouldn't exist outside of someone's head, how are you seeing this?"
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = 15
light_power = 1
flags_1 = CONDUCT_1
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/dualsaber.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
w_class = WEIGHT_CLASS_SMALL
hitsound = SFX_SWING_HIT

light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = 6 //TWICE AS BRIGHT AS A REGULAR ESWORD
light_color = LIGHT_COLOR_ELECTRIC_GREEN
light_on = FALSE
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/flamethrower.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
custom_materials = list(/datum/material/iron=500)
resistance_flags = FIRE_PROOF
trigger_guard = TRIGGER_GUARD_NORMAL
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_on = FALSE
var/status = FALSE
var/lit = FALSE //on or off
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/melee/energy.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
attack_verb_continuous = list("hits", "taps", "pokes")
attack_verb_simple = list("hit", "tap", "poke")
resistance_flags = FIRE_PROOF
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = 3
light_power = 1
light_on = FALSE
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/tools/weldingtool.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
usesound = list('sound/items/welder.ogg', 'sound/items/welder2.ogg')
drop_sound = 'sound/items/handling/weldingtool_drop.ogg'
pickup_sound = 'sound/items/handling/weldingtool_pickup.ogg'
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = 2
light_power = 0.75
light_color = LIGHT_COLOR_FIRE
Expand Down
4 changes: 2 additions & 2 deletions code/modules/antagonists/cult/cult_items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Striking a noncultist, however, will tear their flesh."}
throw_speed = 1
throw_range = 3
sharpness = SHARP_EDGED
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = 4
light_color = COLOR_RED
attack_verb_continuous = list("cleaves", "slashes", "tears", "lacerates", "hacks", "rips", "dices", "carves")
Expand Down Expand Up @@ -999,7 +999,7 @@ Striking a noncultist, however, will tear their flesh."}
icon = 'icons/effects/effects.dmi'
icon_state = "at_shield2"
layer = FLY_LAYER
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = 2
duration = 8
var/target
Expand Down
2 changes: 1 addition & 1 deletion code/modules/assembly/flash.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
throwforce = 0
w_class = WEIGHT_CLASS_TINY
custom_materials = list(/datum/material/iron = 300, /datum/material/glass = 300)
light_system = MOVABLE_LIGHT //Used as a flash here.
light_system = OVERLAY_LIGHT //Used as a flash here.
light_outer_range = FLASH_LIGHT_RANGE
light_color = COLOR_WHITE
light_power = FLASH_LIGHT_POWER
Expand Down
2 changes: 1 addition & 1 deletion code/modules/atmospherics/ZAS/Fire.dm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ If it gains pressure too slowly, it may leak or just rupture instead of explodin
icon_state = "1"
layer = GASFIRE_LAYER
blend_mode = BLEND_ADD
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = LIGHT_RANGE_FIRE
light_power = 1
light_color = LIGHT_COLOR_FIRE
Expand Down
2 changes: 1 addition & 1 deletion code/modules/clothing/head/cakehat.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
flags_inv = HIDEEARS|HIDEHAIR
armor = list(BLUNT = 0, PUNCTURE = 0, SLASH = 0, LASER = 0, ENERGY = 0, BOMB = 0, BIO = 0, FIRE = 0, ACID = 0)
light_outer_range = 2 //luminosity when on
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
flags_cover = HEADCOVERSEYES
heat = 999
supports_variations_flags = CLOTHING_TESHARI_VARIATION | CLOTHING_VOX_VARIATION
Expand Down
2 changes: 1 addition & 1 deletion code/modules/clothing/head/hardhat.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
resistance_flags = FIRE_PROOF
zmm_flags = ZMM_MANGLE_PLANES

light_system = MOVABLE_LIGHT_DIRECTIONAL
light_system = OVERLAY_LIGHT_DIRECTIONAL
light_outer_range = 4
light_power = 0.2
light_on = FALSE
Expand Down
2 changes: 1 addition & 1 deletion code/modules/clothing/shoes/kindlekicks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
icon_state = "kindleKicks"
inhand_icon_state = "kindleKicks"
actions_types = list(/datum/action/item_action/kindle_kicks)
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = 2
light_power = 3
light_on = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
inhand_icon_state = "eng_helm"
max_integrity = 300
armor = list(BLUNT = 10, PUNCTURE = 5, SLASH = 0, LASER = 10, ENERGY = 20, BOMB = 10, BIO = 100, FIRE = 50, ACID = 75)
light_system = MOVABLE_LIGHT_DIRECTIONAL
light_system = OVERLAY_LIGHT_DIRECTIONAL
light_outer_range = 4
light_power = 1
light_on = FALSE
Expand Down
2 changes: 1 addition & 1 deletion code/modules/clothing/spacesuits/plasmamen.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
tint = 2
armor = list(BLUNT = 0, PUNCTURE = 0, SLASH = 0, LASER = 0, ENERGY = 0, BOMB = 0, BIO = 100, FIRE = 100, ACID = 75)
resistance_flags = FIRE_PROOF
light_system = MOVABLE_LIGHT_DIRECTIONAL
light_system = OVERLAY_LIGHT_DIRECTIONAL
light_outer_range = 4
light_on = FALSE
var/helmet_on = FALSE
Expand Down
2 changes: 1 addition & 1 deletion code/modules/hydroponics/grown/ambrosia.dm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
name = "ambrosia gaia branch"
desc = "Eating this <i>makes</i> you immortal."
icon_state = "ambrosia_gaia"
light_system = MOVABLE_LIGHT
light_system = OVERLAY_LIGHT
light_outer_range = 3
seed = /obj/item/seeds/ambrosia/gaia
wine_power = 70
Expand Down
Loading

0 comments on commit 6263519

Please sign in to comment.