From a2f9aaf89931614ead93fe1d8b2bcf54a9da8c57 Mon Sep 17 00:00:00 2001
From: Ghommie <42542238+Ghommie@users.noreply.github.com>
Date: Mon, 28 Oct 2019 17:04:31 +0100
Subject: [PATCH] Porting "Adjacent Atmos subsystem revival"
---
code/__DEFINES/atmospherics.dm | 7 ++++
code/__DEFINES/subsystems.dm | 6 +---
code/__DEFINES/turf_flags.dm | 1 +
code/controllers/subsystem/adjacent_air.dm | 35 +++++++++++++++++++
code/game/turfs/change_turf.dm | 9 +++--
code/game/turfs/open.dm | 2 +-
code/game/turfs/turf.dm | 4 +--
.../environmental/LINDA_system.dm | 4 +--
code/modules/holodeck/area_copy.dm | 2 +-
code/modules/power/supermatter/supermatter.dm | 2 +-
tgstation.dme | 1 +
11 files changed, 59 insertions(+), 14 deletions(-)
create mode 100644 code/controllers/subsystem/adjacent_air.dm
diff --git a/code/__DEFINES/atmospherics.dm b/code/__DEFINES/atmospherics.dm
index f73a74ab19..baf29240c3 100644
--- a/code/__DEFINES/atmospherics.dm
+++ b/code/__DEFINES/atmospherics.dm
@@ -251,6 +251,13 @@
out_var += cached_gases[total_moles_id];\
}
+#ifdef TESTING
+GLOBAL_LIST_INIT(atmos_adjacent_savings, list(0,0))
+#define CALCULATE_ADJACENT_TURFS(T) if (SSadjacent_air.queue[T]) { GLOB.atmos_adjacent_savings[1] += 1 } else { GLOB.atmos_adjacent_savings[2] += 1; SSadjacent_air.queue[T] = 1 }
+#else
+#define CALCULATE_ADJACENT_TURFS(T) SSadjacent_air.queue[T] = 1
+#endif
+
//Unomos - So for whatever reason, garbage collection actually drastically decreases the cost of atmos later in the round. Turning this into a define yields massively improved performance.
#define GAS_GARBAGE_COLLECT(GASGASGAS)\
var/list/CACHE_GAS = GASGASGAS;\
diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm
index d4086bc4d9..a4fd695fbf 100644
--- a/code/__DEFINES/subsystems.dm
+++ b/code/__DEFINES/subsystems.dm
@@ -26,10 +26,6 @@
#define TIMER_ID_NULL -1
-//For servers that can't do with any additional lag, set this to none in flightpacks.dm in subsystem/processing.
-#define FLIGHTSUIT_PROCESSING_NONE 0
-#define FLIGHTSUIT_PROCESSING_FULL 1
-
#define INITIALIZATION_INSSATOMS 0 //New should not call Initialize
#define INITIALIZATION_INNEW_MAPLOAD 2 //New should call Initialize(TRUE)
#define INITIALIZATION_INNEW_REGULAR 1 //New should call Initialize(FALSE)
@@ -112,10 +108,10 @@
#define FIRE_PRIORITY_AIR_TURFS 40
#define FIRE_PRIORITY_DEFAULT 50
#define FIRE_PRIORITY_PARALLAX 65
-#define FIRE_PRIORITY_FLIGHTPACKS 80
#define FIRE_PRIORITY_MOBS 100
#define FIRE_PRIORITY_TGUI 110
#define FIRE_PRIORITY_TICKER 200
+#define FIRE_PRIORITY_ATMOS_ADJACENCY 300
#define FIRE_PRIORITY_CHAT 400
#define FIRE_PRIORITY_OVERLAYS 500
#define FIRE_PRIORITY_INPUT 1000 // This must always always be the max highest priority. Player input must never be lost.
diff --git a/code/__DEFINES/turf_flags.dm b/code/__DEFINES/turf_flags.dm
index 5ceb6f2e2e..8604a92c01 100644
--- a/code/__DEFINES/turf_flags.dm
+++ b/code/__DEFINES/turf_flags.dm
@@ -3,3 +3,4 @@
#define CHANGETURF_FORCEOP 4
#define CHANGETURF_SKIP 8 // A flag for PlaceOnTop to just instance the new turf instead of calling ChangeTurf. Used for uninitialized turfs NOTHING ELSE
#define CHANGETURF_INHERIT_AIR 16 // Inherit air from previous turf. Implies CHANGETURF_IGNORE_AIR
+#define CHANGETURF_RECALC_ADJACENT 32 //Immediately recalc adjacent atmos turfs instead of queuing.
\ No newline at end of file
diff --git a/code/controllers/subsystem/adjacent_air.dm b/code/controllers/subsystem/adjacent_air.dm
new file mode 100644
index 0000000000..8395eda708
--- /dev/null
+++ b/code/controllers/subsystem/adjacent_air.dm
@@ -0,0 +1,35 @@
+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()
+#ifdef TESTING
+ ..("P:[length(queue)], S:[GLOB.atmos_adjacent_savings[1]], T:[GLOB.atmos_adjacent_savings[2]]")
+#else
+ ..("P:[length(queue)]")
+#endif
+
+/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]
+ queue.Cut(1,2)
+
+ currT.ImmediateCalculateAdjacentTurfs()
+
+ if(mc_check)
+ if(MC_TICK_CHECK)
+ break
+ else
+ CHECK_TICK
\ No newline at end of file
diff --git a/code/game/turfs/change_turf.dm b/code/game/turfs/change_turf.dm
index f1c5080c8f..6a055bbd35 100644
--- a/code/game/turfs/change_turf.dm
+++ b/code/game/turfs/change_turf.dm
@@ -15,7 +15,7 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
if(turf_type)
var/turf/newT = ChangeTurf(turf_type, baseturf_type, flags)
SSair.remove_from_active(newT)
- newT.CalculateAdjacentTurfs()
+ CALCULATE_ADJACENT_TURFS(newT)
SSair.add_to_active(newT,1)
/turf/proc/copyTurf(turf/T)
@@ -140,6 +140,8 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
newTurf.air = stashed_air
SSair.add_to_active(newTurf)
else
+ if(ispath(path,/turf/closed))
+ flags |= CHANGETURF_RECALC_ADJACENT
return ..()
// Take off the top layer turf and replace it with the next baseturf down
@@ -263,7 +265,10 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
//If you modify this function, ensure it works correctly with lateloaded map templates.
/turf/proc/AfterChange(flags) //called after a turf has been replaced in ChangeTurf()
levelupdate()
- CalculateAdjacentTurfs()
+ if(flags & CHANGETURF_RECALC_ADJACENT)
+ ImmediateCalculateAdjacentTurfs()
+ else
+ CALCULATE_ADJACENT_TURFS(src)
//update firedoor adjacency
var/list/turfs_to_check = get_adjacent_open_turfs(src) | src
diff --git a/code/game/turfs/open.dm b/code/game/turfs/open.dm
index 833a07c9c3..1730a2ec85 100644
--- a/code/game/turfs/open.dm
+++ b/code/game/turfs/open.dm
@@ -200,7 +200,7 @@
update_visuals()
current_cycle = times_fired
- CalculateAdjacentTurfs()
+ ImmediateCalculateAdjacentTurfs()
for(var/i in atmos_adjacent_turfs)
var/turf/open/enemy_tile = i
var/datum/gas_mixture/enemy_air = enemy_tile.return_air()
diff --git a/code/game/turfs/turf.dm b/code/game/turfs/turf.dm
index 7fe48365ef..1b2ccda82c 100755
--- a/code/game/turfs/turf.dm
+++ b/code/game/turfs/turf.dm
@@ -62,7 +62,7 @@
add_overlay(/obj/effect/fullbright)
if(requires_activation)
- CalculateAdjacentTurfs()
+ CALCULATE_ADJACENT_TURFS(src)
SSair.add_to_active(src)
if (light_power && light_range)
@@ -85,7 +85,7 @@
return INITIALIZE_HINT_NORMAL
/turf/proc/Initalize_Atmos(times_fired)
- CalculateAdjacentTurfs()
+ CALCULATE_ADJACENT_TURFS(src)
/turf/Destroy(force)
. = QDEL_HINT_IWILLGC
diff --git a/code/modules/atmospherics/environmental/LINDA_system.dm b/code/modules/atmospherics/environmental/LINDA_system.dm
index 1ad899920a..5c6e33a2e8 100644
--- a/code/modules/atmospherics/environmental/LINDA_system.dm
+++ b/code/modules/atmospherics/environmental/LINDA_system.dm
@@ -43,7 +43,7 @@
/atom/movable/proc/BlockSuperconductivity() // objects that block air and don't let superconductivity act. Only firelocks atm.
return FALSE
-/turf/proc/CalculateAdjacentTurfs()
+/turf/proc/ImmediateCalculateAdjacentTurfs()
var/canpass = CANATMOSPASS(src, src)
var/canvpass = CANVERTICALATMOSPASS(src, src)
for(var/direction in GLOB.cardinals_multiz)
@@ -107,7 +107,7 @@
/turf/air_update_turf(command = 0)
if(command)
- CalculateAdjacentTurfs()
+ ImmediateCalculateAdjacentTurfs()
SSair.add_to_active(src,command)
/atom/movable/proc/move_update_air(turf/T)
diff --git a/code/modules/holodeck/area_copy.dm b/code/modules/holodeck/area_copy.dm
index efe7418e44..5e7d0a08dc 100644
--- a/code/modules/holodeck/area_copy.dm
+++ b/code/modules/holodeck/area_copy.dm
@@ -122,7 +122,7 @@ GLOBAL_LIST_INIT(duplicate_forbidden_vars,list(
if(toupdate.len)
for(var/turf/T1 in toupdate)
- T1.CalculateAdjacentTurfs()
+ CALCULATE_ADJACENT_TURFS(T1)
SSair.add_to_active(T1,1)
diff --git a/code/modules/power/supermatter/supermatter.dm b/code/modules/power/supermatter/supermatter.dm
index 1b3a2a716c..06d1812ece 100644
--- a/code/modules/power/supermatter/supermatter.dm
+++ b/code/modules/power/supermatter/supermatter.dm
@@ -313,7 +313,7 @@ GLOBAL_DATUM(main_supermatter_engine, /obj/machinery/power/supermatter_crystal)
playsound(T, 'sound/effects/supermatter.ogg', 50, 1)
T.visible_message("[T] smacks into [src] and rapidly flashes to ash.",\
"You hear a loud crack as you are washed with a wave of heat.")
- T.CalculateAdjacentTurfs()
+ CALCULATE_ADJACENT_TURFS(T)
/obj/machinery/power/supermatter_crystal/process_atmos()
var/turf/T = loc
diff --git a/tgstation.dme b/tgstation.dme
index 545687805b..89d5cb3a3c 100755
--- a/tgstation.dme
+++ b/tgstation.dme
@@ -224,6 +224,7 @@
#include "code\controllers\configuration\entries\game_options.dm"
#include "code\controllers\configuration\entries\general.dm"
#include "code\controllers\subsystem\acid.dm"
+#include "code\controllers\subsystem\adjacent_air.dm"
#include "code\controllers\subsystem\air.dm"
#include "code\controllers\subsystem\air_turfs.dm"
#include "code\controllers\subsystem\assets.dm"