diff --git a/code/__DEFINES/atmospherics.dm b/code/__DEFINES/atmospherics.dm index 9ed2306ecbd5..430f7f29b307 100644 --- a/code/__DEFINES/atmospherics.dm +++ b/code/__DEFINES/atmospherics.dm @@ -176,6 +176,4 @@ #define ADD_GAS(gas_id, out_list)\ var/list/tmp_gaslist = GLOB.gaslist_cache[gas_id]; out_list[gas_id] = tmp_gaslist.Copy(); -//ASSERT_GAS(gas_id, gas_mixture) - used to guarantee that the gas list for this id exists in gas_mixture.gases. -//Must be used before adding to a gas. May be used before reading from a gas. #define ASSERT_GAS(gas_id, gas_mixture) if (!gas_mixture.gases[gas_id]) { ADD_GAS(gas_id, gas_mixture.gases) }; diff --git a/code/game/mecha/equipment/tools/other_tools.dm b/code/game/mecha/equipment/tools/other_tools.dm index 8951a0dbd5d2..385d11254299 100644 --- a/code/game/mecha/equipment/tools/other_tools.dm +++ b/code/game/mecha/equipment/tools/other_tools.dm @@ -422,7 +422,7 @@ if(!istype(T)) return var/datum/gas_mixture/GM = new - ADD_GAS(/datum/gas/plasma, GM.gases) + GM.add_gas(/datum/gas/plasma) if(prob(10)) GM.gases[/datum/gas/plasma][MOLES] += 100 GM.temperature = 1500+T0C //should be enough to start a fire diff --git a/code/game/objects/effects/effect_system/effects_smoke.dm b/code/game/objects/effects/effect_system/effects_smoke.dm index 3de8432ee9c7..4dc985c9a122 100644 --- a/code/game/objects/effects/effect_system/effects_smoke.dm +++ b/code/game/objects/effects/effect_system/effects_smoke.dm @@ -169,7 +169,7 @@ qdel(H) var/list/G_gases = G.gases if(G_gases[/datum/gas/plasma]) - ASSERT_GAS(/datum/gas/nitrogen, G) + G.assert_gas(/datum/gas/nitrogen) G_gases[/datum/gas/nitrogen][MOLES] += (G_gases[/datum/gas/plasma][MOLES]) G_gases[/datum/gas/plasma][MOLES] = 0 G.garbage_collect() diff --git a/code/game/objects/items/tanks/jetpack.dm b/code/game/objects/items/tanks/jetpack.dm index f1644f0b1acd..6466696b9890 100644 --- a/code/game/objects/items/tanks/jetpack.dm +++ b/code/game/objects/items/tanks/jetpack.dm @@ -17,7 +17,7 @@ /obj/item/tank/jetpack/New() ..() if(gas_type) - ASSERT_GAS(gas_type,air_contents) + air_contents.assert_gas(gas_type) air_contents.gases[gas_type][MOLES] = (6 * ONE_ATMOSPHERE) * volume / (R_IDEAL_GAS_EQUATION * T20C) ion_trail = new diff --git a/code/game/objects/items/tanks/tank_types.dm b/code/game/objects/items/tanks/tank_types.dm index 7a1fa569a36d..4a687b458d18 100644 --- a/code/game/objects/items/tanks/tank_types.dm +++ b/code/game/objects/items/tanks/tank_types.dm @@ -21,7 +21,7 @@ /obj/item/tank/internals/oxygen/New() ..() - ASSERT_GAS(/datum/gas/oxygen, air_contents) + air_contents.assert_gas(/datum/gas/oxygen) air_contents.gases[/datum/gas/oxygen][MOLES] = (6*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C) return @@ -87,7 +87,7 @@ /obj/item/tank/internals/plasma/New() ..() - ASSERT_GAS(/datum/gas/plasma, air_contents) + air_contents.assert_gas(/datum/gas/plasma) air_contents.gases[/datum/gas/plasma][MOLES] = (3*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C) return @@ -124,7 +124,7 @@ /obj/item/tank/internals/plasmaman/New() ..() - ASSERT_GAS(/datum/gas/plasma, air_contents) + air_contents.assert_gas(/datum/gas/plasma) air_contents.gases[/datum/gas/plasma][MOLES] = (3*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C) return @@ -166,7 +166,7 @@ /obj/item/tank/internals/emergency_oxygen/New() ..() - ASSERT_GAS(/datum/gas/oxygen, air_contents) + air_contents.assert_gas(/datum/gas/oxygen) air_contents.gases[/datum/gas/oxygen][MOLES] = (3*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C) return diff --git a/code/game/turfs/open.dm b/code/game/turfs/open.dm index 5d83d677dede..0eddbc411e8d 100644 --- a/code/game/turfs/open.dm +++ b/code/game/turfs/open.dm @@ -355,6 +355,6 @@ if (air.gases[/datum/gas/carbon_dioxide] && air.gases[/datum/gas/oxygen]) air.gases[/datum/gas/carbon_dioxide][MOLES]=max(air.gases[/datum/gas/carbon_dioxide][MOLES]-(pulse_strength/1000),0) air.gases[/datum/gas/oxygen][MOLES]=max(air.gases[/datum/gas/oxygen][MOLES]-(pulse_strength/2000),0) - ASSERT_GAS(/datum/gas/pluoxium,air) + air.assert_gas(/datum/gas/pluoxium) air.gases[/datum/gas/pluoxium][MOLES]+=(pulse_strength/4000) - air.garbage_collect() \ No newline at end of file + air.garbage_collect() diff --git a/code/modules/admin/verbs/debug.dm b/code/modules/admin/verbs/debug.dm index 6f16a816df44..357e69101aab 100644 --- a/code/modules/admin/verbs/debug.dm +++ b/code/modules/admin/verbs/debug.dm @@ -735,7 +735,7 @@ GLOBAL_PROTECT(LastAdminCalledProc) if(Rad.anchored) if(!Rad.loaded_tank) var/obj/item/tank/internals/plasma/Plasma = new/obj/item/tank/internals/plasma(Rad) - ASSERT_GAS(/datum/gas/plasma, Plasma.air_contents) + Plasma.air_contents.assert_gas(/datum/gas/plasma) Plasma.air_contents.gases[/datum/gas/plasma][MOLES] = 70 Rad.drainratio = 0 Rad.loaded_tank = Plasma diff --git a/code/modules/atmospherics/gasmixtures/gas_mixture.dm b/code/modules/atmospherics/gasmixtures/gas_mixture.dm index 2ebf5bd7d556..dd6e4ffe7123 100644 --- a/code/modules/atmospherics/gasmixtures/gas_mixture.dm +++ b/code/modules/atmospherics/gasmixtures/gas_mixture.dm @@ -37,14 +37,24 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache()) reaction_results = new //listmos procs +//use the macros in performance intensive areas. for their definitions, refer to code/__DEFINES/atmospherics.dm -// The following procs used to live here: thermal_energy(), assert_gas() and add_gas(). They have been moved into defines in code/__DEFINES/atmospherics.dm + //assert_gas(gas_id) - used to guarantee that the gas list for this id exists in gas_mixture.gases. + //Must be used before adding to a gas. May be used before reading from a gas. +/datum/gas_mixture/proc/assert_gas(gas_id) + ASSERT_GAS(gas_id, src) //assert_gases(args) - shorthand for calling ASSERT_GAS() once for each gas type. /datum/gas_mixture/proc/assert_gases() for(var/id in args) ASSERT_GAS(id, src) + //add_gas(gas_id) - similar to assert_gas(), but does not check for an existing + //gas list for this id. This can clobber existing gases. + //Used instead of assert_gas() when you know the gas does not exist. Faster than assert_gas(). +/datum/gas_mixture/proc/add_gas(gas_id) + ADD_GAS(gas_id, gases) + //add_gases(args) - shorthand for calling add_gas() once for each gas_type. /datum/gas_mixture/proc/add_gases() var/cached_gases = gases @@ -101,6 +111,9 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache()) /datum/gas_mixture/proc/return_volume() //liters return max(0, volume) +/datum/gas_mixture/proc/thermal_energy() //joules + return THERMAL_ENERGY(src) //see code/__DEFINES/atmospherics.dm; use the define in performance critical areas + /datum/gas_mixture/proc/archive() //Update archived versions of variables //Returns: 1 in all cases diff --git a/code/modules/atmospherics/machinery/components/trinary_devices/filter.dm b/code/modules/atmospherics/machinery/components/trinary_devices/filter.dm index f0840f31f60c..5281c3bad79a 100644 --- a/code/modules/atmospherics/machinery/components/trinary_devices/filter.dm +++ b/code/modules/atmospherics/machinery/components/trinary_devices/filter.dm @@ -103,7 +103,7 @@ var/datum/gas_mixture/filtered_out = new filtered_out.temperature = removed.temperature - ASSERT_GAS(filter_type, filtered_out) + filtered_out.add_gas(filter_type) filtered_out.gases[filter_type][MOLES] = removed.gases[filter_type][MOLES] removed.gases[filter_type][MOLES] = 0 diff --git a/code/modules/atmospherics/machinery/components/unary_devices/tank.dm b/code/modules/atmospherics/machinery/components/unary_devices/tank.dm index cf93f943909d..b12eb594426c 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/tank.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/tank.dm @@ -17,7 +17,7 @@ air_contents.volume = volume air_contents.temperature = T20C if(gas_type) - ASSERT_GAS(gas_type, air_contents) + air_contents.assert_gas(gas_type) air_contents.gases[gas_type][MOLES] = AIR_CONTENTS name = "[name] ([air_contents.gases[gas_type][GAS_META][META_GAS_NAME]])" diff --git a/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm b/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm index e1293ab01b56..2b9d6cc7e5c7 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/vent_scrubber.dm @@ -175,7 +175,7 @@ filtered_out.temperature = removed.temperature for(var/gas in filter_types & removed_gases) - ADD_GAS(gas, filtered_gases) + filtered_out.add_gas(gas) filtered_gases[gas][MOLES] = removed_gases[gas][MOLES] removed_gases[gas][MOLES] = 0 diff --git a/code/modules/atmospherics/machinery/other/miner.dm b/code/modules/atmospherics/machinery/other/miner.dm index cb28f178020a..f63065b431c4 100644 --- a/code/modules/atmospherics/machinery/other/miner.dm +++ b/code/modules/atmospherics/machinery/other/miner.dm @@ -132,7 +132,7 @@ if(!isopenturf(O)) return FALSE var/datum/gas_mixture/merger = new - ASSERT_GAS(spawn_id, merger) + merger.assert_gas(spawn_id) merger.gases[spawn_id][MOLES] = (spawn_mol) merger.temperature = spawn_temp O.assume_air(merger) diff --git a/code/modules/atmospherics/machinery/portable/canister.dm b/code/modules/atmospherics/machinery/portable/canister.dm index 653f76da30db..08b20f07bba9 100644 --- a/code/modules/atmospherics/machinery/portable/canister.dm +++ b/code/modules/atmospherics/machinery/portable/canister.dm @@ -196,7 +196,7 @@ /obj/machinery/portable_atmospherics/canister/proc/create_gas() if(gas_type) - ADD_GAS(gas_type, air_contents.gases) + air_contents.add_gas(gas_type) if(starter_temp) air_contents.temperature = starter_temp air_contents.gases[gas_type][MOLES] = (maximum_pressure * filled) * air_contents.volume / (R_IDEAL_GAS_EQUATION * air_contents.temperature) diff --git a/code/modules/atmospherics/machinery/portable/scrubber.dm b/code/modules/atmospherics/machinery/portable/scrubber.dm index 3ba7e0a11004..4bb7b022884c 100644 --- a/code/modules/atmospherics/machinery/portable/scrubber.dm +++ b/code/modules/atmospherics/machinery/portable/scrubber.dm @@ -45,7 +45,7 @@ filtered.temperature = filtering.temperature for(var/gas in filtering.gases & scrubbing) - ADD_GAS(gas, filtered.gases) + filtered.add_gas(gas) filtered.gases[gas][MOLES] = filtering.gases[gas][MOLES] // Shuffle the "bad" gasses to the filtered mixture. filtering.gases[gas][MOLES] = 0 filtering.garbage_collect() // Now that the gasses are set to 0, clean up the mixture. diff --git a/code/modules/power/singularity/collector.dm b/code/modules/power/singularity/collector.dm index 36dd615e8617..a5e9db1fdef7 100644 --- a/code/modules/power/singularity/collector.dm +++ b/code/modules/power/singularity/collector.dm @@ -37,7 +37,7 @@ eject() else loaded_tank.air_contents.gases[/datum/gas/plasma][MOLES] -= 0.001*drainratio - ASSERT_GAS(/datum/gas/tritium,loaded_tank.air_contents) + loaded_tank.air_contents.assert_gas(/datum/gas/tritium) loaded_tank.air_contents.gases[/datum/gas/tritium][MOLES] += 0.001*drainratio loaded_tank.air_contents.garbage_collect()