From 24994ec75270800ced6653a2b0a9e5a8dd4b5dc3 Mon Sep 17 00:00:00 2001 From: Mloc-Argent Date: Sun, 13 Oct 2013 19:44:12 +0100 Subject: [PATCH] Small work on making zones wake up on geometry changes. Also added sleeping for zones with unsimulated tiles; unfortunately it probably won't happen for ages due to a dichotomy paradox. Signed-off-by: Mloc-Argent --- code/ZAS/FEA_gas_mixture.dm | 12 ++++++++++++ code/ZAS/ZAS_Turfs.dm | 2 ++ code/ZAS/ZAS_Zones.dm | 30 +++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/code/ZAS/FEA_gas_mixture.dm b/code/ZAS/FEA_gas_mixture.dm index a4bdb022068..cea0efc3ab7 100644 --- a/code/ZAS/FEA_gas_mixture.dm +++ b/code/ZAS/FEA_gas_mixture.dm @@ -1007,6 +1007,18 @@ What are the archived variables for? return 0 return 1 +/datum/gas_mixture/proc/compare_unsim(turf/list/samples) + //Purpose: Compares a list of unsimulated tiles to self to see if within acceptable ranges that group processing may be enabled + //Called by: ZAS sleeping detection. + //Inputs: List of unsimulated turfs to compare to + //Outputs: 1 if within an acceptable range to sleep, 0 otherwise. + var/datum/gas_mixture/after_share = new + after_share.copy_from(src) + + ShareSpace(after_share, samples) + + return src.compare(after_share) + /datum/gas_mixture/proc/subtract(datum/gas_mixture/right_side) //Purpose: Subtracts right_side from air_mixture. Used to help turfs mingle //Called by: Pipelines ending in a break (or something) diff --git a/code/ZAS/ZAS_Turfs.dm b/code/ZAS/ZAS_Turfs.dm index 7ba40ef715a..12ac2df2445 100644 --- a/code/ZAS/ZAS_Turfs.dm +++ b/code/ZAS/ZAS_Turfs.dm @@ -179,6 +179,8 @@ if((air_check_directions & direction && !(air_directions_archived & direction)) || \ (unsim_check_directions & direction && !(unsim_directions_archived & direction))) ZConnect(src,T) + zone.ActivateIfNeeded() + if(T.zone) T.zone.ActivateIfNeeded() //Something like a wall was built, changing the geometry. else if((!(air_check_directions & direction) && air_directions_archived & direction) || \ diff --git a/code/ZAS/ZAS_Zones.dm b/code/ZAS/ZAS_Zones.dm index 371be846a9c..b58cdd1903a 100644 --- a/code/ZAS/ZAS_Zones.dm +++ b/code/ZAS/ZAS_Zones.dm @@ -21,6 +21,7 @@ var/list/CounterDoorDirections = list(SOUTH,EAST) //Which directions doors turfs var/last_rebuilt = 0 var/status = ZONE_ACTIVE var/interactions_with_neighbors = 0 + var/interactions_with_unsim = 0 var/progress = "nothing" @@ -185,10 +186,14 @@ var/list/CounterDoorDirections = list(SOUTH,EAST) //Which directions doors turfs unsimulated_tiles -= T if(unsimulated_tiles.len) + var/old_pressure = air.return_pressure() var/moved_air = ShareSpace(air,unsimulated_tiles) if(moved_air > vsc.airflow_lightest_pressure) AirflowSpace(src) + + if(old_pressure && (moved_air / old_pressure) > MINIMUM_AIR_RATIO_TO_SUSPEND) //Check if we've moved enough air to be considered awake. + interactions_with_unsim++ else unsimulated_tiles = null @@ -305,10 +310,11 @@ var/list/CounterDoorDirections = list(SOUTH,EAST) //Which directions doors turfs Z.interactions_with_neighbors++ interactions_with_neighbors++ - if(!interactions_with_neighbors && !unsimulated_tiles) + if(!interactions_with_neighbors && !interactions_with_unsim) SetStatus(ZONE_SLEEPING) interactions_with_neighbors = 0 + interactions_with_unsim = 0 progress = "all components completed successfully, the problem is not here" @@ -329,6 +335,28 @@ var/list/CounterDoorDirections = list(SOUTH,EAST) //Which directions doors turfs /zone/proc/CheckStatus() return status + +/zone/proc/ActivateIfNeeded() + if(status == ZONE_ACTIVE) return + + var/difference = 0 + + if(unsimulated_tiles && unsimulated_tiles.len) + if(air.compare_unsim(unsimulated_tiles)) + difference = 1 + + if(!difference) + for(var/zone/Z in connected_zones) //Check adjacent zones for air difference. + if(air.compare(Z.air)) + difference = 1 + break + + if(difference) //We have a difference, activate the zone. + SetStatus(ZONE_ACTIVE) + + return + + /zone/proc/assume_air(var/datum/gas_mixture/giver) if(status == ZONE_ACTIVE) return air.merge(giver)