From c7db3ad8f9e60c3fe13b675a6fc577ec4086c5c8 Mon Sep 17 00:00:00 2001 From: Ghommie Date: Tue, 16 Jul 2019 23:51:38 +0200 Subject: [PATCH 1/3] Porting a couple atmos performance improvements. --- .../atmospherics/gasmixtures/gas_mixture.dm | 23 +++++------ .../atmospherics/gasmixtures/gas_types.dm | 14 +++++++ .../atmospherics/gasmixtures/reactions.dm | 39 +++++++++++++------ 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/code/modules/atmospherics/gasmixtures/gas_mixture.dm b/code/modules/atmospherics/gasmixtures/gas_mixture.dm index 9858db2abb..527427af02 100644 --- a/code/modules/atmospherics/gasmixtures/gas_mixture.dm +++ b/code/modules/atmospherics/gasmixtures/gas_mixture.dm @@ -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(data = MOLES) // Same as above except vacuums return HEAT_CAPACITY_VACUUM + var/list/cached_gases = gases + for(var/id in cached_gases) + var/gas_data = cached_gases[id] + . += gas_data[data] * gas_data[GAS_META][META_GAS_SPECIFIC_HEAT] 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 diff --git a/code/modules/atmospherics/gasmixtures/gas_types.dm b/code/modules/atmospherics/gasmixtures/gas_types.dm index d628826b01..19f7bff965 100644 --- a/code/modules/atmospherics/gasmixtures/gas_types.dm +++ b/code/modules/atmospherics/gasmixtures/gas_types.dm @@ -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' diff --git a/code/modules/atmospherics/gasmixtures/reactions.dm b/code/modules/atmospherics/gasmixtures/reactions.dm index ef0a422079..a2369b3f56 100644 --- a/code/modules/atmospherics/gasmixtures/reactions.dm +++ b/code/modules/atmospherics/gasmixtures/reactions.dm @@ -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)) + . += new type + 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() From 408c9aec51526d859f778de61d95d13894b17550 Mon Sep 17 00:00:00 2001 From: Ghommie Date: Wed, 17 Jul 2019 01:01:33 +0200 Subject: [PATCH 2/3] Nothing the power of copypasta won't stop. --- code/modules/atmospherics/gasmixtures/gas_mixture.dm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/modules/atmospherics/gasmixtures/gas_mixture.dm b/code/modules/atmospherics/gasmixtures/gas_mixture.dm index 527427af02..0d9c0730c1 100644 --- a/code/modules/atmospherics/gasmixtures/gas_mixture.dm +++ b/code/modules/atmospherics/gasmixtures/gas_mixture.dm @@ -38,11 +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(data = MOLES) // Same as above except vacuums return HEAT_CAPACITY_VACUUM +/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) - var/gas_data = cached_gases[id] - . += gas_data[data] * gas_data[GAS_META][META_GAS_SPECIFIC_HEAT] + . += cached_gases[id] * cached_gasheats[id] if(!.) . += HEAT_CAPACITY_VACUUM //we want vacuums in turfs to have the same heat capacity as space From 8bd64598c5b92a74396c36e4ba5283e57cf055b3 Mon Sep 17 00:00:00 2001 From: Ghommie Date: Wed, 17 Jul 2019 01:32:33 +0200 Subject: [PATCH 3/3] umh mh... --- code/modules/atmospherics/gasmixtures/reactions.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/modules/atmospherics/gasmixtures/reactions.dm b/code/modules/atmospherics/gasmixtures/reactions.dm index a2369b3f56..5ad97fb7c8 100644 --- a/code/modules/atmospherics/gasmixtures/reactions.dm +++ b/code/modules/atmospherics/gasmixtures/reactions.dm @@ -3,7 +3,7 @@ /proc/init_gas_reactions() . = list() for(var/type in subtypesof(/datum/gas)) - . += new type + .[type] = list() for(var/r in subtypesof(/datum/gas_reaction)) var/datum/gas_reaction/reaction = r