LSNS: formatting changes, change if statements to switch

This commit is contained in:
jacob1
2019-08-10 17:22:46 -04:00
parent 25b7021f2a
commit 0ec50951f7

View File

@@ -47,19 +47,19 @@ Element_LSNS::Element_LSNS()
//#TPT-Directive ElementHeader Element_LSNS static int update(UPDATE_FUNC_ARGS) //#TPT-Directive ElementHeader Element_LSNS static int update(UPDATE_FUNC_ARGS)
int Element_LSNS::update(UPDATE_FUNC_ARGS) int Element_LSNS::update(UPDATE_FUNC_ARGS)
{ {
int r, rx, ry, rt, rd = parts[i].tmp2; int rd = parts[i].tmp2;
if (rd > 25) parts[i].tmp2 = rd = 25; if (rd > 25) parts[i].tmp2 = rd = 25;
if (parts[i].life) if (parts[i].life)
{ {
parts[i].life = 0; parts[i].life = 0;
for (rx = -2; rx < 3; rx++) for (int rx = -2; rx <= 2; rx++)
for (ry = -2; ry < 3; ry++) for (int ry = -2; ry <= 2; ry++)
if (BOUNDS_CHECK && (rx || ry)) if (BOUNDS_CHECK && (rx || ry))
{ {
r = pmap[y + ry][x + rx]; int r = pmap[y + ry][x + rx];
if (!r) if (!r)
continue; continue;
rt = TYP(r); int rt = TYP(r);
if (sim->parts_avg(i, ID(r), PT_INSL) != PT_INSL) if (sim->parts_avg(i, ID(r), PT_INSL) != PT_INSL)
{ {
if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt == PT_WATR || rt == PT_SLTW || rt == PT_NTCT || rt == PT_PTCT || rt == PT_INWR) && parts[ID(r)].life == 0) if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt == PT_WATR || rt == PT_SLTW || rt == PT_NTCT || rt == PT_PTCT || rt == PT_INWR) && parts[ID(r)].life == 0)
@@ -72,48 +72,50 @@ int Element_LSNS::update(UPDATE_FUNC_ARGS)
} }
} }
bool setFilt = false; bool doSerialization = false;
bool Setnewlife = false; bool doDeserialization = false;
int partlife = 0; int life = 0;
int Newlife = 0; for (int rx = -rd; rx < rd + 1; rx++)
for (rx = -rd; rx < rd + 1; rx++) for (int ry = -rd; ry < rd + 1; ry++)
for (ry = -rd; ry < rd + 1; ry++)
if (x + rx >= 0 && y + ry >= 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) if (x + rx >= 0 && y + ry >= 0 && x + rx < XRES && y + ry < YRES && (rx || ry))
{ {
r = pmap[y + ry][x + rx]; int r = pmap[y + ry][x + rx];
if (!r) if (!r)
r = sim->photons[y + ry][x + rx]; r = sim->photons[y + ry][x + rx];
if (!r) if (!r)
continue; continue;
if (parts[i].tmp == 1 && TYP(r) != PT_LSNS && TYP(r) != PT_FILT && parts[ID(r)].life >= 0)
switch (parts[i].tmp)
{ {
setFilt = true; case 1:
partlife = parts[ID(r)].life; // .life serialization into FILT
} if (TYP(r) != PT_LSNS && TYP(r) != PT_FILT && parts[ID(r)].life >= 0)
if (parts[i].tmp == 3 && TYP(r) == PT_FILT)
{
Setnewlife = true;
Newlife = parts[ID(r)].ctype;
}
if ((parts[i].tmp != 1) && (parts[i].tmp != 2) && (parts[i].tmp != 3))
{
if (parts[ID(r)].life > parts[i].temp - 273.15)
{ {
parts[i].life = 1; doSerialization = true;
life = parts[ID(r)].life;
} }
} break;
//Invert mode. case 3:
if (parts[i].tmp == 2) // .life deserialization
{ if (TYP(r) == PT_FILT)
if (parts[ID(r)].life > parts[i].temp - 273.15) {
parts[i].life = 0; doDeserialization = true;
else life = parts[ID(r)].ctype;
}
break;
case 2:
// Invert mode
if (TYP(r) != PT_METL && parts[ID(r)].life <= parts[i].temp - 273.15)
parts[i].life = 1; parts[i].life = 1;
break;
default:
// Normal mode
if (TYP(r) != PT_METL && parts[ID(r)].life > parts[i].temp - 273.15)
parts[i].life = 1;
break;
} }
} }
int nx, ny;
for (int rx = -1; rx <= 1; rx++) for (int rx = -1; rx <= 1; rx++)
for (int ry = -1; ry <= 1; ry++) for (int ry = -1; ry <= 1; ry++)
if (BOUNDS_CHECK && (rx || ry)) if (BOUNDS_CHECK && (rx || ry))
@@ -121,14 +123,14 @@ int Element_LSNS::update(UPDATE_FUNC_ARGS)
int r = pmap[y + ry][x + rx]; int r = pmap[y + ry][x + rx];
if (!r) if (!r)
continue; continue;
nx = x + rx; int nx = x + rx;
ny = y + ry; int ny = y + ry;
//.life serialization. // .life serialization.
if (setFilt) if (doSerialization)
{ {
while (TYP(r) == PT_FILT) while (TYP(r) == PT_FILT)
{ {
parts[ID(r)].ctype = 0x10000000 + partlife; parts[ID(r)].ctype = 0x10000000 + life;
nx += rx; nx += rx;
ny += ry; ny += ry;
if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES)
@@ -136,20 +138,18 @@ int Element_LSNS::update(UPDATE_FUNC_ARGS)
r = pmap[ny][nx]; r = pmap[ny][nx];
} }
} }
//.life deserialization. // .life deserialization.
if (Setnewlife) if (doDeserialization)
{ {
if (TYP(r) != PT_FILT) if (TYP(r) != PT_FILT)
{ {
parts[ID(r)].life = Newlife - 0x10000000; parts[ID(r)].life = life - 0x10000000;
break; break;
} }
} }
} }
return 0; return 0;
} }
Element_LSNS::~Element_LSNS() {}
Element_LSNS::~Element_LSNS() {}