From b095316f2f7dfd22db2c3227630558839a478d7f Mon Sep 17 00:00:00 2001 From: nevimer <77420409+nevimer@users.noreply.github.com> Date: Fri, 20 Jan 2023 14:25:43 -0500 Subject: [PATCH] Mirrors https://github.com/tgstation/tgstation/pull/67678 (#18835) 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 (cherry picked from commit a6d4e180adf47504e16b5e521ed249ba496bb1c4) # Conflicts: # code/modules/lighting/lighting_object.dm Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> --- code/__DEFINES/subsystems.dm | 1 + code/_compile_options.dm | 5 +++++ code/controllers/subsystem/lighting.dm | 4 ++++ code/controllers/subsystem/timer.dm | 1 + code/modules/lighting/lighting_object.dm | 6 ++++++ 5 files changed, 17 insertions(+) diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index a52b3585edc..5c87a89b618 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -284,6 +284,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__) diff --git a/code/_compile_options.dm b/code/_compile_options.dm index 752dce5206e..7a6680dc4b2 100644 --- a/code/_compile_options.dm +++ b/code/_compile_options.dm @@ -43,6 +43,11 @@ */ //#define REAGENTS_TESTING +// 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 + #define VISUALIZE_ACTIVE_TURFS //Highlights atmos active turfs in green #define TRACK_MAX_SHARE //Allows max share tracking, for use in the atmos debugging ui #endif //ifdef TESTING diff --git a/code/controllers/subsystem/lighting.dm b/code/controllers/subsystem/lighting.dm index 6e65c9056c7..f79136f678b 100644 --- a/code/controllers/subsystem/lighting.dm +++ b/code/controllers/subsystem/lighting.dm @@ -6,6 +6,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/stat_entry(msg) msg = "L:[length(sources_queue)]|C:[length(corners_queue)]|O:[length(objects_queue)]" diff --git a/code/controllers/subsystem/timer.dm b/code/controllers/subsystem/timer.dm index 9a043ffba41..c632d9d4f04 100644 --- a/code/controllers/subsystem/timer.dm +++ b/code/controllers/subsystem/timer.dm @@ -569,6 +569,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) diff --git a/code/modules/lighting/lighting_object.dm b/code/modules/lighting/lighting_object.dm index cd590008720..04990095209 100644 --- a/code/modules/lighting/lighting_object.dm +++ b/code/modules/lighting/lighting_object.dm @@ -50,6 +50,12 @@ GLOBAL_LIST_EMPTY(default_lighting_underlays_by_z) return ..() /datum/lighting_object/proc/update() +#ifdef VISUALIZE_LIGHT_UPDATES + affected_turf.add_atom_colour(COLOR_BLUE_LIGHT, ADMIN_COLOUR_PRIORITY) + animate(affected_turf, 10, color = null) + addtimer(CALLBACK(affected_turf, /atom/proc/remove_atom_colour, ADMIN_COLOUR_PRIORITY, COLOR_BLUE_LIGHT), 10, TIMER_UNIQUE|TIMER_OVERRIDE) +#endif + // To the future coder who sees this and thinks // "Why didn't he just use a loop?" // Well my man, it's because the loop performed like shit.