Huge optimizations+some fixes

This commit is contained in:
Putnam
2021-01-19 17:48:20 -08:00
parent a6a91347ff
commit f05df1c7de
21 changed files with 128 additions and 75 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -151,6 +151,7 @@
#define SSAIR_ACTIVETURFS 9
#define SSAIR_TURF_POST_PROCESS 10
#define SSAIR_FINALIZE_TURFS 11
#define SSAIR_ATMOSMACHINERY_AIR 12
// |= on overlays is not actually guaranteed to not add same appearances but we're optimistically using it anyway.
#define COMPILE_OVERLAYS(A)\

View File

@@ -21,6 +21,7 @@ SUBSYSTEM_DEF(air)
var/list/networks = list()
var/list/pipenets_needing_rebuilt = list()
var/list/obj/machinery/atmos_machinery = list()
var/list/obj/machinery/atmos_air_machinery = list()
var/list/pipe_init_dirs_cache = list()
//atmos singletons
@@ -85,16 +86,8 @@ SUBSYSTEM_DEF(air)
/datum/controller/subsystem/air/fire(resumed = 0)
var/timer = TICK_USAGE_REAL
if(currentpart == SSAIR_ACTIVETURFS)
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
currentpart = SSAIR_REBUILD_PIPENETS
if(currentpart == SSAIR_REBUILD_PIPENETS)
timer = TICK_USAGE_REAL
var/list/pipenet_rebuilds = pipenets_needing_rebuilt
for(var/thing in pipenet_rebuilds)
var/obj/machinery/atmospherics/AT = thing
@@ -106,22 +99,17 @@ SUBSYSTEM_DEF(air)
if(state != SS_RUNNING)
return
resumed = FALSE
currentpart = SSAIR_ACTIVETURFS
currentpart = SSAIR_PIPENETS
if(currentpart == SSAIR_PIPENETS || !resumed)
timer = TICK_USAGE_REAL
process_pipenets(resumed)
cost_pipenets = MC_AVERAGE(cost_pipenets, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_FINALIZE_TURFS
if(currentpart == SSAIR_FINALIZE_TURFS)
if(finish_turf_processing(MC_TICK_REMAINING_MS))
pause()
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_ATMOSMACHINERY
if(currentpart == SSAIR_ATMOSMACHINERY)
timer = TICK_USAGE_REAL
process_atmos_machinery(resumed)
@@ -129,6 +117,31 @@ SUBSYSTEM_DEF(air)
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_HIGHPRESSURE
if(currentpart == SSAIR_HIGHPRESSURE)
timer = TICK_USAGE_REAL
process_high_pressure_delta(resumed)
cost_highpressure = MC_AVERAGE(cost_highpressure, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
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 = 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 = equalize_enabled ? SSAIR_EQUALIZE : SSAIR_EXCITEDGROUPS
if(currentpart == SSAIR_EQUALIZE)
@@ -151,21 +164,11 @@ SUBSYSTEM_DEF(air)
if(currentpart == SSAIR_TURF_POST_PROCESS)
timer = TICK_USAGE_REAL
if(post_process_turfs(resumed,MC_TICK_REMAINING_MS))
pause()
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_HIGHPRESSURE
if(currentpart == SSAIR_HIGHPRESSURE)
timer = TICK_USAGE_REAL
process_high_pressure_delta(resumed)
cost_highpressure = MC_AVERAGE(cost_highpressure, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
if(state != SS_RUNNING)
return
resumed = 0
currentpart = SSAIR_HOTSPOTS
if(currentpart == SSAIR_HOTSPOTS)
@@ -175,8 +178,7 @@ SUBSYSTEM_DEF(air)
if(state != SS_RUNNING)
return
resumed = 0
if(heat_enabled)
currentpart = SSAIR_TURF_CONDUCTION
currentpart = heat_enabled ? SSAIR_TURF_CONDUCTION : SSAIR_ACTIVETURFS
if(currentpart == SSAIR_TURF_CONDUCTION)
timer = TICK_USAGE_REAL
@@ -188,6 +190,15 @@ SUBSYSTEM_DEF(air)
resumed = 0
currentpart = SSAIR_ACTIVETURFS
if(currentpart == SSAIR_ACTIVETURFS)
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
currentpart = SSAIR_REBUILD_PIPENETS
/datum/controller/subsystem/air/proc/process_pipenets(resumed = 0)
if (!resumed)
src.currentrun = networks.Copy()
@@ -221,6 +232,20 @@ 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)
@@ -250,7 +275,7 @@ SUBSYSTEM_DEF(air)
return
/datum/controller/subsystem/air/proc/process_turf_equalize(resumed = 0)
if(process_turf_equalize_extools(resumed,MC_TICK_REMAINING_MS))
if(process_turf_equalize_auxtools(resumed,MC_TICK_REMAINING_MS))
pause()
/*
//cache for sanic speed
@@ -270,7 +295,7 @@ SUBSYSTEM_DEF(air)
*/
/datum/controller/subsystem/air/proc/process_turfs(resumed = 0)
if(process_turfs_extools(resumed,MC_TICK_REMAINING_MS))
if(process_turfs_auxtools(resumed,MC_TICK_REMAINING_MS))
pause()
/*
//cache for sanic speed
@@ -289,14 +314,22 @@ SUBSYSTEM_DEF(air)
*/
/datum/controller/subsystem/air/proc/process_excited_groups(resumed = 0)
if(process_excited_groups_extools(resumed,MC_TICK_REMAINING_MS))
if(process_excited_groups_auxtools(resumed,MC_TICK_REMAINING_MS))
pause()
/datum/controller/subsystem/air/proc/finish_turf_processing()
/datum/controller/subsystem/air/proc/process_turfs_extools()
/datum/controller/subsystem/air/proc/post_process_turfs()
/datum/controller/subsystem/air/proc/process_turf_equalize_extools()
/datum/controller/subsystem/air/proc/process_excited_groups_extools()
/datum/controller/subsystem/air/proc/finish_turf_processing(resumed = 0)
if(finish_turf_processing_auxtools(MC_TICK_REMAINING_MS))
pause()
/datum/controller/subsystem/air/proc/post_process_turfs(resumed = 0)
if(post_process_turfs_auxtools(resumed,MC_TICK_REMAINING_MS))
pause()
/datum/controller/subsystem/air/proc/finish_turf_processing_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()
/datum/controller/subsystem/air/proc/process_excited_groups_auxtools()
/datum/controller/subsystem/air/proc/get_amt_gas_mixes()
/datum/controller/subsystem/air/proc/get_max_gas_mixes()
/datum/controller/subsystem/air/proc/turf_process_time()
@@ -323,7 +356,7 @@ SUBSYSTEM_DEF(air)
CHECK_TICK
/datum/controller/subsystem/air/proc/setup_atmos_machinery()
for (var/obj/machinery/atmospherics/AM in atmos_machinery)
for (var/obj/machinery/atmospherics/AM in atmos_machinery + atmos_air_machinery)
AM.atmosinit()
CHECK_TICK
@@ -331,7 +364,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)
for (var/obj/machinery/atmospherics/AM in atmos_machinery + atmos_air_machinery)
AM.build_network()
CHECK_TICK
@@ -359,12 +392,15 @@ SUBSYSTEM_DEF(air)
return pipe_init_dirs_cache[type]["[dir]"]
/proc/get_extools_benchmarks()
#undef SSAIR_PIPENETS
#undef SSAIR_ATMOSMACHINERY
#undef SSAIR_ACTIVETURFS
#undef SSAIR_EXCITEDGROUPS
#undef SSAIR_HIGHPRESSURE
#undef SSAIR_HOTSPOTS
#undef SSAIR_TURF_CONDUCTION
#undef SSAIR_REBUILD_PIPENETS
#undef SSAIR_EQUALIZE
#undef SSAIR_ACTIVETURFS
#undef SSAIR_TURF_POST_PROCESS
#undef SSAIR_FINALIZE_TURFS
#undef SSAIR_ATMOSMACHINERY_AIR

View File

@@ -720,6 +720,8 @@ SUBSYSTEM_DEF(shuttle)
preview_shuttle.register()
preview_shuttle.reset_air()
// TODO indicate to the user that success happened, rather than just
// blanking the modification tab
preview_shuttle = null

View File

@@ -72,11 +72,11 @@
/obj/machinery/air_sensor/Initialize()
. = ..()
SSair.atmos_machinery += src
SSair.atmos_air_machinery += src
set_frequency(frequency)
/obj/machinery/air_sensor/Destroy()
SSair.atmos_machinery -= src
SSair.atmos_air_machinery -= src
SSradio.remove_object(src, frequency)
return ..()

View File

@@ -58,10 +58,11 @@
if (T.atmos_adjacent_turfs)
T.atmos_adjacent_turfs -= src
UNSETEMPTY(T.atmos_adjacent_turfs)
T.set_sleeping(!length(T.atmos_adjacent_turfs))
T.__update_auxtools_turf_adjacency_info(isspaceturf(T.get_z_base_turf()), -1)
UNSETEMPTY(atmos_adjacent_turfs)
src.atmos_adjacent_turfs = atmos_adjacent_turfs
set_sleeping(!(canpass || canvpass))
set_sleeping(!length(atmos_adjacent_turfs))
__update_auxtools_turf_adjacency_info(isspaceturf(get_z_base_turf()))
/turf/proc/set_sleeping(should_sleep)

View File

@@ -218,6 +218,18 @@ GLOBAL_LIST_INIT(auxtools_atmos_initialized,FALSE)
//Performs various reactions such as combustion or fusion (LOL)
//Returns: 1 if any reaction took place; 0 otherwise
/datum/gas_mixture/proc/adjust_heat(amt)
//Adjusts the thermal energy of the gas mixture, rather than having to do the full calculation.
//Returns: null
/datum/gas_mixture/proc/equalize_with(datum/gas_mixture/giver)
//Makes this mix have the same temperature and gas ratios as the giver, but with the same pressure, accounting for volume.
//Returns: null
/proc/equalize_all_gases_in_list(list/L)
//Makes every gas in the given list have the same pressure, temperature and gas proportions.
//Returns: null
/datum/gas_mixture/proc/__remove()
/datum/gas_mixture/remove(amount)
var/datum/gas_mixture/removed = new type

View File

@@ -39,6 +39,7 @@
var/construction_type
var/pipe_state //icon_state as a pipe item
var/on = FALSE
var/interacts_with_air = FALSE
/obj/machinery/atmospherics/examine(mob/user)
. = ..()
@@ -57,6 +58,9 @@
armor = list("melee" = 25, "bullet" = 10, "laser" = 10, "energy" = 100, "bomb" = 0, "bio" = 100, "rad" = 100, "fire" = 100, "acid" = 70)
..()
if(process)
if(interacts_with_air)
SSair.atmos_air_machinery += src
else
SSair.atmos_machinery += src
SetInitDirections()
@@ -65,6 +69,7 @@
nullifyNode(i)
SSair.atmos_machinery -= src
SSair.atmos_air_machinery -= src
SSair.pipenets_needing_rebuilt -= src
dropContents()

View File

@@ -15,6 +15,9 @@
desc = "Has a valve and pump attached to it. There are two ports."
level = 1
interacts_with_air = TRUE
var/frequency = 0
var/id = null
var/datum/radio_frequency/radio_connection

View File

@@ -16,6 +16,7 @@
var/datum/radio_frequency/radio_connection
level = 1
interacts_with_air = TRUE
layer = GAS_SCRUBBER_LAYER
pipe_state = "injector"

View File

@@ -6,6 +6,7 @@
can_unwrench = TRUE
level = 1
interacts_with_air = TRUE
layer = GAS_SCRUBBER_LAYER
pipe_state = "pvent"

View File

@@ -5,6 +5,7 @@
icon_state = "relief_valve-e-map"
can_unwrench = TRUE
interaction_flags_machine = INTERACT_MACHINE_OFFLINE | INTERACT_MACHINE_WIRES_IF_OPEN | INTERACT_MACHINE_ALLOW_SILICON | INTERACT_MACHINE_OPEN_SILICON | INTERACT_MACHINE_SET_MACHINE
interacts_with_air = TRUE
var/opened = FALSE
var/open_pressure = ONE_ATMOSPHERE * 3
var/close_pressure = ONE_ATMOSPHERE

View File

@@ -15,6 +15,8 @@
level = 1
layer = GAS_SCRUBBER_LAYER
interacts_with_air = TRUE
var/id_tag = null
var/pump_direction = RELEASING

View File

@@ -13,6 +13,8 @@
level = 1
layer = GAS_SCRUBBER_LAYER
interacts_with_air = TRUE
var/id_tag = null
var/scrubbing = SCRUBBING //0 = siphoning, 1 = scrubbing

View File

@@ -241,26 +241,4 @@
/datum/pipeline/proc/reconcile_air()
var/list/datum/gas_mixture/GL = get_all_connected_airs()
var/total_thermal_energy = 0
var/total_heat_capacity = 0
var/datum/gas_mixture/total_gas_mixture = new(0)
for(var/i in GL)
var/datum/gas_mixture/G = i
total_gas_mixture.set_volume(total_gas_mixture.return_volume() + G.return_volume())
total_gas_mixture.merge(G)
total_thermal_energy += G.thermal_energy()
total_heat_capacity += G.heat_capacity()
if(total_heat_capacity)
total_gas_mixture.set_temperature(total_thermal_energy/total_heat_capacity)
if(total_gas_mixture.return_volume() > 0)
//Update individual gas_mixtures by volume ratio
for(var/i in GL)
var/datum/gas_mixture/G = i
G.copy_from(total_gas_mixture)
G.multiply(G.return_volume()/total_gas_mixture.return_volume())
equalize_all_gases_in_list(GL)

View File

@@ -12,6 +12,7 @@
icon_state = "miner"
density = FALSE
resistance_flags = INDESTRUCTIBLE|ACID_PROOF|FIRE_PROOF
interacts_with_air = TRUE
var/spawn_id = null
var/spawn_temp = T20C
var/spawn_mol = MOLES_CELLSTANDARD * 10

View File

@@ -6,6 +6,7 @@
buckle_lying = 1
var/icon_temperature = T20C //stop small changes in temperature causing icon refresh
resistance_flags = LAVA_PROOF | FIRE_PROOF
interacts_with_air = TRUE
/obj/machinery/atmospherics/pipe/heat_exchanging/Initialize()
. = ..()

View File

@@ -16,7 +16,7 @@
/obj/machinery/portable_atmospherics/New()
..()
SSair.atmos_machinery += src
SSair.atmos_air_machinery += src
air_contents = new(volume)
air_contents.set_temperature(T20C)
@@ -24,7 +24,7 @@
return 1
/obj/machinery/portable_atmospherics/Destroy()
SSair.atmos_machinery -= src
SSair.atmos_air_machinery -= src
disconnect()
qdel(air_contents)

View File

@@ -283,7 +283,7 @@ GLOBAL_DATUM(main_supermatter_engine, /obj/machinery/power/supermatter_crystal)
/obj/machinery/power/supermatter_crystal/Initialize()
. = ..()
uid = gl_uid++
SSair.atmos_machinery += src
SSair.atmos_air_machinery += src
countdown = new(src)
countdown.start()
GLOB.poi_list |= src
@@ -302,7 +302,7 @@ GLOBAL_DATUM(main_supermatter_engine, /obj/machinery/power/supermatter_crystal)
/obj/machinery/power/supermatter_crystal/Destroy()
investigate_log("has been destroyed.", INVESTIGATE_SUPERMATTER)
SSair.atmos_machinery -= src
SSair.atmos_air_machinery -= src
QDEL_NULL(radio)
GLOB.poi_list -= src
QDEL_NULL(countdown)

View File

@@ -205,3 +205,9 @@
var/turf/oldT = moved_atoms[moved_object]
moved_object.lateShuttleMove(oldT, movement_force, movement_direction)
/obj/docking_port/mobile/proc/reset_air()
var/list/turfs = return_ordered_turfs(x, y, z, dir)
for(var/i in 1 to length(turfs))
var/turf/open/T = turfs[i]
if(istype(T))
T.air.copy_from_turf(T)