diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index e4355c2aa..d494c3fde 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -2292,17 +2292,8 @@ void Simulation::UpdateParticles(int start, int end) if (elements[t].Diffusion)//the random diffusion that gasses have { - if constexpr (LATENTHEAT) - { - //The magic number controls diffusion speed - parts[i].vx += 0.05*sqrtf(parts[i].temp)*elements[t].Diffusion*(2.0f*rng.uniform01()-1.0f); - parts[i].vy += 0.05*sqrtf(parts[i].temp)*elements[t].Diffusion*(2.0f*rng.uniform01()-1.0f); - } - else - { - parts[i].vx += elements[t].Diffusion*(2.0f*rng.uniform01()-1.0f); - parts[i].vy += elements[t].Diffusion*(2.0f*rng.uniform01()-1.0f); - } + parts[i].vx += elements[t].Diffusion*(2.0f*rng.uniform01()-1.0f); + parts[i].vy += elements[t].Diffusion*(2.0f*rng.uniform01()-1.0f); } auto transitionOccurred = false; @@ -2355,39 +2346,18 @@ void Simulation::UpdateParticles(int start, int end) //heat transfer code auto h_count = 0; bool cond; - if constexpr (LATENTHEAT) - { - cond = t && (t!=PT_HSWC||parts[i].life==10) && elements[t].HeatConduct*gel_scale > 0; - } - else - { - cond = t && (t!=PT_HSWC||parts[i].life==10) && rng.chance(int(elements[t].HeatConduct*gel_scale), 250); - } + cond = t && (t!=PT_HSWC||parts[i].life==10) && rng.chance(int(elements[t].HeatConduct*gel_scale), 250); + if (cond) { if (aheat_enable && !(elements[t].Properties&PROP_NOAMBHEAT)) { - if constexpr (LATENTHEAT) - { - auto c_heat = parts[i].temp*96.645/elements[t].HeatConduct*gel_scale*std::fabs(elements[t].Weight) + hv[y/CELL][x/CELL]*100*(pv[y/CELL][x/CELL]-MIN_PRESSURE)/(MAX_PRESSURE-MIN_PRESSURE)*2; - float c_Cm = 96.645/elements[t].HeatConduct*gel_scale*std::fabs(elements[t].Weight) + 100*(pv[y/CELL][x/CELL]-MIN_PRESSURE)/(MAX_PRESSURE-MIN_PRESSURE)*2; - auto pt = c_heat/c_Cm; - pt = restrict_flt(pt, -MAX_TEMP+MIN_TEMP, MAX_TEMP-MIN_TEMP); - parts[i].temp = pt; - //Pressure increase from heat (temporary) - pv[y/CELL][x/CELL] += (pt-hv[y/CELL][x/CELL])*0.004; - hv[y/CELL][x/CELL] = pt; - } - else - { - auto c_heat = (hv[y/CELL][x/CELL]-parts[i].temp)*0.04; - c_heat = restrict_flt(c_heat, -MAX_TEMP+MIN_TEMP, MAX_TEMP-MIN_TEMP); - parts[i].temp += c_heat; - hv[y/CELL][x/CELL] -= c_heat; - } + auto c_heat = (hv[y/CELL][x/CELL]-parts[i].temp)*0.04; + c_heat = restrict_flt(c_heat, -MAX_TEMP+MIN_TEMP, MAX_TEMP-MIN_TEMP); + parts[i].temp += c_heat; + hv[y/CELL][x/CELL] -= c_heat; } auto c_heat = 0.0f; - float c_Cm = 0.0f; int surround_hconduct[8]; for (auto j=0; j<8; j++) { @@ -2405,46 +2375,16 @@ void Simulation::UpdateParticles(int start, int end) && (t!=PT_FILT || rt!=PT_HSWC || parts[ID(r)].tmp != 1)) { surround_hconduct[j] = ID(r); - if constexpr (LATENTHEAT) - { - if (rt==PT_GEL) - gel_scale = parts[ID(r)].tmp*2.55f; - else gel_scale = 1.0f; - - c_heat += parts[ID(r)].temp*96.645/elements[rt].HeatConduct*gel_scale*std::fabs(elements[rt].Weight); - c_Cm += 96.645/elements[rt].HeatConduct*gel_scale*std::fabs(elements[rt].Weight); - } - else - { - c_heat += parts[ID(r)].temp; - } + c_heat += parts[ID(r)].temp; h_count++; } } float pt = R_TEMP; - if constexpr (LATENTHEAT) + pt = (c_heat+parts[i].temp)/(h_count+1); + pt = parts[i].temp = restrict_flt(pt, MIN_TEMP, MAX_TEMP); + for (auto j=0; j<8; j++) { - if (t==PT_GEL) - gel_scale = parts[i].tmp*2.55f; - else gel_scale = 1.0f; - - if (t == PT_PHOT) - pt = (c_heat+parts[i].temp*96.645)/(c_Cm+96.645); - else - pt = (c_heat+parts[i].temp*96.645/elements[t].HeatConduct*gel_scale*std::fabs(elements[t].Weight))/(c_Cm+96.645/elements[t].HeatConduct*gel_scale*std::fabs(elements[t].Weight)); - - c_heat += parts[i].temp*96.645/elements[t].HeatConduct*gel_scale*std::fabs(elements[t].Weight); - c_Cm += 96.645/elements[t].HeatConduct*gel_scale*std::fabs(elements[t].Weight); - parts[i].temp = restrict_flt(pt, MIN_TEMP, MAX_TEMP); - } - else - { - pt = (c_heat+parts[i].temp)/(h_count+1); - pt = parts[i].temp = restrict_flt(pt, MIN_TEMP, MAX_TEMP); - for (auto j=0; j<8; j++) - { - parts[surround_hconduct[j]].temp = pt; - } + parts[surround_hconduct[j]].temp = pt; } auto ctemph = pt; @@ -2465,26 +2405,9 @@ void Simulation::UpdateParticles(int start, int end) if (elements[t].HighTemperatureTransition != NT && ctemph>=elements[t].HighTemperature) { // particle type change due to high temperature - float dbt = ctempl - pt; if (elements[t].HighTemperatureTransition != ST) { - if constexpr (LATENTHEAT) - { - if (elements[t].LatentHeat <= (c_heat - (elements[t].HighTemperature - dbt)*c_Cm)) - { - pt = (c_heat - elements[t].LatentHeat)/c_Cm; - t = elements[t].HighTemperatureTransition; - } - else - { - parts[i].temp = restrict_flt(elements[t].HighTemperature - dbt, MIN_TEMP, MAX_TEMP); - s = 0; - } - } - else - { - t = elements[t].HighTemperatureTransition; - } + t = elements[t].HighTemperatureTransition; } else if (t == PT_ICEI || t == PT_SNOW) { @@ -2500,28 +2423,9 @@ void Simulation::UpdateParticles(int start, int end) if (s) { - if constexpr (LATENTHEAT) - { - //One ice table value for all it's kinds - if (elements[t].LatentHeat <= (c_heat - (elements[parts[i].ctype].LowTemperature - dbt)*c_Cm)) - { - pt = (c_heat - elements[t].LatentHeat)/c_Cm; - t = parts[i].ctype; - parts[i].ctype = PT_NONE; - parts[i].life = 0; - } - else - { - parts[i].temp = restrict_flt(elements[parts[i].ctype].LowTemperature - dbt, MIN_TEMP, MAX_TEMP); - s = 0; - } - } - else - { - t = parts[i].ctype; - parts[i].ctype = PT_NONE; - parts[i].life = 0; - } + t = parts[i].ctype; + parts[i].ctype = PT_NONE; + parts[i].life = 0; } } else @@ -2529,24 +2433,7 @@ void Simulation::UpdateParticles(int start, int end) } else if (t == PT_SLTW) { - if constexpr (LATENTHEAT) - { - if (elements[t].LatentHeat <= (c_heat - (elements[t].HighTemperature - dbt)*c_Cm)) - { - pt = (c_heat - elements[t].LatentHeat)/c_Cm; - - t = rng.chance(1, 4) ? PT_SALT : PT_WTRV; - } - else - { - parts[i].temp = restrict_flt(elements[t].HighTemperature - dbt, MIN_TEMP, MAX_TEMP); - s = 0; - } - } - else - { - t = rng.chance(1, 4) ? PT_SALT : PT_WTRV; - } + t = rng.chance(1, 4) ? PT_SALT : PT_WTRV; } else if (t == PT_BRMT) { @@ -2579,26 +2466,9 @@ void Simulation::UpdateParticles(int start, int end) else if (elements[t].LowTemperatureTransition != NT && ctempl= (c_heat - (elements[t].LowTemperature - dbt)*c_Cm)) - { - pt = (c_heat + elements[elements[t].LowTemperatureTransition].LatentHeat)/c_Cm; - t = elements[t].LowTemperatureTransition; - } - else - { - parts[i].temp = restrict_flt(elements[t].LowTemperature - dbt, MIN_TEMP, MAX_TEMP); - s = 0; - } - } - else - { - t = elements[t].LowTemperatureTransition; - } + t = elements[t].LowTemperatureTransition; } else if (t == PT_WTRV) { @@ -2658,14 +2528,7 @@ void Simulation::UpdateParticles(int start, int end) } else s = 0; - if constexpr (LATENTHEAT) - { - pt = restrict_flt(pt, MIN_TEMP, MAX_TEMP); - for (auto j=0; j<8; j++) - { - parts[surround_hconduct[j]].temp = pt; - } - } + if (s) // particle type change occurred { if (t==PT_ICEI || t==PT_LAVA || t==PT_SNOW)