From a6d4e180adf47504e16b5e521ed249ba496bb1c4 Mon Sep 17 00:00:00 2001 From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Date: Sat, 18 Jun 2022 17:50:18 -0700 Subject: [PATCH] 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 --- 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_corner.dm | 17 +++++++++++++++++ code/modules/lighting/lighting_object.dm | 5 +++++ 6 files changed, 33 insertions(+) diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index aa942b9d13e..df95c8d4eaa 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -260,6 +260,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 94d17a40bcb..a4ccce442ca 100644 --- a/code/_compile_options.dm +++ b/code/_compile_options.dm @@ -35,6 +35,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 29999a8ff46..378a849dfa1 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 791677903ab..704e7fb19e0 100644 --- a/code/controllers/subsystem/timer.dm +++ b/code/controllers/subsystem/timer.dm @@ -565,6 +565,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_corner.dm b/code/modules/lighting/lighting_corner.dm index 19285ae9888..572cd8b50d7 100644 --- a/code/modules/lighting/lighting_corner.dm +++ b/code/modules/lighting/lighting_corner.dm @@ -88,8 +88,14 @@ // God that was a mess, now to do the rest of the corner code! Hooray! /datum/lighting_corner/proc/update_lumcount(delta_r, delta_g, delta_b) + +#ifdef VISUALIZE_LIGHT_UPDATES + if (!SSlighting.allow_duped_values && !(delta_r || delta_g || delta_b)) // 0 is falsey ok + return +#else if (!(delta_r || delta_g || delta_b)) // 0 is falsey ok return +#endif lum_r += delta_r lum_g += delta_g @@ -109,6 +115,10 @@ if (largest_color_luminosity > 1) . = 1 / largest_color_luminosity + var/old_r = cache_r + var/old_g = cache_g + var/old_b = cache_b + #if LIGHTING_SOFT_THRESHOLD != 0 else if (largest_color_luminosity < LIGHTING_SOFT_THRESHOLD) . = 0 // 0 means soft lighting. @@ -123,6 +133,13 @@ #endif src.largest_color_luminosity = round(largest_color_luminosity, LIGHTING_ROUND_VALUE) +#ifdef VISUALIZE_LIGHT_UPDATES + if(!SSlighting.allow_duped_corners && old_r == cache_r && old_g == cache_g && old_b == cache_b) + return +#else + if(old_r == cache_r && old_g == cache_g && old_b == cache_b) + return +#endif var/datum/lighting_object/lighting_object = master_NE?.lighting_object if (lighting_object && !lighting_object.needs_update) diff --git a/code/modules/lighting/lighting_object.dm b/code/modules/lighting/lighting_object.dm index 21cfb8003cf..9004e35b204 100644 --- a/code/modules/lighting/lighting_object.dm +++ b/code/modules/lighting/lighting_object.dm @@ -43,6 +43,11 @@ 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?"