Moves assert_gas() into a define it should always have been, speeding up atmos slightly
This commit is contained in:
committed by
CitadelStationBot
parent
5f4b3594d0
commit
4f32b7a0d4
@@ -21,10 +21,6 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
||||
cached_gas[ARCHIVE] = 0
|
||||
cached_gas[GAS_META] = GLOB.meta_gas_info[id]
|
||||
|
||||
#define GASLIST(id, out_list)\
|
||||
var/list/tmp_gaslist = GLOB.gaslist_cache[id];\
|
||||
out_list = tmp_gaslist.Copy();
|
||||
|
||||
/datum/gas_mixture
|
||||
var/list/gases
|
||||
var/temperature //kelvins
|
||||
@@ -43,30 +39,18 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
||||
|
||||
//listmos procs
|
||||
|
||||
//assert_gas(gas_id) - used to guarantee that the gas list for this id exists.
|
||||
//Must be used before adding to a gas. May be used before reading from a gas.
|
||||
/datum/gas_mixture/proc/assert_gas(gas_id)
|
||||
var/cached_gases = gases
|
||||
if(cached_gases[gas_id])
|
||||
return
|
||||
GASLIST(gas_id, cached_gases[gas_id])
|
||||
// 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_gases(args) - shorthand for calling assert_gas() once for each gas type.
|
||||
//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)
|
||||
|
||||
//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)
|
||||
GASLIST(gas_id, gases[gas_id])
|
||||
ASSERT_GAS(id, src)
|
||||
|
||||
//add_gases(args) - shorthand for calling add_gas() once for each gas_type.
|
||||
/datum/gas_mixture/proc/add_gases()
|
||||
var/cached_gases = gases
|
||||
for(var/id in args)
|
||||
GASLIST(id, cached_gases[id])
|
||||
ADD_GAS(id, cached_gases)
|
||||
|
||||
//garbage_collect() - removes any gas list which is empty.
|
||||
//If called with a list as an argument, only removes gas lists with IDs from that list.
|
||||
@@ -80,6 +64,7 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
||||
cached_gases -= id
|
||||
|
||||
//PV = nRT
|
||||
|
||||
/datum/gas_mixture/proc/heat_capacity() //joules per kelvin
|
||||
var/list/cached_gases = gases
|
||||
. = 0
|
||||
@@ -195,7 +180,7 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
||||
var/list/giver_gases = giver.gases
|
||||
//gas transfer
|
||||
for(var/giver_id in giver_gases)
|
||||
assert_gas(giver_id)
|
||||
ASSERT_GAS(giver_id, src)
|
||||
cached_gases[giver_id][MOLES] += giver_gases[giver_id][MOLES]
|
||||
|
||||
return 1
|
||||
@@ -212,7 +197,7 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
||||
|
||||
removed.temperature = temperature
|
||||
for(var/id in cached_gases)
|
||||
removed.add_gas(id)
|
||||
ADD_GAS(id, removed.gases)
|
||||
removed_gases[id][MOLES] = QUANTIZE((cached_gases[id][MOLES] / sum) * amount)
|
||||
cached_gases[id][MOLES] -= removed_gases[id][MOLES]
|
||||
garbage_collect()
|
||||
@@ -230,7 +215,7 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
||||
|
||||
removed.temperature = temperature
|
||||
for(var/id in cached_gases)
|
||||
removed.add_gas(id)
|
||||
ADD_GAS(id, removed.gases)
|
||||
removed_gases[id][MOLES] = QUANTIZE(cached_gases[id][MOLES] * ratio)
|
||||
cached_gases[id][MOLES] -= removed_gases[id][MOLES]
|
||||
|
||||
@@ -245,18 +230,19 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
||||
|
||||
copy.temperature = temperature
|
||||
for(var/id in cached_gases)
|
||||
copy.add_gas(id)
|
||||
ADD_GAS(id, copy.gases)
|
||||
copy_gases[id][MOLES] = cached_gases[id][MOLES]
|
||||
|
||||
return copy
|
||||
|
||||
|
||||
/datum/gas_mixture/copy_from(datum/gas_mixture/sample)
|
||||
var/list/cached_gases = gases //accessing datum vars is slower than proc vars
|
||||
var/list/sample_gases = sample.gases
|
||||
|
||||
temperature = sample.temperature
|
||||
for(var/id in sample_gases)
|
||||
assert_gas(id)
|
||||
ASSERT_GAS(id,src)
|
||||
cached_gases[id][MOLES] = sample_gases[id][MOLES]
|
||||
|
||||
//remove all gases not in the sample
|
||||
@@ -282,7 +268,7 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
||||
gas -= "TEMP"
|
||||
gases.Cut()
|
||||
for(var/id in gas)
|
||||
add_gas(id)
|
||||
ADD_GAS(id, gases)
|
||||
gases[id][MOLES] = text2num(gas[id])
|
||||
return 1
|
||||
|
||||
@@ -310,10 +296,9 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
||||
|
||||
//GAS TRANSFER
|
||||
for(var/id in sharer_gases - cached_gases) // create gases not in our cache
|
||||
add_gas(id)
|
||||
ADD_GAS(id, gases)
|
||||
for(var/id in cached_gases) // transfer gases
|
||||
if(!sharer_gases[id]) //checking here prevents an uneeded proc call if the check fails.
|
||||
sharer.add_gas(id)
|
||||
ASSERT_GAS(id, sharer)
|
||||
|
||||
var/gas = cached_gases[id]
|
||||
var/sharergas = sharer_gases[id]
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
|
||||
/datum/gas_mixture/immutable/cloner/garbage_collect()
|
||||
..()
|
||||
add_gas("n2")
|
||||
ADD_GAS("n2", gases)
|
||||
gases["n2"][MOLES] = MOLES_O2STANDARD + MOLES_N2STANDARD
|
||||
|
||||
/datum/gas_mixture/immutable/cloner/heat_capacity()
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
cached_gases["co2"][MOLES] -= reaction_rate
|
||||
cached_gases["agent_b"][MOLES] -= reaction_rate*0.05
|
||||
|
||||
air.assert_gas("o2") //only need to assert oxygen, as this reaction doesn't occur without the other gases existing
|
||||
ASSERT_GAS("o2", air) //only need to assert oxygen, as this reaction doesn't occur without the other gases existing
|
||||
cached_gases["o2"][MOLES] += reaction_rate
|
||||
|
||||
air.temperature -= (reaction_rate*20000)/air.heat_capacity()
|
||||
@@ -126,7 +126,7 @@
|
||||
if(burned_fuel)
|
||||
energy_released += FIRE_CARBON_ENERGY_RELEASED * burned_fuel
|
||||
|
||||
air.assert_gas("co2")
|
||||
ASSERT_GAS("co2", air)
|
||||
cached_gases["co2"][MOLES] += burned_fuel
|
||||
|
||||
cached_results[id] += burned_fuel
|
||||
@@ -142,14 +142,14 @@
|
||||
else
|
||||
temperature_scale = (temperature-PLASMA_MINIMUM_BURN_TEMPERATURE)/(PLASMA_UPPER_TEMPERATURE-PLASMA_MINIMUM_BURN_TEMPERATURE)
|
||||
if(temperature_scale > 0)
|
||||
air.assert_gas("o2")
|
||||
ASSERT_GAS("o2", air)
|
||||
oxygen_burn_rate = OXYGEN_BURN_RATE_BASE - temperature_scale
|
||||
if(cached_gases["o2"][MOLES] > cached_gases["plasma"][MOLES]*PLASMA_OXYGEN_FULLBURN)
|
||||
plasma_burn_rate = (cached_gases["plasma"][MOLES]*temperature_scale)/PLASMA_BURN_RATE_DELTA
|
||||
else
|
||||
plasma_burn_rate = (temperature_scale*(cached_gases["o2"][MOLES]/PLASMA_OXYGEN_FULLBURN))/PLASMA_BURN_RATE_DELTA
|
||||
if(plasma_burn_rate > MINIMUM_HEAT_CAPACITY)
|
||||
air.assert_gas("co2")
|
||||
ASSERT_GAS("co2", air)
|
||||
cached_gases["plasma"][MOLES] = QUANTIZE(cached_gases["plasma"][MOLES] - plasma_burn_rate)
|
||||
cached_gases["o2"][MOLES] = QUANTIZE(cached_gases["o2"][MOLES] - (plasma_burn_rate * oxygen_burn_rate))
|
||||
cached_gases["co2"][MOLES] += plasma_burn_rate
|
||||
|
||||
Reference in New Issue
Block a user