Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upThermal energy based temperature system #27387
Conversation
This comment has been minimized.
This comment has been minimized.
|
More things to do/check. In item.cpp in std::string item::info there is omething about the temperature tags and item_counters but I don't know what it does. No item has its thermal properties yet. So all items behave as if they were water. When item is spawned it starts at temperature of 0 K and negative energy (but no tags or anything so it behaves like normal room temperature item). The new items are set to enviroment temperature at next temperature check. Up to 5 minutes later. (Cooked items that become hot on cooking are set immediately). game_constants.h has constants for hot (38 C), cold (4.4 C) and freezing (0 C). |
This comment has been minimized.
This comment has been minimized.
|
This pull request has been mentioned on Cataclysm: Dark Days Ahead. There might be relevant details there: https://discourse.cataclysmdda.org/t/the-current-system-for-food-temperatures-is-flawed/17119/30 |
This comment has been minimized.
This comment has been minimized.
|
This is neat, but we need to do some heavy testing to ensure that this doesn't break existing games. I don't want to see a repeat of the era a few months back where food temperature was going haywire. |
Hirmuolio
added some commits
Dec 31, 2018
mlangsdorf
added
[C++]
Temperature
labels
Dec 31, 2018
mlangsdorf
reviewed
Dec 31, 2018
|
Please follow CDDA's manual of code style and make sure ( ) are separated by spaces. I gave suggestions for a couple but there's many more. also consider storing temperature as an integer in milliKelvins and passing energy as an integer in milli or centi Joules. |
This comment has been minimized.
This comment has been minimized.
|
I already said that we can't go to smaller unit of energy without causing 200 liter water tank energy to overflow. And breaking temperatures for items that are in vanilla would be bad. The temperature does not really need any extra precision. Comparing item temperature to enviroment temperature is practically the only place where the "exact" temperature is used. But since high temperatures would never be used we could go for more precision without worrying about temperature overflowing. And I used farenheits for it to make it easier to ineract with other systems that use farenheit without need to do conversion. So if we don't use farenheits we might as well convert from celcius or kelvin instead of from milli farenheit. (Also using metric prefixes with imperial units!) |
mlangsdorf
and others
added some commits
Dec 31, 2018
This comment has been minimized.
This comment has been minimized.
|
Simulation like this doesn't have to account for every nook and cranny to do NASA style calculations. If you just take item weight into account to simulate that your steak will freeze a bit quicker then your freshly killed turkey, and your small bottle of water will freeze faster then then a barrel full of water then you are in the clear. |
Hirmuolio
added some commits
Jan 1, 2019
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Night-Pryanik
reviewed
Jan 1, 2019
src/item.cpp Outdated
Hirmuolio
referenced this pull request
Feb 26, 2019
Merged
Json changes for the new temperature system #28392
ifreund
removed
the
0.D Freeze
label
Mar 8, 2019
This comment has been minimized.
This comment has been minimized.
|
I've come to the conclusion that I cannot merge this until we have some unit tests for it, I'm not going to be able to develop the appropriate level of confidence in it's correctness until I do that. |
This comment has been minimized.
This comment has been minimized.
|
I don't know much about tests. What kind of things the tests should cover? Something like this?: |
This comment has been minimized.
This comment has been minimized.
|
Exactly that kind of thing, the overall form is: We need a variety of these focusing on scenarios typically encountered by the player, i.e. how quickly food and water become inedible in cold weather and how quickly it can be thawed. |
Hirmuolio
added some commits
Mar 11, 2019
This comment has been minimized.
This comment has been minimized.
|
There are some tests now. Test 1: Spawn item. Test 2: Water (250 ml) 55 C in 20 C enviroment. Test 3 section 1: Meat 50 C in -20 C enviroment. Test 2 section 2: Meat -20 C in 20 C enviroment. |
Hirmuolio
added some commits
Mar 12, 2019
This comment has been minimized.
This comment has been minimized.
|
Strange that I would get different result from the tests compared to Travis. Most of them are off by 1/100000 K but two of them are stranger and are off by whole 1 K. |
Hirmuolio
added some commits
Mar 12, 2019
This comment has been minimized.
This comment has been minimized.
|
We have a lot of RNG influence scattered around so a little fuzziness is expected. Over time we can remove the randomness and tighten up the tests, but we don't have to do it right now. The tests are exactly the kind of thing I was looking for. |
Hirmuolio
added some commits
Mar 13, 2019
This comment has been minimized.
This comment has been minimized.
|
Well I think it is now ready. Some foods will have slightly odd values until the json pull request is merged too. (that one may have some conflicts with this. Nothing major. Needs to be checked after this is merged) |
kevingranade
merged commit a868b99
into
CleverRaven:master
Mar 14, 2019
This comment has been minimized.
This comment has been minimized.
adamkad1
commented
Mar 15, 2019
|
cooling clothes when? |
Hirmuolio
deleted the
Hirmuolio:Hirmuolio-temperature
branch
Mar 21, 2019
This comment has been minimized.
This comment has been minimized.
|
This pull request has been mentioned on Cataclysm: Dark Days Ahead. There might be relevant details there: https://discourse.cataclysmdda.org/t/water-drawn-from-ponds-may-be-frozen-in-summer/19432/7 |
Hirmuolio commentedDec 31, 2018
•
edited
Summary
Each item gets its temperature and thermal energy tracked for better phase changes. Items also cool/heat based on energy flow to/from the enviroment.
SUMMARY: Balance "Item temperatures are now based on their thermal energy"Purpose of change
In current system items freeze/unfreeze instantly after reaching the required temperature.
Also in current system the cooling/heating happens purely based on the temperature difference. As a result all items cool and heat at identical rates.
Describe the solution
The new heating/cooling are based on energy flow which is based on item volume and mass.
For liquid and solid items the temperature change is calculated with solution which is based on Newton's law of cooling and rate of heat flow.
T(t) = T_e + ( T_0 - T_e ) * exp( - t * I / ( m * c ) )
For partially frozen items the energy change is calculated with rate of heat flow and the phase change is calculated from the energy.
E(t) = E_0 + I * m * ( T_0 - T_e ) * t / m
where T_e is enviroment temperature, T_0 is item temperature at beginning, t is time, I is conductivity term, m is mass and c is specific heat (either liquid or solid).
The conductivity_term is constant chosen so that 1 l of water cools from 55 °C to 35 °C in about 75 minutes ( to match https://www.researchgate.net/publication/282841499_Study_on_heat_transfer_coefficients_during_cooling_of_PET_bottles_for_food_beverages). Greater values make items change temperature faster. Surface area is calculated into the conductivity term. This value is subjective and can be changed.
Item temperature is calculated using the item's mass and freezing temperature and also the average of the item's materials' specific heat (both liquid and solid) and latent heat of fusion. If specific heats or latent heat are not specified for the item the values of water are used.
The new the freezing/unfreezing happens more realistically based on thermal energy in the item. If the item has enough energy to be at least 50% liquid then it will be considered to be liquid.
Temperature tags are assigned based on temperatures defined in game_constants.cpp:
"FROZEN" = Below freezing temperature
"COLD" = 4.4 °C
"HOT" = 38 °C
Describe alternatives you've considered
If item volume and mass do not have meaningful impact on the temperature system then the calculations can be simplified so that all items again heat/cool at same rate while still keeping energy based temperature system.
The average of the materials of the item is not the best solution. But some items get their vitamins from the average of their materials so adding new materials to them would change their vitamin contents.
Better system would be to use the first material of the item. Or to add a new field on the items that decides what is the main material it is made of.
Additional context
The heat flow is based on https://en.wikipedia.org/wiki/Rate_of_heat_flow and https://en.wikipedia.org/wiki/Newton's_law_of_cooling. All the variables that can not be easily aquired in game are lumped in the conductivity_term constant.