Use NT and ST for checks against *Transition

This is already a fairly obscure part of the codebase, and that NT and ST are only used in element files but not where *Transition properties are processed really doesn't help. This change makes usage of these constants easier to search for. Sadly, this doesn't help the case of IPL, IPH, ITL, ITH, whose handling is still implicit. I dared not rework the code to check for them explicitly because eww, floats.
This commit is contained in:
Tamás Bálint Misius
2024-06-20 11:45:28 +02:00
parent b4a12aae32
commit f3c92038e1
3 changed files with 25 additions and 22 deletions

View File

@@ -3,23 +3,12 @@
#include "Misc.h"
#include "common/tpt-rand.h"
#include "common/tpt-compat.h"
#include "ElementDefs.h"
#include "ElementClasses.h"
#include "Particle.h"
#include "ElementGraphics.h"
#include "Simulation.h"
#include "SimulationData.h"
#include "graphics/Renderer.h"
#include "TransitionConstants.h"
#include <algorithm>
#include <cmath>
constexpr float IPL = MIN_PRESSURE - 1;
constexpr float IPH = MAX_PRESSURE + 1;
constexpr float ITL = MIN_TEMP - 1;
constexpr float ITH = MAX_TEMP + 1;
// no transition (PT_NONE means kill part)
constexpr int NT = -1;
// special transition - lava ctypes etc need extra code, which is only found and run if ST is given
constexpr int ST = PT_NUM;

View File

@@ -1,6 +1,7 @@
#include "Simulation.h"
#include "Air.h"
#include "ElementClasses.h"
#include "TransitionConstants.h"
#include "gravity/Gravity.h"
#include "ToolClasses.h"
#include "SimulationData.h"
@@ -2467,11 +2468,11 @@ void Simulation::UpdateParticles(int start, int end)
if ((t==PT_ICEI || t==PT_SNOW) && (!sd.IsElement(parts[i].ctype) || parts[i].ctype==PT_ICEI || parts[i].ctype==PT_SNOW))
parts[i].ctype = PT_WATR;
if (elements[t].HighTemperatureTransition>-1 && ctemph>=elements[t].HighTemperature)
if (elements[t].HighTemperatureTransition != NT && ctemph>=elements[t].HighTemperature)
{
// particle type change due to high temperature
float dbt = ctempl - pt;
if (elements[t].HighTemperatureTransition != PT_NUM)
if (elements[t].HighTemperatureTransition != ST)
{
if constexpr (LATENTHEAT)
{
@@ -2581,11 +2582,11 @@ void Simulation::UpdateParticles(int start, int end)
else
s = 0;
}
else if (elements[t].LowTemperatureTransition > -1 && ctempl<elements[t].LowTemperature)
else if (elements[t].LowTemperatureTransition != NT && ctempl<elements[t].LowTemperature)
{
// particle type change due to low temperature
float dbt = ctempl - pt;
if (elements[t].LowTemperatureTransition != PT_NUM)
if (elements[t].LowTemperatureTransition != ST)
{
if constexpr (LATENTHEAT)
{
@@ -2791,9 +2792,9 @@ void Simulation::UpdateParticles(int start, int end)
{
auto s = 1;
auto gravtot = fabs(gravy[(y/CELL)*XCELLS+(x/CELL)])+fabs(gravx[(y/CELL)*XCELLS+(x/CELL)]);
if (elements[t].HighPressureTransition>-1 && pv[y/CELL][x/CELL]>elements[t].HighPressure) {
if (elements[t].HighPressureTransition != NT && pv[y/CELL][x/CELL]>elements[t].HighPressure) {
// particle type change due to high pressure
if (elements[t].HighPressureTransition!=PT_NUM)
if (elements[t].HighPressureTransition != ST)
t = elements[t].HighPressureTransition;
else if (t==PT_BMTL) {
if (pv[y/CELL][x/CELL]>2.5f)
@@ -2803,14 +2804,14 @@ void Simulation::UpdateParticles(int start, int end)
else s = 0;
}
else s = 0;
} else if (elements[t].LowPressureTransition>-1 && pv[y/CELL][x/CELL]<elements[t].LowPressure && gravtot<=(elements[t].LowPressure/4.0f)) {
} else if (elements[t].LowPressureTransition != NT && pv[y/CELL][x/CELL]<elements[t].LowPressure && gravtot<=(elements[t].LowPressure/4.0f)) {
// particle type change due to low pressure
if (elements[t].LowPressureTransition!=PT_NUM)
if (elements[t].LowPressureTransition != ST)
t = elements[t].LowPressureTransition;
else s = 0;
} else if (elements[t].HighPressureTransition>-1 && gravtot>(elements[t].HighPressure/4.0f)) {
} else if (elements[t].HighPressureTransition != NT && gravtot>(elements[t].HighPressure/4.0f)) {
// particle type change due to high gravity
if (elements[t].HighPressureTransition!=PT_NUM)
if (elements[t].HighPressureTransition != ST)
t = elements[t].HighPressureTransition;
else if (t==PT_BMTL) {
if (gravtot>0.625f)

View File

@@ -0,0 +1,13 @@
#pragma once
#include "ElementDefs.h"
constexpr float IPL = MIN_PRESSURE - 1;
constexpr float IPH = MAX_PRESSURE + 1;
constexpr float ITL = MIN_TEMP - 1;
constexpr float ITH = MAX_TEMP + 1;
// no transition (PT_NONE means kill part)
constexpr int NT = -1;
// special transition - lava ctypes etc need extra code, which is only found and run if ST is given
constexpr int ST = PT_NUM;