From 1ecbd23a5b653679abf272ebf84ee553a0ddd7c9 Mon Sep 17 00:00:00 2001 From: Fluffy <65877598+FluffyGhoster@users.noreply.github.com> Date: Fri, 1 Dec 2023 13:14:21 +0100 Subject: [PATCH] Optimize air alarms processing and light overlays (#17715) * hfhdg * asf * sdf * fsfa --- code/game/machinery/alarm.dm | 28 ++++++++++++ code/modules/lighting/lighting_overlay.dm | 25 ++++++----- code/modules/xgm/xgm_gas_mixture.dm | 14 +++--- html/changelogs/fluffyghost-optimizations.yml | 43 +++++++++++++++++++ 4 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 html/changelogs/fluffyghost-optimizations.yml diff --git a/code/game/machinery/alarm.dm b/code/game/machinery/alarm.dm index cc46695ba53..573c5e7535c 100644 --- a/code/game/machinery/alarm.dm +++ b/code/game/machinery/alarm.dm @@ -153,6 +153,13 @@ pixel_x = 10; var/global/image/alarm_overlay + //Used to cache the previous gas mixture result, and evaluate if we can skip processing or not + var/previous_environment_group_multiplier = null + var/previous_environment_temperature = null + var/previous_environment_total_moles = null + var/previous_environment_volume = null + var/list/previous_environment_gas = list() + /obj/machinery/alarm/north PRESET_NORTH @@ -361,6 +368,27 @@ pixel_x = 10; var/datum/gas_mixture/environment = location.return_air() + var/is_same_environment = TRUE + for(var/k in environment.gas) + if(environment.gas[k] != previous_environment_gas[k]) + is_same_environment = FALSE + previous_environment_gas = environment.gas.Copy() + break + if(is_same_environment) + if( (environment.temperature != previous_environment_temperature) ||\ + (environment.group_multiplier != previous_environment_group_multiplier) ||\ + (environment.total_moles != previous_environment_total_moles) ||\ + (environment.volume != previous_environment_volume) + ) + is_same_environment = FALSE + previous_environment_group_multiplier = environment.group_multiplier + previous_environment_temperature = environment.temperature + previous_environment_total_moles = environment.total_moles + previous_environment_volume = environment.volume + + if(is_same_environment) + return + //Handle temperature adjustment here. handle_heating_cooling(environment) diff --git a/code/modules/lighting/lighting_overlay.dm b/code/modules/lighting/lighting_overlay.dm index 5f6e7b6f0a9..785ad255118 100644 --- a/code/modules/lighting/lighting_overlay.dm +++ b/code/modules/lighting/lighting_overlay.dm @@ -59,18 +59,21 @@ // See LIGHTING_CORNER_DIAGONAL in lighting_corner.dm for why these values are what they are. var/list/corners = T.corners - var/datum/lighting_corner/cr = dummy_lighting_corner - var/datum/lighting_corner/cg = dummy_lighting_corner - var/datum/lighting_corner/cb = dummy_lighting_corner - var/datum/lighting_corner/ca = dummy_lighting_corner - if (corners) - cr = corners[3] || dummy_lighting_corner - cg = corners[2] || dummy_lighting_corner - cb = corners[4] || dummy_lighting_corner - ca = corners[1] || dummy_lighting_corner - var/max = max(cr.cache_mx, cg.cache_mx, cb.cache_mx, ca.cache_mx) - luminosity = max > LIGHTING_SOFT_THRESHOLD + //Local cache, because otherwise it accesses the global variable repeatedly, which is slower + var/dummy_lighting_corner_cache = dummy_lighting_corner + + var/datum/lighting_corner/cr = dummy_lighting_corner_cache + var/datum/lighting_corner/cg = dummy_lighting_corner_cache + var/datum/lighting_corner/cb = dummy_lighting_corner_cache + var/datum/lighting_corner/ca = dummy_lighting_corner_cache + if (corners) + cr = corners[3] || dummy_lighting_corner_cache + cg = corners[2] || dummy_lighting_corner_cache + cb = corners[4] || dummy_lighting_corner_cache + ca = corners[1] || dummy_lighting_corner_cache + + luminosity = max(cr.cache_mx, cg.cache_mx, cb.cache_mx, ca.cache_mx) > LIGHTING_SOFT_THRESHOLD var/rr = cr.cache_r var/rg = cr.cache_g diff --git a/code/modules/xgm/xgm_gas_mixture.dm b/code/modules/xgm/xgm_gas_mixture.dm index 022d315bd91..b278289e930 100644 --- a/code/modules/xgm/xgm_gas_mixture.dm +++ b/code/modules/xgm/xgm_gas_mixture.dm @@ -1,18 +1,18 @@ /datum/gas_mixture - //Associative list of gas moles. - //Gases with 0 moles are not tracked and are pruned by update_values() + ///Associative list of gas moles. + ///Gases with 0 moles are not tracked and are pruned by update_values() var/list/gas - //Temperature in Kelvin of this gas mix. + ///Temperature in Kelvin of this gas mix. var/temperature = 0 - //Sum of all the gas moles in this mix. Updated by update_values() + ///Sum of all the gas moles in this mix. Updated by update_values() var/total_moles = 0 - //Volume of this mix. + ///Volume of this mix. var/volume = CELL_VOLUME - //Size of the group this gas_mixture is representing. 1 for singletons. + ///Size of the group this gas_mixture is representing. 1 for singletons. var/group_multiplier = 1 - //List of active tile overlays for this gas_mixture. Updated by check_tile_graphic() + ///List of active tile overlays for this gas_mixture. Updated by check_tile_graphic() var/list/graphic /datum/gas_mixture/New(_volume = CELL_VOLUME, _temperature = 0, _group_multiplier = 1) diff --git a/html/changelogs/fluffyghost-optimizations.yml b/html/changelogs/fluffyghost-optimizations.yml new file mode 100644 index 00000000000..40629f3a942 --- /dev/null +++ b/html/changelogs/fluffyghost-optimizations.yml @@ -0,0 +1,43 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# wip (For works in progress) +# tweak +# soundadd +# sounddel +# rscadd (general adding of nice things) +# rscdel (general deleting of nice things) +# imageadd +# imagedel +# maptweak +# spellcheck (typo fixes) +# experiment +# balance +# admin +# backend +# security +# refactor +################################# + +# Your name. +author: FluffyGhost + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries. +# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog. +changes: + - refactor: "DMdoced some ZAS variables from comments." + - backend: "Optimized air alarms not to reprocess gasses if the atmosphere has not changed, saving more than half of the median execution time." + - backend: "Optimized lights overlay updating, which is now around 10 percent more performant in median execution time."