update auxmos

This commit is contained in:
Katherine Kiefer
2023-08-18 22:13:30 +10:00
parent a36c4fd163
commit 16a490ee5c
19 changed files with 63 additions and 238 deletions
+44 -181
View File
@@ -29,11 +29,7 @@ SUBSYSTEM_DEF(air)
var/list/hotspots = list()
var/list/networks = list()
var/list/pipenets_needing_rebuilt = list()
var/list/deferred_airs = list()
var/cur_deferred_airs = 0
var/max_deferred_airs = 0
var/list/obj/machinery/atmos_machinery = list()
var/list/obj/machinery/atmos_air_machinery = list()
var/list/pipe_init_dirs_cache = list()
//atmos singletons
@@ -57,8 +53,6 @@ SUBSYSTEM_DEF(air)
var/equalize_hard_turf_limit = 2000
// Whether equalization is enabled. Can be disabled for performance reasons.
var/equalize_enabled = TRUE
// Whether equalization should be enabled.
var/should_do_equalization = TRUE
// When above 0, won't equalize; performance handling
var/eq_cooldown = 0
// Whether turf-to-turf heat exchanging should be enabled.
@@ -97,7 +91,6 @@ SUBSYSTEM_DEF(air)
msg += "LT:[low_pressure_turfs]|"
msg += "ET:[num_equalize_processed]|"
msg += "GT:[num_group_turfs_processed]|"
msg += "DF:[max_deferred_airs]|"
msg += "GA:[get_amt_gas_mixes()]|"
msg += "MG:[get_max_gas_mixes()]"
return ..()
@@ -108,7 +101,6 @@ SUBSYSTEM_DEF(air)
setup_atmos_machinery()
setup_pipenets()
gas_reactions = init_gas_reactions()
should_do_equalization = CONFIG_GET(flag/atmos_equalize_enabled)
auxtools_update_reactions()
return ..()
@@ -157,6 +149,35 @@ SUBSYSTEM_DEF(air)
if(state != SS_RUNNING)
return
resumed = FALSE
currentpart = SSAIR_ACTIVETURFS
if(currentpart == SSAIR_ACTIVETURFS)
timer = TICK_USAGE_REAL
process_turfs(resumed)
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_EXCITEDGROUPS
if(currentpart == SSAIR_EXCITEDGROUPS)
process_excited_groups(resumed)
if(state != SS_RUNNING)
return
resumed = 0
currentpart = equalize_enabled ? SSAIR_EQUALIZE : SSAIR_FINALIZE_TURFS
if(currentpart == SSAIR_EQUALIZE)
equalize_turfs(resumed)
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_FINALIZE_TURFS
if(currentpart == SSAIR_FINALIZE_TURFS)
finish_turf_processing(resumed)
if(state != SS_RUNNING)
return
resumed = FALSE
currentpart = SSAIR_PIPENETS
if(currentpart == SSAIR_PIPENETS || !resumed)
@@ -167,7 +188,6 @@ SUBSYSTEM_DEF(air)
return
resumed = 0
currentpart = SSAIR_ATMOSMACHINERY
// This is only machinery like filters, mixers that don't interact with air
if(currentpart == SSAIR_ATMOSMACHINERY)
timer = TICK_USAGE_REAL
process_atmos_machinery(resumed)
@@ -184,34 +204,6 @@ SUBSYSTEM_DEF(air)
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_FINALIZE_TURFS
// This literally just waits for the turf processing thread to finish, doesn't do anything else.
// this is necessary cause the next step after this interacts with the air--we get consistency
// issues if we don't wait for it, disappearing gases etc.
if(currentpart == SSAIR_FINALIZE_TURFS)
finish_turf_processing(resumed)
if(state != SS_RUNNING)
cur_thread_wait_ticks++
return
resumed = 0
thread_wait_ticks = MC_AVERAGE(thread_wait_ticks, cur_thread_wait_ticks)
cur_thread_wait_ticks = 0
currentpart = SSAIR_DEFERRED_AIRS
if(currentpart == SSAIR_DEFERRED_AIRS)
timer = TICK_USAGE_REAL
process_deferred_airs(resumed)
cost_deferred_airs = MC_AVERAGE(cost_deferred_airs, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_ATMOSMACHINERY_AIR
if(currentpart == SSAIR_ATMOSMACHINERY_AIR)
timer = TICK_USAGE_REAL
process_atmos_air_machinery(resumed)
cost_atmos_machinery = MC_AVERAGE(cost_atmos_machinery, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_HOTSPOTS
if(currentpart == SSAIR_HOTSPOTS)
@@ -221,7 +213,7 @@ SUBSYSTEM_DEF(air)
if(state != SS_RUNNING)
return
resumed = 0
currentpart = heat_enabled ? SSAIR_TURF_CONDUCTION : SSAIR_ACTIVETURFS
currentpart = heat_enabled ? SSAIR_TURF_CONDUCTION : SSAIR_REBUILD_PIPENETS
// Heat -- slow and of questionable usefulness. Off by default for this reason. Pretty cool, though.
if(currentpart == SSAIR_TURF_CONDUCTION)
timer = TICK_USAGE_REAL
@@ -231,48 +223,7 @@ SUBSYSTEM_DEF(air)
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_ACTIVETURFS
// This simply starts the turf thread. It runs in the background until the FINALIZE_TURFS step, at which point it's waited for.
// This also happens to do all the commented out stuff below, all in a single separate thread. This is mostly so that the
// waiting is consistent.
if(currentpart == SSAIR_ACTIVETURFS)
run_delay_heuristics()
timer = TICK_USAGE_REAL
process_turfs(resumed)
cost_turfs = MC_AVERAGE(cost_turfs, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
if(state != SS_RUNNING)
return
resumed = 0
/*
// Monstermos and/or Putnamos--making large pressure deltas move faster
if(currentpart == SSAIR_EQUALIZE)
timer = TICK_USAGE_REAL
process_turf_equalize(resumed)
cost_equalize = MC_AVERAGE(cost_equalize, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_EXCITEDGROUPS
// Making small pressure deltas equalize immediately so they don't process anymore
if(currentpart == SSAIR_EXCITEDGROUPS)
timer = TICK_USAGE_REAL
process_excited_groups(resumed)
cost_groups = MC_AVERAGE(cost_groups, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_TURF_POST_PROCESS
// Quick multithreaded "should we display/react?" checks followed by finishing those up before the next step
if(currentpart == SSAIR_TURF_POST_PROCESS)
timer = TICK_USAGE_REAL
post_process_turfs(resumed)
cost_post_process = MC_AVERAGE(cost_post_process, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_HOTSPOTS
*/
currentpart = SSAIR_REBUILD_PIPENETS
currentpart = SSAIR_REBUILD_PIPENETS
/datum/controller/subsystem/air/proc/process_pipenets(resumed = 0)
if (!resumed)
@@ -293,32 +244,6 @@ SUBSYSTEM_DEF(air)
if(istype(atmos_machine, /obj/machinery/atmospherics))
pipenets_needing_rebuilt += atmos_machine
/datum/controller/subsystem/air/proc/process_deferred_airs(resumed = 0)
cur_deferred_airs = deferred_airs.len
max_deferred_airs = max(cur_deferred_airs,max_deferred_airs)
while(deferred_airs.len)
var/list/cur_op = deferred_airs[deferred_airs.len]
deferred_airs.len--
var/datum/gas_mixture/air1
var/datum/gas_mixture/air2
if(isopenturf(cur_op[1]))
var/turf/open/T = cur_op[1]
air1 = T.return_air()
else
air1 = cur_op[1]
if(isopenturf(cur_op[2]))
var/turf/open/T = cur_op[2]
air2 = T.return_air()
else
air2 = cur_op[2]
if(istype(cur_op[3], /datum/callback))
var/datum/callback/cb = cur_op[3]
cb.Invoke(air1, air2)
else
air1.transfer_ratio_to(air2, cur_op[3])
if(MC_TICK_CHECK)
return
/datum/controller/subsystem/air/proc/process_atmos_machinery(resumed = 0)
var/seconds = wait * 0.1
if (!resumed)
@@ -333,22 +258,6 @@ SUBSYSTEM_DEF(air)
if(MC_TICK_CHECK)
return
/datum/controller/subsystem/air/proc/process_atmos_air_machinery(resumed = 0)
var/seconds = wait * 0.1
if (!resumed)
src.currentrun = atmos_air_machinery.Copy()
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
while(currentrun.len)
var/obj/machinery/M = currentrun[currentrun.len]
currentrun.len--
if(!M || (M.process_atmos(seconds) == PROCESS_KILL))
atmos_air_machinery.Remove(M)
if(MC_TICK_CHECK)
return
/datum/controller/subsystem/air/proc/process_turf_heat()
/datum/controller/subsystem/air/proc/process_hotspots(resumed = 0)
if (!resumed)
src.currentrun = hotspots.Copy()
@@ -376,78 +285,31 @@ SUBSYSTEM_DEF(air)
return
/datum/controller/subsystem/air/proc/process_turf_equalize(resumed = 0)
if(process_turf_equalize_auxtools(resumed,TICK_REMAINING_MS))
if(process_turf_equalize_auxtools(TICK_REMAINING_MS))
pause()
/*
//cache for sanic speed
var/fire_count = times_fired
if (!resumed)
src.currentrun = active_turfs.Copy()
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
while(currentrun.len)
var/turf/open/T = currentrun[currentrun.len]
currentrun.len--
if (T)
T.equalize_pressure_in_zone(fire_count)
//equalize_pressure_in_zone(T, fire_count)
if (MC_TICK_CHECK)
return
*/
/datum/controller/subsystem/air/proc/run_delay_heuristics()
if(should_do_equalization)
if(!equalize_enabled)
cost_equalize = 0
if(should_do_equalization)
eq_cooldown--
if(eq_cooldown <= 0)
equalize_enabled = TRUE
else
equalize_enabled = FALSE
var/total_thread_time = cost_turfs + cost_equalize + cost_groups + cost_post_process
if(total_thread_time)
var/wait_ms = wait * 100
var/delay_threshold = 1-(total_thread_time/wait_ms + cur_deferred_airs / 50)
share_max_steps = max(1,round(share_max_steps_target * delay_threshold, 1))
eq_cooldown += (1-delay_threshold) * (cost_equalize / total_thread_time) * 2
if(eq_cooldown > 0.5)
equalize_enabled = FALSE
excited_group_pressure_goal = max(0,excited_group_pressure_goal_target * delay_threshold)
/datum/controller/subsystem/air/proc/process_turfs(resumed = 0)
if(process_turfs_auxtools(resumed,TICK_REMAINING_MS))
if(process_turfs_auxtools(TICK_REMAINING_MS))
pause()
/*
//cache for sanic speed
var/fire_count = times_fired
if (!resumed)
src.currentrun = active_turfs.Copy()
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
while(currentrun.len)
var/turf/open/T = currentrun[currentrun.len]
currentrun.len--
if (T)
T.process_cell(fire_count)
if (MC_TICK_CHECK)
return
*/
/datum/controller/subsystem/air/proc/process_excited_groups(resumed = 0)
if(process_excited_groups_auxtools(resumed,TICK_REMAINING_MS))
if(process_excited_groups_auxtools(TICK_REMAINING_MS))
pause()
/datum/controller/subsystem/air/proc/finish_turf_processing(resumed = 0)
if(finish_turf_processing_auxtools(TICK_REMAINING_MS) || thread_running())
if(finish_turf_processing_auxtools(TICK_REMAINING_MS))
pause()
/datum/controller/subsystem/air/proc/equalize_turfs(resumed = 0)
if(equalize_turfs_auxtools(TICK_REMAINING_MS))
pause()
/datum/controller/subsystem/air/proc/post_process_turfs(resumed = 0)
if(post_process_turfs_auxtools(resumed,TICK_REMAINING_MS))
if(post_process_turfs_auxtools(TICK_REMAINING_MS))
pause()
/datum/controller/subsystem/air/proc/finish_turf_processing_auxtools()
/datum/controller/subsystem/air/proc/equalize_turfs_auxtools()
/datum/controller/subsystem/air/proc/process_turfs_auxtools()
/datum/controller/subsystem/air/proc/post_process_turfs_auxtools()
/datum/controller/subsystem/air/proc/process_turf_equalize_auxtools()
@@ -456,6 +318,7 @@ SUBSYSTEM_DEF(air)
/datum/controller/subsystem/air/proc/get_max_gas_mixes()
/datum/controller/subsystem/air/proc/turf_process_time()
/datum/controller/subsystem/air/proc/heat_process_time()
/datum/controller/subsystem/air/proc/process_turf_heat()
/datum/controller/subsystem/air/StartLoadingMap()
map_loading = TRUE
@@ -478,7 +341,7 @@ SUBSYSTEM_DEF(air)
CHECK_TICK
/datum/controller/subsystem/air/proc/setup_atmos_machinery()
for (var/obj/machinery/atmospherics/AM in atmos_machinery + atmos_air_machinery)
for (var/obj/machinery/atmospherics/AM in atmos_machinery)
AM.atmosinit()
CHECK_TICK
@@ -486,7 +349,7 @@ SUBSYSTEM_DEF(air)
// all atmos machinery has to initalize before the first
// pipenet can be built.
/datum/controller/subsystem/air/proc/setup_pipenets()
for (var/obj/machinery/atmospherics/AM in atmos_machinery + atmos_air_machinery)
for (var/obj/machinery/atmospherics/AM in atmos_machinery)
AM.build_network()
CHECK_TICK