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
@@ -38,8 +38,11 @@ GLOBAL_LIST_INIT(meta_gas_fusions, meta_gas_fusion_list())
for(var/id in cached_gases) for(var/id in cached_gases)
. += cached_gases[id] * cached_gasheats[id] . += 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(!.) if(!.)
. += HEAT_CAPACITY_VACUUM //we want vacuums in turfs to have the same heat capacity as space . += 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) /datum/gas_mixture/react(datum/holder)
. = NO_REACTION . = NO_REACTION
var/list/cached_gases = gases var/list/cached_gases = gases
if(!cached_gases.len) if(!length(cached_gases))
return return
var/possible var/list/reactions = list()
for(var/I in cached_gases) for(var/I in cached_gases)
if(GLOB.nonreactive_gases[I]) reactions += SSair.gas_reactions[I]
continue if(!length(reactions))
possible = TRUE
break
if(!possible)
return return
reaction_results = new reaction_results = new
var/temp = temperature var/temp = temperature
var/ener = THERMAL_ENERGY(src) var/ener = THERMAL_ENERGY(src)
reaction_loop: reaction_loop:
for(var/r in SSair.gas_reactions) for(var/r in reactions)
var/datum/gas_reaction/reaction = r var/datum/gas_reaction/reaction = r
var/list/min_reqs = reaction.min_requirements var/list/min_reqs = reaction.min_requirements
@@ -376,14 +376,11 @@ GLOBAL_LIST_INIT(meta_gas_fusions, meta_gas_fusion_list())
continue reaction_loop continue reaction_loop
//at this point, all requirements for the reaction are satisfied. we can now react() //at this point, all requirements for the reaction are satisfied. we can now react()
*/ */
. |= reaction.react(src, holder) . |= reaction.react(src, holder)
if (. & STOP_REACTIONS) if (. & STOP_REACTIONS)
break break
if(.) if(.)
GAS_GARBAGE_COLLECT(gases) 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 //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 //So I don't have to do some hacky switches/defines/magic strings
@@ -78,22 +78,26 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
var/moles_visible = null var/moles_visible = null
var/dangerous = FALSE //currently used by canisters var/dangerous = FALSE //currently used by canisters
var/fusion_power = 0 //How much the gas accelerates a fusion reaction 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 /datum/gas/oxygen
id = "o2" id = "o2"
specific_heat = 20 specific_heat = 20
name = "Oxygen" name = "Oxygen"
rarity = 900
/datum/gas/nitrogen /datum/gas/nitrogen
id = "n2" id = "n2"
specific_heat = 20 specific_heat = 20
name = "Nitrogen" name = "Nitrogen"
rarity = 1000
/datum/gas/carbon_dioxide //what the fuck is this? /datum/gas/carbon_dioxide //what the fuck is this?
id = "co2" id = "co2"
specific_heat = 30 specific_heat = 30
name = "Carbon Dioxide" name = "Carbon Dioxide"
fusion_power = 3 fusion_power = 3
rarity = 700
/datum/gas/plasma /datum/gas/plasma
id = "plasma" id = "plasma"
@@ -102,6 +106,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
gas_overlay = "plasma" gas_overlay = "plasma"
moles_visible = MOLES_GAS_VISIBLE moles_visible = MOLES_GAS_VISIBLE
dangerous = TRUE dangerous = TRUE
rarity = 800
/datum/gas/water_vapor /datum/gas/water_vapor
id = "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" gas_overlay = "water_vapor"
moles_visible = MOLES_GAS_VISIBLE moles_visible = MOLES_GAS_VISIBLE
fusion_power = 8 fusion_power = 8
rarity = 500
/datum/gas/hypernoblium /datum/gas/hypernoblium
id = "nob" id = "nob"
@@ -118,6 +124,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
gas_overlay = "freon" gas_overlay = "freon"
moles_visible = MOLES_GAS_VISIBLE moles_visible = MOLES_GAS_VISIBLE
dangerous = TRUE dangerous = TRUE
rarity = 50
/datum/gas/nitrous_oxide /datum/gas/nitrous_oxide
id = "n2o" id = "n2o"
@@ -126,6 +133,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
gas_overlay = "nitrous_oxide" gas_overlay = "nitrous_oxide"
moles_visible = MOLES_GAS_VISIBLE * 2 moles_visible = MOLES_GAS_VISIBLE * 2
dangerous = TRUE dangerous = TRUE
rarity = 600
/datum/gas/nitryl /datum/gas/nitryl
id = "no2" id = "no2"
@@ -135,6 +143,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
moles_visible = MOLES_GAS_VISIBLE moles_visible = MOLES_GAS_VISIBLE
dangerous = TRUE dangerous = TRUE
fusion_power = 15 fusion_power = 15
rarity = 100
/datum/gas/tritium /datum/gas/tritium
id = "tritium" id = "tritium"
@@ -144,6 +153,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
moles_visible = MOLES_GAS_VISIBLE moles_visible = MOLES_GAS_VISIBLE
dangerous = TRUE dangerous = TRUE
fusion_power = 1 fusion_power = 1
rarity = 300
/datum/gas/bz /datum/gas/bz
id = "bz" id = "bz"
@@ -151,18 +161,21 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
name = "BZ" name = "BZ"
dangerous = TRUE dangerous = TRUE
fusion_power = 8 fusion_power = 8
rarity = 400
/datum/gas/stimulum /datum/gas/stimulum
id = "stim" id = "stim"
specific_heat = 5 specific_heat = 5
name = "Stimulum" name = "Stimulum"
fusion_power = 7 fusion_power = 7
rarity = 1
/datum/gas/pluoxium /datum/gas/pluoxium
id = "pluox" id = "pluox"
specific_heat = 80 specific_heat = 80
name = "Pluoxium" name = "Pluoxium"
fusion_power = 10 fusion_power = 10
rarity = 200
/datum/gas/miasma /datum/gas/miasma
id = "miasma" id = "miasma"
@@ -171,6 +184,7 @@ GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/g
name = "Miasma" name = "Miasma"
gas_overlay = "miasma" gas_overlay = "miasma"
moles_visible = MOLES_GAS_VISIBLE * 60 moles_visible = MOLES_GAS_VISIBLE * 60
rarity = 250
/obj/effect/overlay/gas /obj/effect/overlay/gas
icon = 'icons/effects/atmospherics.dmi' icon = 'icons/effects/atmospherics.dmi'
@@ -1,19 +1,36 @@
//All defines used in reactions are located in ..\__DEFINES\reactions.dm //All defines used in reactions are located in ..\__DEFINES\reactions.dm
/proc/init_gas_reactions() /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)) for(var/r in subtypesof(/datum/gas_reaction))
var/datum/gas_reaction/reaction = r var/datum/gas_reaction/reaction = r
if(!initial(reaction.exclude)) if(initial(reaction.exclude))
reaction_types += reaction continue
reaction_types = sortList(reaction_types, /proc/cmp_gas_reactions) 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() /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
for(var/path in reaction_types) if (!length(a) || !length(b))
. += new path return length(b) - length(a)
var/maxa
/proc/cmp_gas_reactions(datum/gas_reaction/a, datum/gas_reaction/b) //sorts in descending order of priority var/maxb
return initial(b.priority) - initial(a.priority) 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 /datum/gas_reaction
//regarding the requirements lists: the minimum or maximum requirements must be non-zero. //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/nitrous_oxide] -= reaction_efficency
cached_gases[/datum/gas/plasma] -= 2*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) if(energy_released > 0)
var/new_heat_capacity = air.heat_capacity() var/new_heat_capacity = air.heat_capacity()