Merge pull request #8911 from Ghommie/Ghommie-cit145

Porting a couple atmos performance code improvements.
This commit is contained in:
kevinz000
2019-07-25 17:44:17 -07:00
committed by GitHub
3 changed files with 52 additions and 24 deletions

View File

@@ -38,8 +38,11 @@ GLOBAL_LIST_INIT(meta_gas_fusions, meta_gas_fusion_list())
for(var/id in cached_gases)
. += cached_gases[id] * cached_gasheats[id]
/datum/gas_mixture/turf/heat_capacity()
. = ..()
/datum/gas_mixture/turf/heat_capacity() // Same as above except vacuums return HEAT_CAPACITY_VACUUM
var/list/cached_gases = gases
var/list/cached_gasheats = GLOB.meta_gas_specific_heats
for(var/id in cached_gases)
. += cached_gases[id] * cached_gasheats[id]
if(!.)
. += HEAT_CAPACITY_VACUUM //we want vacuums in turfs to have the same heat capacity as space
@@ -331,22 +334,19 @@ GLOBAL_LIST_INIT(meta_gas_fusions, meta_gas_fusion_list())
/datum/gas_mixture/react(datum/holder)
. = NO_REACTION
var/list/cached_gases = gases
if(!cached_gases.len)
if(!length(cached_gases))
return
var/possible
var/list/reactions = list()
for(var/I in cached_gases)
if(GLOB.nonreactive_gases[I])
continue
possible = TRUE
break
if(!possible)
reactions += SSair.gas_reactions[I]
if(!length(reactions))
return
reaction_results = new
var/temp = temperature
var/ener = THERMAL_ENERGY(src)
reaction_loop:
for(var/r in SSair.gas_reactions)
for(var/r in reactions)
var/datum/gas_reaction/reaction = r
var/list/min_reqs = reaction.min_requirements
@@ -376,14 +376,11 @@ GLOBAL_LIST_INIT(meta_gas_fusions, meta_gas_fusion_list())
continue reaction_loop
//at this point, all requirements for the reaction are satisfied. we can now react()
*/
. |= reaction.react(src, holder)
if (. & STOP_REACTIONS)
break
if(.)
GAS_GARBAGE_COLLECT(gases)
if(temperature < TCMB) //just for safety
temperature = TCMB
//Takes the amount of the gas you want to PP as an argument
//So I don't have to do some hacky switches/defines/magic strings

View File

@@ -78,22 +78,26 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
var/moles_visible = null
var/dangerous = FALSE //currently used by canisters
var/fusion_power = 0 //How much the gas accelerates a fusion reaction
var/rarity = 0 // relative rarity compared to other gases, used when setting up the reactions list.
/datum/gas/oxygen
id = "o2"
specific_heat = 20
name = "Oxygen"
rarity = 900
/datum/gas/nitrogen
id = "n2"
specific_heat = 20
name = "Nitrogen"
rarity = 1000
/datum/gas/carbon_dioxide //what the fuck is this?
id = "co2"
specific_heat = 30
name = "Carbon Dioxide"
fusion_power = 3
rarity = 700
/datum/gas/plasma
id = "plasma"
@@ -102,6 +106,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
gas_overlay = "plasma"
moles_visible = MOLES_GAS_VISIBLE
dangerous = TRUE
rarity = 800
/datum/gas/water_vapor
id = "water_vapor"
@@ -110,6 +115,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
gas_overlay = "water_vapor"
moles_visible = MOLES_GAS_VISIBLE
fusion_power = 8
rarity = 500
/datum/gas/hypernoblium
id = "nob"
@@ -118,6 +124,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
gas_overlay = "freon"
moles_visible = MOLES_GAS_VISIBLE
dangerous = TRUE
rarity = 50
/datum/gas/nitrous_oxide
id = "n2o"
@@ -126,6 +133,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
gas_overlay = "nitrous_oxide"
moles_visible = MOLES_GAS_VISIBLE * 2
dangerous = TRUE
rarity = 600
/datum/gas/nitryl
id = "no2"
@@ -135,6 +143,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
moles_visible = MOLES_GAS_VISIBLE
dangerous = TRUE
fusion_power = 15
rarity = 100
/datum/gas/tritium
id = "tritium"
@@ -144,6 +153,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
moles_visible = MOLES_GAS_VISIBLE
dangerous = TRUE
fusion_power = 1
rarity = 300
/datum/gas/bz
id = "bz"
@@ -151,18 +161,21 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
name = "BZ"
dangerous = TRUE
fusion_power = 8
rarity = 400
/datum/gas/stimulum
id = "stim"
specific_heat = 5
name = "Stimulum"
fusion_power = 7
rarity = 1
/datum/gas/pluoxium
id = "pluox"
specific_heat = 80
name = "Pluoxium"
fusion_power = 10
rarity = 200
/datum/gas/miasma
id = "miasma"
@@ -171,6 +184,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
name = "Miasma"
gas_overlay = "miasma"
moles_visible = MOLES_GAS_VISIBLE * 60
rarity = 250
/obj/effect/overlay/gas
icon = 'icons/effects/atmospherics.dmi'

View File

@@ -1,19 +1,36 @@
//All defines used in reactions are located in ..\__DEFINES\reactions.dm
/proc/init_gas_reactions()
var/list/reaction_types = list()
. = list()
for(var/type in subtypesof(/datum/gas))
.[type] = list()
for(var/r in subtypesof(/datum/gas_reaction))
var/datum/gas_reaction/reaction = r
if(!initial(reaction.exclude))
reaction_types += reaction
reaction_types = sortList(reaction_types, /proc/cmp_gas_reactions)
if(initial(reaction.exclude))
continue
reaction = new r
var/datum/gas/reaction_key
for (var/req in reaction.min_requirements)
if (ispath(req))
var/datum/gas/req_gas = req
if (!reaction_key || initial(reaction_key.rarity) > initial(req_gas.rarity))
reaction_key = req_gas
.[reaction_key] += list(reaction)
sortTim(., /proc/cmp_gas_reactions, TRUE)
. = list()
for(var/path in reaction_types)
. += new path
/proc/cmp_gas_reactions(datum/gas_reaction/a, datum/gas_reaction/b) //sorts in descending order of priority
return initial(b.priority) - initial(a.priority)
/proc/cmp_gas_reactions(list/datum/gas_reaction/a, list/datum/gas_reaction/b) // compares lists of reactions by the maximum priority contained within the list
if (!length(a) || !length(b))
return length(b) - length(a)
var/maxa
var/maxb
for (var/datum/gas_reaction/R in a)
if (R.priority > maxa)
maxa = R.priority
for (var/datum/gas_reaction/R in b)
if (R.priority > maxb)
maxb = R.priority
return maxb - maxa
/datum/gas_reaction
//regarding the requirements lists: the minimum or maximum requirements must be non-zero.
@@ -364,7 +381,7 @@
cached_gases[/datum/gas/nitrous_oxide] -= reaction_efficency
cached_gases[/datum/gas/plasma] -= 2*reaction_efficency
SSresearch.science_tech.add_point_type(TECHWEB_POINT_TYPE_DEFAULT, (reaction_efficency**0.5)*BZ_RESEARCH_AMOUNT)
SSresearch.science_tech.add_point_type(TECHWEB_POINT_TYPE_DEFAULT, (reaction_efficency**0.5)*BZ_RESEARCH_AMOUNT)
if(energy_released > 0)
var/new_heat_capacity = air.heat_capacity()