Jump to content

applyInputTemperature in ElementConverter has broken support for multiple inputs


Nightinggale
  • Branch: Preview Branch Version: Windows Fixed

Buildings using the ElementConverter with applyInputTemperature set to true will not apply the temperature the player will expect. In short it will pick the last input element in the list and use the temperature from that one while ignoring the rest. If we use the water sieve as example (while ignoring the fixed temperature output), the last is polluted water, meaning the output temperature will not care if the filtration medium is -200 C or +500 C.

What happens more specifically is inside the ElementConverter class and all the affected code is in the ConvertMass method.

It sets the float num2 to 0 (decompiler misnaming?). When it loops through the input elements, each time it takes some mass, it executes the code

num2 = component2.Temperature;

component2 being the looped element. This means whenever the next needed element is found, the temperature of the previous elements will be overwritten.

Proposed solution

Mathematical speaking, this is weighted average of the elements' temperatures where the weight is (mass*thermal capacity).

During the loop iteration, store temperatures as a list (from this point "the list") of float pairs. Add one pair for each element and name the two floats weight and temperature. Temperature is the temperature of component2 while weight is "mass * thermal capacity".

Once the loop is done, calculate the resulting temperature as follows:

float temperature = 0;
foreach (entry in list)
{
  temperature += (entry.weight / total_weight) * entry.temperature;
}

For optimization, add the weight to get the total weight during the loop. Also keep the current code, which remembers the last temperature. The weighted average can then be skipped if there is less than 2 entries in the list since we know the result will end up as the same as the last temperature if there is only one entry.

I think this would be the perfect balance between meeting the player's expectations vs performance and coding difficulty. Not only would this affect unmodded ONI, it will also help mods. ElementConverter is a frequently used component in mods meaning this issue is active in multiple mods on steam.


Steps to Reproduce
Read the description and the source code.



User Feedback


A developer has marked this issue as fixed. This means that the issue has been addressed in the current development build and will likely be in the next update.

Changed Status to Fixed

Thanks for the heads-up. Input temperature is now calculated based on all inputs!

  • Thanks 1

Share this comment


Link to comment
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...