mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-29 19:00:33 +02:00
rewrite ldtc to be less buggy
This commit is contained in:
@@ -46,10 +46,14 @@ Element_LDTC::Element_LDTC()
|
|||||||
Update = &Element_LDTC::update;
|
Update = &Element_LDTC::update;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int mask_invert_filter = 0x1;
|
//#TPT-Directive ElementHeader Element_LDTC static const int FLAG_INVERT_FILTER
|
||||||
const int mask_ignore_energy = 0x2;
|
//#TPT-Directive ElementHeader Element_LDTC static const int FLAG_IGNORE_ENERGY
|
||||||
const int mask_no_copy_color = 0x4;
|
//#TPT-Directive ElementHeader Element_LDTC static const int FLAG_NO_COPY_COLOR
|
||||||
const int mask_keep_searching = 0x8;
|
//#TPT-Directive ElementHeader Element_LDTC static const int FLAG_KEEP_SEARCHING
|
||||||
|
const int Element_LDTC::FLAG_INVERT_FILTER = 0x1;
|
||||||
|
const int Element_LDTC::FLAG_IGNORE_ENERGY = 0x2;
|
||||||
|
const int Element_LDTC::FLAG_NO_COPY_COLOR = 0x4;
|
||||||
|
const int Element_LDTC::FLAG_KEEP_SEARCHING = 0x8;
|
||||||
|
|
||||||
//NOTES:
|
//NOTES:
|
||||||
// ctype is used to store the target element, if any. (NONE is treated as a wildcard)
|
// ctype is used to store the target element, if any. (NONE is treated as a wildcard)
|
||||||
@@ -62,31 +66,37 @@ const int mask_keep_searching = 0x8;
|
|||||||
// 0x08: Keep searching even after finding a particle
|
// 0x08: Keep searching even after finding a particle
|
||||||
|
|
||||||
|
|
||||||
|
//#TPT-Directive ElementHeader Element_LDTC static bool phot_data_type(int rt);
|
||||||
/* Returns true for particles that activate the special FILT color copying mode */
|
/* Returns true for particles that activate the special FILT color copying mode */
|
||||||
bool phot_data_type(int rt)
|
bool Element_LDTC::phot_data_type(int rt)
|
||||||
{
|
{
|
||||||
if (rt == PT_FILT || rt == PT_PHOT || rt == PT_BRAY)
|
return rt == PT_FILT || rt == PT_PHOT || rt == PT_BRAY;
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#TPT-Directive ElementHeader Element_LDTC static bool accepted_conductor(Simulation *sim, int rt);
|
||||||
/* Returns true for particles that start a ray search ("dtec" mode)
|
/* Returns true for particles that start a ray search ("dtec" mode)
|
||||||
*/
|
*/
|
||||||
bool accepted_type(Simulation* sim, int r)
|
bool Element_LDTC::accepted_conductor(Simulation* sim, int r)
|
||||||
{
|
{
|
||||||
int rt = TYP(r);
|
int rt = TYP(r);
|
||||||
if ((sim->elements[rt].Properties & PROP_CONDUCTS) && !(rt == PT_WATR || rt == PT_SLTW || rt == PT_NTCT || rt == PT_PTCT || rt == PT_INWR))
|
return (sim->elements[rt].Properties & PROP_CONDUCTS) &&
|
||||||
{
|
!(rt == PT_WATR || rt == PT_SLTW || rt == PT_NTCT ||
|
||||||
if (sim->parts[ID(r)].life == 0)
|
rt == PT_PTCT || rt == PT_INWR) &&
|
||||||
return true;
|
sim->parts[ID(r)].life == 0;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#TPT-Directive ElementHeader Element_LDTC static int update(UPDATE_FUNC_ARGS)
|
//#TPT-Directive ElementHeader Element_LDTC static int update(UPDATE_FUNC_ARGS)
|
||||||
int Element_LDTC::update(UPDATE_FUNC_ARGS)
|
int Element_LDTC::update(UPDATE_FUNC_ARGS)
|
||||||
{
|
{
|
||||||
int max = parts[i].tmp + parts[i].life;
|
int ctype = TYP(parts[i].ctype), ctypeExtra = ID(parts[i].ctype), detectLength = parts[i].tmp, detectSpaces = parts[i].tmp2;
|
||||||
|
bool copyColor = !(parts[i].tmp2 & Element_LDTC::FLAG_NO_COPY_COLOR);
|
||||||
|
bool ignoreEnergy = parts[i].tmp2 & Element_LDTC::FLAG_IGNORE_ENERGY;
|
||||||
|
bool invertFilter = parts[i].tmp2 & Element_LDTC::FLAG_INVERT_FILTER;
|
||||||
|
bool keepSearching = parts[i].tmp2 & Element_LDTC::FLAG_KEEP_SEARCHING;
|
||||||
|
if (detectSpaces < 0)
|
||||||
|
detectSpaces = parts[i].tmp2 = 0;
|
||||||
|
if (detectLength < 0)
|
||||||
|
detectLength = parts[i].tmp = 0;
|
||||||
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++)
|
||||||
@@ -96,58 +106,60 @@ int Element_LDTC::update(UPDATE_FUNC_ARGS)
|
|||||||
int r = pmap[y+ry][x+rx];
|
int r = pmap[y+ry][x+rx];
|
||||||
if (!r)
|
if (!r)
|
||||||
continue;
|
continue;
|
||||||
|
bool boolMode = Element_LDTC::accepted_conductor(sim, r);
|
||||||
if (!accepted_type(sim, r) && ((parts[i].tmp2 & mask_no_copy_color) || !phot_data_type(TYP(r))))
|
bool filtMode = copyColor && TYP(r) == PT_FILT;
|
||||||
|
if (!boolMode && !filtMode)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Stolen from DRAY, does the ray searching
|
int maxRange = parts[i].life + parts[i].tmp;
|
||||||
int xStep = rx * -1, yStep = ry * -1;
|
int xStep = rx * -1, yStep = ry * -1;
|
||||||
int xCurrent = x + (xStep * (parts[i].life + 1)), yCurrent = y + (yStep * (parts[i].life + 1));
|
int xCurrent = x + (xStep * (parts[i].life + 1)), yCurrent = y + (yStep * (parts[i].life + 1));
|
||||||
for (;(parts[i].tmp == 0) || !(xCurrent - x >= max) || (yCurrent-y >= max); xCurrent += xStep, yCurrent += yStep)
|
for (; !parts[i].tmp ||
|
||||||
|
(xStep * (xCurrent - x) <= maxRange &&
|
||||||
|
yStep * (yCurrent - y) <= maxRange);
|
||||||
|
xCurrent += xStep, yCurrent += yStep)
|
||||||
{
|
{
|
||||||
int rr = pmap[yCurrent][xCurrent];
|
|
||||||
if (!(xCurrent>=0 && yCurrent>=0 && xCurrent<XRES && yCurrent<YRES))
|
if (!(xCurrent>=0 && yCurrent>=0 && xCurrent<XRES && yCurrent<YRES))
|
||||||
{
|
|
||||||
break; // We're out of bounds! Oops!
|
break; // We're out of bounds! Oops!
|
||||||
}
|
int rr = pmap[yCurrent][xCurrent];
|
||||||
if (!rr)
|
if (!rr && !ignoreEnergy)
|
||||||
{
|
|
||||||
rr = sim->photons[yCurrent][xCurrent];
|
rr = sim->photons[yCurrent][xCurrent];
|
||||||
if (!(rr && !(parts[i].tmp2 & mask_ignore_energy)))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!rr)
|
if (!rr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Usual DTEC-like mode
|
|
||||||
if (!phot_data_type(TYP(r)))
|
|
||||||
{
|
|
||||||
// If ctype isn't set (no type restriction), or ctype matches what we found
|
// If ctype isn't set (no type restriction), or ctype matches what we found
|
||||||
// Can use .tmp2 flag to invert this
|
// Can use .tmp2 flag to invert this
|
||||||
if (parts[i].ctype == 0 || (parts[i].ctype == TYP(rr)) ^ (parts[i].tmp2 & mask_invert_filter))
|
bool matchesCtype = parts[i].ctype == TYP(rr) && (ctype != PT_LIFE || parts[ID(rr)].ctype == ctypeExtra);
|
||||||
|
bool matchesFilter = !ctype || (invertFilter ^ (int)matchesCtype);
|
||||||
|
if (!matchesFilter)
|
||||||
|
{
|
||||||
|
if (keepSearching)
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// room for more conditions here.
|
||||||
|
|
||||||
|
if (boolMode)
|
||||||
{
|
{
|
||||||
parts[ID(r)].life = 4;
|
parts[ID(r)].life = 4;
|
||||||
parts[ID(r)].ctype = TYP(r);
|
parts[ID(r)].ctype = TYP(r);
|
||||||
sim->part_change_type(ID(r), x + rx, y + ry, PT_SPRK);
|
sim->part_change_type(ID(r), x + rx, y + ry, PT_SPRK);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// room for more conditions here.
|
|
||||||
}
|
if (filtMode)
|
||||||
// FILT color copying mode
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If ctype isn't set (no type restriction), or ctype matches what we found
|
|
||||||
// Can use .tmp2 flag to invert this
|
|
||||||
if (parts[i].ctype == 0 || (parts[i].ctype == TYP(rr)) ^ (parts[i].tmp2 & mask_invert_filter))
|
|
||||||
{
|
|
||||||
if (phot_data_type(TYP(rr)))
|
|
||||||
{
|
{
|
||||||
|
if (!Element_LDTC::phot_data_type(TYP(rr)))
|
||||||
|
continue;
|
||||||
|
|
||||||
int nx = x + rx, ny = y + ry;
|
int nx = x + rx, ny = y + ry;
|
||||||
|
int photonWl = TYP(rr) == PT_FILT ?
|
||||||
|
Element_FILT::getWavelengths(&parts[ID(rr)]) :
|
||||||
|
parts[ID(rr)].ctype;
|
||||||
while (TYP(r) == PT_FILT)
|
while (TYP(r) == PT_FILT)
|
||||||
{
|
{
|
||||||
parts[ID(r)].ctype = Element_FILT::getWavelengths(&parts[ID(rr)]);
|
parts[ID(r)].ctype = photonWl;
|
||||||
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)
|
||||||
@@ -158,10 +170,6 @@ int Element_LDTC::update(UPDATE_FUNC_ARGS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(parts[i].tmp2 & mask_keep_searching))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user