Skip to content

Commit

Permalink
fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
silicons committed Oct 10, 2024
1 parent a8231ed commit e926271
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
3 changes: 2 additions & 1 deletion code/___compile_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@
// ## Atmospherics

//? Gasmixtures

/// Enable general assertions.
#define GASMIXTURE_ASSERTIONS
#define CF_ATMOS_DEBUG_ASSERTIONS


//? ZAS (Environmental)
Expand Down
50 changes: 31 additions & 19 deletions code/modules/atmospherics/environmental/turf-share.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
* * limit_ratio is provided so you can limit the amount of energy transferred to a single segment
* of say, a heat exchanging pipeline, as while the entire pipeline has a lot of heat capacity,
* an individual pipe segment does not.
// * someone please help do the algebra and see equalize_ratio and limit_ratio aren't just able to be collapsed into one term
* * someone please help do the algebra and see equalize_ratio and limit_ratio aren't just able to be collapsed into one term
*
* @params
* * temperature - the temperature of the sharer
* * heat_capacity - the specific heat of the sharer in J / K
* * limit_ratio - a multiplier for the part of 'heat_capacity' that can be drawn from / added to this tick.
* The allowable values are: [0, 1].
* * equalize_ratio - a limit to delta-energy; 0.5 means only transfer up to 50% of the energy needed to equalize.
* Be very, very careful when setting high values of this!
* The allowable values are: [0, 1].
* * cell_limit - the maximum effective volume in cells of the share. If we're in a zone with
* 10 tiles and share_volume is only 2, we will at most equalize the energy
* in 1/5 of our zone. This is to artificially limit the effectiveness
Expand All @@ -31,26 +33,31 @@
* @return the temperature change to the sharer
*/
/turf/proc/air_thermal_superconduction(temperature, heat_capacity, limit_ratio, equalize_ratio, cell_limit)
#warn fix
#ifdef CF_ATMOS_DEBUG_ASSERTIONS
ASSERT(limit_ratio >= 0 && limit_ratio <= 1)
ASSERT(equalize_ratio >= 0 && equalize_ratio <= 1)
#endif
#warn test
// unsimulated mixtures
var/datum/gas_mixture/sharing_with_immutable = return_air_immutable()
// to avoid precision issues, we only want our singular heat capacity
var/our_heat_capacity = sharing_with_immutable.heat_capacity_singular()
var/our_singular_heat_capacity = sharing_with_immutable.heat_capacity_singular()
// then, we divide their capacity by cell limit instead of expand our relative capacity.
var/midpoint_t = ((our_heat_capacity * sharing_with_immutable.temperature) + ((heat_capacity / cell_limit) * temperature)) \
/ (our_heat_capacity + (heat_capacity / cell_limit))
// if this was an actual simulated turf, we'd need to calculate the change
// with equalize ratio, and then limit it with limit ratio
//
// since this is unsimulated, limit ratio is effectively just a secondary
// equalize ratio, as the total temperature change is tempered by the
// limit ratio limiting the availability of thermal energy to effect that change
// (we don't change but the opposite & equal change to the sharer still happens)
var/their_effective_capacity = (heat_capacity / cell_limit) * limit_ratio
// calculate midpoint temperature
var/midpoint_t = ((our_singular_heat_capacity * sharing_with_immutable.temperature) + (their_effective_capacity * temperature)) \
/ (our_heat_capacity + their_effective_capacity)
// since it's an unsimulated turf, we just care to change their temperature.
return (midpoint_t - temperature) * equalize_ratio * limit_ratio

/turf/simulated/air_thermal_superconduction(temperature, heat_capacity, limit_ratio, equalize_ratio, cell_limit)
#warn fix
#ifdef CF_ATMOS_DEBUG_ASSERTIONS
ASSERT(limit_ratio >= 0 && limit_ratio <= 1)
ASSERT(equalize_ratio >= 0 && equalize_ratio <= 1)
#endif
#warn test
// simulated mixtures
//
// the trick is the rest of this proc works regardless of if we're in a zone or not,
// because we're using group multiplier manually with cell unit
var/datum/gas_mixture/sharing_with_mutable = return_air_mutable()
Expand All @@ -63,13 +70,18 @@
// also apply limit ratio here to make them even smaller than they are
var/their_effective_capacity = (heat_capacity / our_size_multiplier) * limit_ratio
// get the temperature 'goal'
// this is only taking into account the portion of them (limit_ratio is used)
// that we're equalizing with, **not** the whole part!
var/midpoint_t = ((our_singular_heat_capacity * sharing_with_mutable.temperature) + (their_effective_capacity * temperature)) / (their_effective_capacity + our_singular_heat_capacity)
// equalize ratio is a delta-energy modifier
// we don't want equalize ratio to affect the 'true' target temperature,
// only how much is actually transferred
// we also don't want to not multiply full energy transfer because it'll get precision issues
// this is the temperature change to the part of them that limit_ratio allows for.
// so this has the heat capacity of `heat_capacity * limit_ratio`.
// this does not care about our effective size multiplier,
// as that is used to bias the temperature change, as opposed to representing
// any change to the total energy being transferred.
var/temperature_change_to_them = (midpoint_t - temperature) * equalize_ratio
// impart temperature change on us
sharing_with_mutable.temperature += (-temperature_change_to_them * (their_effective_capacity / our_singular_heat_capacity)) / our_size_multiplier
// this is calculated with the energy imparted by their temperature change
// this is grouped in a specific way to avoid float imprecision!
sharing_with_mutable.temperature += -temperature_change_to_them * heat_capacity / sharing_with_mutable.group_multiplier * limit_ratio / our_singular_heat_capacity
// return temperature change to them
return temperature_change_to_them * (their_effective_capacity / heat_capacity)
return temperature_change_to_them * limit_ratio
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* based on connecting tiles. Is just a wrapper to use a lookup table.
*/
/datum/gas_mixture/proc/environmental_share_simulated(datum/gas_mixture/other, tiles)
#ifdef GASMIXTURE_ASSERTIONS
#ifdef CF_ATMOS_DEBUG_ASSERTIONS
ASSERT(tiles > 0)
#endif
var/static/list/lookup_table = list(
Expand Down
4 changes: 2 additions & 2 deletions code/modules/atmospherics/gasmixtures/gas_mixture-share.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @return TRUE if we are near-equivalent to the other, FALSE if we are still different.
*/
/datum/gas_mixture/proc/share_with_mixture(datum/gas_mixture/other, ratio)
#ifdef GASMIXTURE_ASSERTIONS
#ifdef CF_ATMOS_DEBUG_ASSERTIONS
ASSERT(ratio > 0 && ratio <= 1)
// todo: volume based, not group multiplier based. is it worth it?
ASSERT(volume == other.volume)
Expand Down Expand Up @@ -89,7 +89,7 @@
* @return TRUE if we are near-equivalent to the other, FALSE if we are still different.
*/
/datum/gas_mixture/proc/share_with_immutable(list/gases, group_multiplier, temperature, ratio)
#ifdef GASMIXTURE_ASSERTIONS
#ifdef CF_ATMOS_DEBUG_ASSERTIONS
ASSERT(ratio > 0 && ratio <= 1)
ASSERT(temperature >= TCMB)
ASSERT(group_multiplier >= 1)
Expand Down

0 comments on commit e926271

Please sign in to comment.