From 597902f7452b0074ffff91c54eecee4f76164bfb Mon Sep 17 00:00:00 2001 From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Date: Thu, 3 Feb 2022 07:58:36 -0800 Subject: [PATCH] Moves adjacent air into the main atmos subsystem (#64559) We should just straight up not be processing turfs if the adjacent turf isn't correctly setup It used to be on a seperate subsystem with a second wait with the idea of reducing the cost of explosions, but since they're instant now there's no reason to not just have it on SSair. Gets rid of my excuse for process_cell runtimes too --- code/__DEFINES/atmospherics/atmos_helpers.dm | 4 +- code/__DEFINES/subsystems.dm | 1 - code/controllers/subsystem/adjacent_air.dm | 41 -------------------- code/controllers/subsystem/air.dm | 39 ++++++++++++++++++- tgstation.dme | 1 - 5 files changed, 40 insertions(+), 46 deletions(-) delete mode 100644 code/controllers/subsystem/adjacent_air.dm diff --git a/code/__DEFINES/atmospherics/atmos_helpers.dm b/code/__DEFINES/atmospherics/atmos_helpers.dm index f97004e975a..433ecd3c7f7 100644 --- a/code/__DEFINES/atmospherics/atmos_helpers.dm +++ b/code/__DEFINES/atmospherics/atmos_helpers.dm @@ -60,9 +60,9 @@ GLOBAL_LIST_INIT(nonoverlaying_gases, typecache_of_gases_with_no_overlays()) #ifdef TESTING GLOBAL_LIST_INIT(atmos_adjacent_savings, list(0,0)) -#define CALCULATE_ADJACENT_TURFS(T, state) if (SSadjacent_air.queue[T]) { GLOB.atmos_adjacent_savings[1] += 1 } else { GLOB.atmos_adjacent_savings[2] += 1; SSadjacent_air.queue[T] = state} +#define CALCULATE_ADJACENT_TURFS(T, state) if (SSair.adjacent_rebuild[T]) { GLOB.atmos_adjacent_savings[1] += 1 } else { GLOB.atmos_adjacent_savings[2] += 1; SSair.adjacent_rebuild[T] = state} #else -#define CALCULATE_ADJACENT_TURFS(T, state) SSadjacent_air.queue[T] = state +#define CALCULATE_ADJACENT_TURFS(T, state) SSair.adjacent_rebuild[T] = state #endif //If you're doing spreading things related to atmos, DO NOT USE CANATMOSPASS, IT IS NOT CHEAP. use this instead, the info is cached after all. it's tweaked just a bit to allow for circular checks diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index ba86b66a4bf..2f90b04d66c 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -192,7 +192,6 @@ #define FIRE_PRIORITY_MOBS 100 #define FIRE_PRIORITY_TGUI 110 #define FIRE_PRIORITY_TICKER 200 -#define FIRE_PRIORITY_ATMOS_ADJACENCY 300 #define FIRE_PRIORITY_STATPANEL 390 #define FIRE_PRIORITY_CHAT 400 #define FIRE_PRIORITY_RUNECHAT 410 diff --git a/code/controllers/subsystem/adjacent_air.dm b/code/controllers/subsystem/adjacent_air.dm deleted file mode 100644 index cde823399db..00000000000 --- a/code/controllers/subsystem/adjacent_air.dm +++ /dev/null @@ -1,41 +0,0 @@ -SUBSYSTEM_DEF(adjacent_air) - name = "Atmos Adjacency" - flags = SS_BACKGROUND - runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME - wait = 10 - priority = FIRE_PRIORITY_ATMOS_ADJACENCY - var/list/queue = list() - -/datum/controller/subsystem/adjacent_air/stat_entry(msg) -#ifdef TESTING - msg = "P:[length(queue)], S:[GLOB.atmos_adjacent_savings[1]], T:[GLOB.atmos_adjacent_savings[2]]" -#else - msg = "P:[length(queue)]" -#endif - return ..() - -/datum/controller/subsystem/adjacent_air/Initialize() - while(length(queue)) - fire(mc_check = FALSE) - return ..() - -/datum/controller/subsystem/adjacent_air/fire(resumed = FALSE, mc_check = TRUE) - - var/list/queue = src.queue - - while (length(queue)) - var/turf/currT = queue[1] - var/goal = queue[currT] - queue.Cut(1,2) - - currT.immediate_calculate_adjacent_turfs() - if(goal == MAKE_ACTIVE) - SSair.add_to_active(currT) - else if(goal == KILL_EXCITED) - SSair.add_to_active(currT, TRUE) - - if(mc_check) - if(MC_TICK_CHECK) - break - else - CHECK_TICK diff --git a/code/controllers/subsystem/air.dm b/code/controllers/subsystem/air.dm index 3bf6fc1cd07..2323a614c3b 100644 --- a/code/controllers/subsystem/air.dm +++ b/code/controllers/subsystem/air.dm @@ -17,6 +17,7 @@ SUBSYSTEM_DEF(air) var/cost_pipenets = 0 var/cost_atmos_machinery = 0 var/cost_rebuilds = 0 + var/cost_adjacent = 0 var/list/excited_groups = list() var/list/active_turfs = list() @@ -25,10 +26,12 @@ SUBSYSTEM_DEF(air) var/list/rebuild_queue = list() //Subservient to rebuild queue var/list/expansion_queue = list() + /// List of turfs to recalculate adjacent turfs on before processing + var/list/adjacent_rebuild = list() /// A list of machines that will be processed when currentpart == SSAIR_ATMOSMACHINERY. Use SSair.begin_processing_machine and SSair.stop_processing_machine to add and remove machines. var/list/obj/machinery/atmos_machinery = list() - var/list/pipe_init_dirs_cache = list() + var/list/pipe_init_dirs_cache = list() //atmos singletons var/list/gas_reactions = list() var/list/atmos_gen @@ -59,6 +62,7 @@ SUBSYSTEM_DEF(air) msg += "AM:[round(cost_atmos_machinery,1)]|" msg += "AO:[round(cost_atoms, 1)]|" msg += "RB:[round(cost_rebuilds,1)]|" + msg += "AJ:[round(cost_adjacent,1)]|" msg += "} " msg += "AT:[active_turfs.len]|" msg += "HS:[hotspots.len]|" @@ -70,6 +74,7 @@ SUBSYSTEM_DEF(air) msg += "AO:[atom_process.len]|" msg += "RB:[rebuild_queue.len]|" msg += "EP:[expansion_queue.len]|" + msg += "AJ:[adjacent_rebuild.len]|" msg += "AT/MS:[round((cost ? active_turfs.len/cost : 0),0.1)]" return ..() @@ -82,6 +87,7 @@ SUBSYSTEM_DEF(air) setup_atmos_machinery() setup_pipenets() setup_turf_visuals() + process_adjacent_rebuild() return ..() @@ -90,6 +96,16 @@ SUBSYSTEM_DEF(air) //Rebuilds can happen at any time, so this needs to be done outside of the normal system cost_rebuilds = 0 + cost_adjacent = 0 + + // We need to have a solid setup for turfs before fire, otherwise we'll get massive runtimes and strange behavior + if(length(adjacent_rebuild)) + timer = TICK_USAGE_REAL + process_adjacent_rebuild() + //This does mean that the apperent rebuild costs fluctuate very quickly, this is just the cost of having them always process, no matter what + cost_adjacent = TICK_USAGE_REAL - timer + if(state != SS_RUNNING) + return // Every time we fire, we want to make sure pipenets are rebuilt. The game state could have changed between each fire() proc call // and anything missing a pipenet can lead to unintended behaviour at worse and various runtimes at best. @@ -206,6 +222,7 @@ SUBSYSTEM_DEF(air) networks = SSair.networks rebuild_queue = SSair.rebuild_queue expansion_queue = SSair.expansion_queue + adjacent_rebuild = SSair.adjacent_rebuild atmos_machinery = SSair.atmos_machinery pipe_init_dirs_cache = SSair.pipe_init_dirs_cache gas_reactions = SSair.gas_reactions @@ -217,6 +234,26 @@ SUBSYSTEM_DEF(air) currentrun = SSair.currentrun queued_for_activation = SSair.queued_for_activation +/datum/controller/subsystem/air/proc/process_adjacent_rebuild(init = FALSE) + var/list/queue = adjacent_rebuild + + while (length(queue)) + var/turf/currT = queue[1] + var/goal = queue[currT] + queue.Cut(1,2) + + currT.immediate_calculate_adjacent_turfs() + if(goal == MAKE_ACTIVE) + add_to_active(currT) + else if(goal == KILL_EXCITED) + add_to_active(currT, TRUE) + + if(init) + CHECK_TICK + else + if(MC_TICK_CHECK) + break + /datum/controller/subsystem/air/proc/process_pipenets(resumed = FALSE) if (!resumed) src.currentrun = networks.Copy() diff --git a/tgstation.dme b/tgstation.dme index 7e99466b6e1..6956ae09d23 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -414,7 +414,6 @@ #include "code\controllers\configuration\entries\resources.dm" #include "code\controllers\subsystem\achievements.dm" #include "code\controllers\subsystem\addiction.dm" -#include "code\controllers\subsystem\adjacent_air.dm" #include "code\controllers\subsystem\ai_controllers.dm" #include "code\controllers\subsystem\air.dm" #include "code\controllers\subsystem\ambience.dm"