diff --git a/code/__DEFINES/atmospherics.dm b/code/__DEFINES/atmospherics.dm index 456582c6a5..47ca0a8ada 100644 --- a/code/__DEFINES/atmospherics.dm +++ b/code/__DEFINES/atmospherics.dm @@ -16,6 +16,9 @@ #define T0C 273.15 // 0degC #define T20C 293.15 // 20degC +//Quantization +#define ATMOS_QUANTIZATION_ACCURACY 0.0000001 //gases below this in mols are GC'd + #define MOLES_CELLSTANDARD (ONE_ATMOSPHERE*CELL_VOLUME/(T20C*R_IDEAL_GAS_EQUATION)) //moles in a 2.5 m^3 cell at 101.325 Pa and 20 degC #define M_CELL_WITH_RATIO (MOLES_CELLSTANDARD * 0.005) //compared against for superconductivity #define O2STANDARD 0.21 //percentage of oxygen in a normal mixture of air @@ -255,7 +258,7 @@ //HELPERS #define THERMAL_ENERGY(gas) (gas.temperature * gas.heat_capacity()) -#define QUANTIZE(variable) (round(variable,0.0000001))/*I feel the need to document what happens here. Basically this is used to catch most rounding errors, however it's previous value made it so that +#define QUANTIZE(variable) (round(variable,ATMOS_QUANTIZATION_ACCURACY))/*I feel the need to document what happens here. Basically this is used to catch most rounding errors, however it's previous value made it so that once gases got hot enough, most procedures wouldnt occur due to the fact that the mole counts would get rounded away. Thus, we lowered it a few orders of magnititude */ //prefer this to gas_mixture/total_moles in performance critical areas diff --git a/code/modules/atmospherics/environmental/LINDA_turf_tile.dm b/code/modules/atmospherics/environmental/LINDA_turf_tile.dm index 389f1a69f3..a457482a06 100644 --- a/code/modules/atmospherics/environmental/LINDA_turf_tile.dm +++ b/code/modules/atmospherics/environmental/LINDA_turf_tile.dm @@ -90,6 +90,7 @@ /turf/open/archive() ARCHIVE_TEMPERATURE(air) + air.gases_archived = air.gases.Copy() archived_cycle = SSair.times_fired temperature_archived = temperature diff --git a/code/modules/atmospherics/gasmixtures/gas_mixture.dm b/code/modules/atmospherics/gasmixtures/gas_mixture.dm index 5b54e58917..ff46f9f3ad 100644 --- a/code/modules/atmospherics/gasmixtures/gas_mixture.dm +++ b/code/modules/atmospherics/gasmixtures/gas_mixture.dm @@ -15,15 +15,16 @@ GLOBAL_LIST_INIT(meta_gas_overlays, meta_gas_overlay_list()) GLOBAL_LIST_INIT(meta_gas_dangers, meta_gas_danger_list()) GLOBAL_LIST_INIT(meta_gas_ids, meta_gas_id_list()) GLOBAL_LIST_INIT(meta_gas_fusions, meta_gas_fusion_list()) + /datum/gas_mixture var/list/gases = list() + var/tmp/list/gases_archived = list() var/temperature = 0 //kelvins var/tmp/temperature_archived = 0 var/volume = CELL_VOLUME //liters var/last_share = 0 var/list/reaction_results = list() var/list/analyzer_results //used for analyzer feedback - not initialized until its used - var/gc_share = FALSE // Whether to call garbage_collect() on the sharer during shares, used for immutable mixtures /datum/gas_mixture/New(volume) if (!isnull(volume)) @@ -219,7 +220,7 @@ GLOBAL_LIST_INIT(meta_gas_fusions, meta_gas_fusion_list()) /datum/gas_mixture/share(datum/gas_mixture/sharer, atmos_adjacent_turfs = 4) - var/list/cached_gases = gases + var/list/cached_gases = gases_archived var/list/sharer_gases = sharer.gases var/temperature_delta = temperature_archived - sharer.temperature_archived @@ -242,10 +243,28 @@ GLOBAL_LIST_INIT(meta_gas_fusions, meta_gas_fusion_list()) var/gas_heat_capacity //and also cache this shit rq because that results in sanic speed for reasons byond explanation var/list/cached_gasheats = GLOB.meta_gas_specific_heats + + //Do this early and save doing TWO MORE (probable) LIST ACCESSES!! + var/our_moles + var/their_moles + + //decs are expensive + var/us + var/them + //GAS TRANSFER for(var/id in cached_gases | sharer_gases) // transfer gases + us = cached_gases[id] + them = sharer_gases[id] - delta = QUANTIZE(cached_gases[id] - sharer_gases[id])/(atmos_adjacent_turfs+1) //the amount of gas that gets moved between the mixtures + //buitl in garbage collect + if(max(us, them) <= ATMOS_QUANTIZATION_ACCURACY) + cached_gases -= id + sharer_gases -= id + continue + + delta = QUANTIZE(us - them)/(atmos_adjacent_turfs+1) //the amount of gas that gets moved between the mixtures + our_moles += cached if(delta && abs_temperature_delta > MINIMUM_TEMPERATURE_DELTA_TO_CONSIDER) gas_heat_capacity = delta * cached_gasheats[id] @@ -259,6 +278,9 @@ GLOBAL_LIST_INIT(meta_gas_fusions, meta_gas_fusion_list()) moved_moles += delta abs_moved_moles += abs(delta) + our_moles += cached_gases[id] + their_moles += sharer_gases[id] + last_share = abs_moved_moles //THERMAL ENERGY TRANSFER @@ -278,13 +300,7 @@ GLOBAL_LIST_INIT(meta_gas_fusions, meta_gas_fusion_list()) if(abs(new_sharer_heat_capacity/old_sharer_heat_capacity - 1) < 0.1) // <10% change in sharer heat capacity temperature_share(sharer, OPEN_HEAT_TRANSFER_COEFFICIENT) - if (initial(sharer.gc_share)) - GAS_GARBAGE_COLLECT(sharer.gases) if(temperature_delta > MINIMUM_TEMPERATURE_TO_MOVE || abs(moved_moles) > MINIMUM_MOLES_DELTA_TO_MOVE) - var/our_moles - TOTAL_MOLES(cached_gases,our_moles) - var/their_moles - TOTAL_MOLES(sharer_gases,their_moles) return (temperature_archived*(our_moles + moved_moles) - sharer.temperature_archived*(their_moles - moved_moles)) * R_IDEAL_GAS_EQUATION / volume /datum/gas_mixture/temperature_share(datum/gas_mixture/sharer, conduction_coefficient, sharer_temperature, sharer_heat_capacity) diff --git a/code/modules/atmospherics/gasmixtures/immutable_mixtures.dm b/code/modules/atmospherics/gasmixtures/immutable_mixtures.dm index 5527ba3fef..80f170c707 100644 --- a/code/modules/atmospherics/gasmixtures/immutable_mixtures.dm +++ b/code/modules/atmospherics/gasmixtures/immutable_mixtures.dm @@ -3,7 +3,6 @@ /datum/gas_mixture/immutable var/initial_temperature - gc_share = TRUE /datum/gas_mixture/immutable/New() ..()