From acdbc8a6c4b5b70f67d017589d42d8e7ceb26ece Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Thu, 15 Apr 2021 17:22:45 +0200 Subject: [PATCH] [MIRROR] Makes the GAS system only update the icon when it has changed (#4924) * Makes the GAS system only update the icon when it has changed (#58337) * Makes the GAS system only update the icon when it has changed Co-authored-by: Emmett Gaines --- code/__DEFINES/dcs/signals.dm | 2 - code/controllers/subsystem/greyscale.dm | 11 +---- code/datums/greyscale/_greyscale_config.dm | 26 ++++++++---- code/datums/greyscale/layer.dm | 2 +- code/game/atoms.dm | 40 ++++++++++++------- code/modules/admin/greyscale_modify_menu.dm | 4 +- .../machinery/portable/canister.dm | 16 ++++---- 7 files changed, 57 insertions(+), 44 deletions(-) diff --git a/code/__DEFINES/dcs/signals.dm b/code/__DEFINES/dcs/signals.dm index 677f83fbe4b..a1fb2a2939d 100644 --- a/code/__DEFINES/dcs/signals.dm +++ b/code/__DEFINES/dcs/signals.dm @@ -118,8 +118,6 @@ #define COMSIG_ATOM_UPDATE_ICON_STATE "atom_update_icon_state" ///from base of [/atom/update_overlays]: (list/new_overlays) #define COMSIG_ATOM_UPDATE_OVERLAYS "atom_update_overlays" -///from base of [/atom/update_greyscale]: (list/colors) -#define COMSIG_ATOM_UPDATE_GREYSCALE "atom_update_greyscale" ///from base of [/atom/update_icon]: (signalOut, did_anything) #define COMSIG_ATOM_UPDATED_ICON "atom_updated_icon" ///from base of atom/Entered(): (atom/movable/entering, /atom/oldLoc) diff --git a/code/controllers/subsystem/greyscale.dm b/code/controllers/subsystem/greyscale.dm index f7070e04136..440053421de 100644 --- a/code/controllers/subsystem/greyscale.dm +++ b/code/controllers/subsystem/greyscale.dm @@ -22,13 +22,6 @@ SUBSYSTEM_DEF(greyscale) /datum/controller/subsystem/greyscale/proc/GetColoredIconByType(type, list/colors) type = "[type]" - if(istext(colors)) // It's the color string format for map edits/type values etc - colors = ParseColorString(colors) + if(istype(colors)) // It's the color list format + colors = colors.Join() return configurations[type].Generate(colors) - -/datum/controller/subsystem/greyscale/proc/ParseColorString(colors) - var/list/split_colors = splittext(colors, "#") - var/list/output = list() - for(var/i in 2 to length(split_colors)) - output += "#[split_colors[i]]" - return output diff --git a/code/datums/greyscale/_greyscale_config.dm b/code/datums/greyscale/_greyscale_config.dm index bfd012343a5..78bc4baf644 100644 --- a/code/datums/greyscale/_greyscale_config.dm +++ b/code/datums/greyscale/_greyscale_config.dm @@ -91,15 +91,21 @@ expected_colors = length(color_groups) /// Actually create the icon and color it in, handles caching -/datum/greyscale_config/proc/Generate(list/colors) - if(length(colors) != expected_colors) - CRASH("[DebugName()] expected [expected_colors] color arguments but only received [length(colors)]") - var/key = colors.Join("&") +/datum/greyscale_config/proc/Generate(color_string) + var/key = color_string var/icon/new_icon = icon_cache[key] if(new_icon) - return new_icon - new_icon = icon_cache[key] = GenerateLayerGroup(colors, layers) - return new_icon + return icon(new_icon) + var/list/colors = ParseColorString(color_string) + if(length(colors) != expected_colors) + CRASH("[DebugName()] expected [expected_colors] color arguments but only received [length(colors)]") + new_icon = GenerateLayerGroup(colors, layers) + // We read a pixel to force the icon to be fully generated before we let it loose into the world + // I hate this + new_icon.GetPixel(1, 1) + new_icon = fcopy_rsc(new_icon) + icon_cache[key] = new_icon + return icon(new_icon) /// Internal recursive proc to handle nested layer groups /datum/greyscale_config/proc/GenerateLayerGroup(list/colors, list/group, list/render_steps) @@ -134,3 +140,9 @@ output["icon"] = GenerateLayerGroup(colors, layers, debug_steps) return output + +/datum/greyscale_config/proc/ParseColorString(color_string) + . = list() + var/list/split_colors = splittext(color_string, "#") + for(var/color in 2 to length(split_colors)) + . += "#[split_colors[color]]" diff --git a/code/datums/greyscale/layer.dm b/code/datums/greyscale/layer.dm index b7cc1bc1976..e0c2a1eac86 100644 --- a/code/datums/greyscale/layer.dm +++ b/code/datums/greyscale/layer.dm @@ -71,4 +71,4 @@ var/list/debug_data = reference_config.GenerateDebug(colors) render_steps += debug_data["steps"] return debug_data["icon"] - return reference_config.Generate(colors) + return reference_config.Generate(colors.Join()) diff --git a/code/game/atoms.dm b/code/game/atoms.dm index 6695a024369..875262639fd 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -223,6 +223,8 @@ if(loc) SEND_SIGNAL(loc, COMSIG_ATOM_CREATED, src) /// Sends a signal that the new atom `src`, has been created at `loc` + update_greyscale() + //atom color stuff if(color) add_atom_colour(color, FIXED_COLOUR_PRIORITY) @@ -697,13 +699,6 @@ update_icon_state() . |= UPDATE_ICON_STATE - if(updates & UPDATE_GREYSCALE) - var/list/colors = update_greyscale() - // Updating the greyscale config in update_greyscale() is fine or we would check this earlier - if(greyscale_config) - icon = SSgreyscale.GetColoredIconByType(greyscale_config, colors) - . |= UPDATE_GREYSCALE - if(updates & UPDATE_OVERLAYS) if(LAZYLEN(managed_vis_overlays)) SSvis_overlays.remove_vis_overlay(src, managed_vis_overlays) @@ -724,20 +719,35 @@ SHOULD_CALL_PARENT(TRUE) return SEND_SIGNAL(src, COMSIG_ATOM_UPDATE_ICON_STATE) -/atom/proc/update_greyscale() - SHOULD_CALL_PARENT(TRUE) - . = list() - var/list/raw_rgb = splittext(greyscale_colors, "#") - for(var/i in 2 to length(raw_rgb)) - . += "#[raw_rgb[i]]" - SEND_SIGNAL(src, COMSIG_ATOM_UPDATE_GREYSCALE, .) - /// Updates the overlays of the atom /atom/proc/update_overlays() SHOULD_CALL_PARENT(TRUE) . = list() SEND_SIGNAL(src, COMSIG_ATOM_UPDATE_OVERLAYS, .) +/// Checks if the colors given are different and if so causes a greyscale icon update +/atom/proc/set_greyscale_colors(list/colors) + SHOULD_CALL_PARENT(TRUE) + var/new_colors = colors.Join("") + if(greyscale_colors == new_colors) + return + greyscale_colors = new_colors + if(!greyscale_config) + return + update_greyscale() + +/// Checks if the greyscale config given is different and if so causes a greyscale icon update +/atom/proc/set_greyscale_config(new_config) + if(greyscale_config == new_config) + return + greyscale_config = new_config + update_greyscale() + +/// Checks if this atom uses the GAS system and if so updates the icon +/atom/proc/update_greyscale() + if(greyscale_config && greyscale_colors) + icon = SSgreyscale.GetColoredIconByType(greyscale_config, greyscale_colors) + /** * An atom we are buckled or is contained within us has tried to move * diff --git a/code/modules/admin/greyscale_modify_menu.dm b/code/modules/admin/greyscale_modify_menu.dm index b8d5c212175..e2a3cc4393d 100644 --- a/code/modules/admin/greyscale_modify_menu.dm +++ b/code/modules/admin/greyscale_modify_menu.dm @@ -70,8 +70,8 @@ split_colors[group] = new_color refresh_preview() if("apply") - target.greyscale_colors = split_colors.Join() - target.update_appearance() + target.greyscale_colors = "" // We do this to force an update, in some cases it will think nothing changed when it should be refreshing + target.set_greyscale_colors(split_colors) if("refresh_file") SSgreyscale.RefreshConfigsFromFile() refresh_preview() diff --git a/code/modules/atmospherics/machinery/portable/canister.dm b/code/modules/atmospherics/machinery/portable/canister.dm index 9d703587844..93451f5841f 100644 --- a/code/modules/atmospherics/machinery/portable/canister.dm +++ b/code/modules/atmospherics/machinery/portable/canister.dm @@ -394,23 +394,23 @@ GLOBAL_LIST_INIT(gas_id_to_canister, init_gas_id_to_canister()) var/isBroken = machine_stat & BROKEN ///Function is used to actually set the overlays if(mode) - . += icon(canister_overlay_file, "tier[mode]") + . += mutable_appearance(canister_overlay_file, "tier[mode]") if(isBroken) - . += icon(canister_overlay_file, "broken") + . += mutable_appearance(canister_overlay_file, "broken") if(holding) - . += icon(canister_overlay_file, "can-open") + . += mutable_appearance(canister_overlay_file, "can-open") if(connected_port) - . += icon(canister_overlay_file, "can-connector") + . += mutable_appearance(canister_overlay_file, "can-connector") switch(air_contents.return_pressure()) if((40 * ONE_ATMOSPHERE) to INFINITY) - . += icon(canister_overlay_file, "can-3") + . += mutable_appearance(canister_overlay_file, "can-3") if((10 * ONE_ATMOSPHERE) to (40 * ONE_ATMOSPHERE)) - . += icon(canister_overlay_file, "can-2") + . += mutable_appearance(canister_overlay_file, "can-2") if((5 * ONE_ATMOSPHERE) to (10 * ONE_ATMOSPHERE)) - . += icon(canister_overlay_file, "can-1") + . += mutable_appearance(canister_overlay_file, "can-1") if((10) to (5 * ONE_ATMOSPHERE)) - . += icon(canister_overlay_file, "can-0") + . += mutable_appearance(canister_overlay_file, "can-0") /obj/machinery/portable_atmospherics/canister/should_atmos_process(datum/gas_mixture/air, exposed_temperature)