From 371857cc354d08db1d6a30ecbdd879e11f09c452 Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 18 Oct 2017 10:24:21 -0200 Subject: [PATCH] Merge pull request #31823 from duncathan/atmos-patch12 Very minor refactor of gas mixture heat_capacity() --- .../environmental/LINDA_turf_tile.dm | 2 +- .../atmospherics/gasmixtures/gas_mixture.dm | 27 ++++++++----------- .../gasmixtures/immutable_mixtures.dm | 3 --- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/code/modules/atmospherics/environmental/LINDA_turf_tile.dm b/code/modules/atmospherics/environmental/LINDA_turf_tile.dm index 721ed63794..265731e96e 100644 --- a/code/modules/atmospherics/environmental/LINDA_turf_tile.dm +++ b/code/modules/atmospherics/environmental/LINDA_turf_tile.dm @@ -27,7 +27,7 @@ var/datum/excited_group/excited_group var/excited = 0 var/recently_active = 0 - var/datum/gas_mixture/air + var/datum/gas_mixture/turf/air var/obj/effect/hotspot/active_hotspot var/atmos_cooldown = 0 diff --git a/code/modules/atmospherics/gasmixtures/gas_mixture.dm b/code/modules/atmospherics/gasmixtures/gas_mixture.dm index 74264b4eae..9b5ea089c2 100644 --- a/code/modules/atmospherics/gasmixtures/gas_mixture.dm +++ b/code/modules/atmospherics/gasmixtures/gas_mixture.dm @@ -65,22 +65,17 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache()) //PV = nRT -/datum/gas_mixture/proc/heat_capacity() //joules per kelvin +/datum/gas_mixture/proc/heat_capacity(data = MOLES) //joules per kelvin var/list/cached_gases = gases . = 0 for(var/id in cached_gases) var/gas_data = cached_gases[id] - . += gas_data[MOLES] * gas_data[GAS_META][META_GAS_SPECIFIC_HEAT] - if(!. && temperature) //if temp isn't defined, this mixture isn't a vacuum like space is. it hasn't been filled with *anything* so we want it to take on the properties of whatever gas enters it - . += HEAT_CAPACITY_VACUUM //however, if temp is defined but HC is still 0, then we want the mixture to behave like space does, as a heat sink + . += gas_data[data] * gas_data[GAS_META][META_GAS_SPECIFIC_HEAT] - -/datum/gas_mixture/proc/heat_capacity_archived() //joules per kelvin - var/list/cached_gases = gases - . = 0 - for(var/id in cached_gases) - var/gas_data = cached_gases[id] - . += gas_data[ARCHIVE] * gas_data[GAS_META][META_GAS_SPECIFIC_HEAT] +/datum/gas_mixture/turf/heat_capacity() + . = ..() + if(!.) + . += HEAT_CAPACITY_VACUUM //we want vacuums in turfs to have the same heat capacity as space //prefer this in performance critical areas #define TOTAL_MOLES(cached_gases, out_var)\ @@ -195,7 +190,7 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache()) amount = min(amount, sum) //Can not take more air than tile has! if(amount <= 0) return null - var/datum/gas_mixture/removed = new + var/datum/gas_mixture/removed = new type var/list/removed_gases = removed.gases //accessing datum vars is slower than proc vars removed.temperature = temperature @@ -213,7 +208,7 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache()) ratio = min(ratio, 1) var/list/cached_gases = gases - var/datum/gas_mixture/removed = new + var/datum/gas_mixture/removed = new type var/list/removed_gases = removed.gases //accessing datum vars is slower than proc vars removed.temperature = temperature @@ -228,7 +223,7 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache()) /datum/gas_mixture/copy() var/list/cached_gases = gases - var/datum/gas_mixture/copy = new + var/datum/gas_mixture/copy = new type var/list/copy_gases = copy.gases copy.temperature = temperature @@ -364,8 +359,8 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache()) sharer_temperature = sharer.temperature_archived var/temperature_delta = temperature_archived - sharer_temperature if(abs(temperature_delta) > MINIMUM_TEMPERATURE_DELTA_TO_CONSIDER) - var/self_heat_capacity = heat_capacity_archived() - sharer_heat_capacity = sharer_heat_capacity || sharer.heat_capacity_archived() + var/self_heat_capacity = heat_capacity(ARCHIVE) + sharer_heat_capacity = sharer_heat_capacity || sharer.heat_capacity(ARCHIVE) if((sharer_heat_capacity > MINIMUM_HEAT_CAPACITY) && (self_heat_capacity > MINIMUM_HEAT_CAPACITY)) var/heat = conduction_coefficient*temperature_delta* \ diff --git a/code/modules/atmospherics/gasmixtures/immutable_mixtures.dm b/code/modules/atmospherics/gasmixtures/immutable_mixtures.dm index 4097ab5c6a..90b9550028 100644 --- a/code/modules/atmospherics/gasmixtures/immutable_mixtures.dm +++ b/code/modules/atmospherics/gasmixtures/immutable_mixtures.dm @@ -19,9 +19,6 @@ /datum/gas_mixture/immutable/merge() return 0 //we're immutable. -/datum/gas_mixture/immutable/heat_capacity_archived() - return heat_capacity() - /datum/gas_mixture/immutable/share(datum/gas_mixture/sharer, atmos_adjacent_turfs = 4) . = ..(sharer, 0) garbage_collect()