Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHOT revamp #884

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/simulation/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Element::Element():
Explosive(0),
Meltable(0),
Hardness(30),
PhotonReflectWavelengths(0x3FFFFFFF),

Weight(50),

Expand Down Expand Up @@ -75,7 +74,6 @@ std::vector<StructProperty> const &Element::GetProperties()
{ "Explosive", StructProperty::Integer, offsetof(Element, Explosive ) },
{ "Meltable", StructProperty::Integer, offsetof(Element, Meltable ) },
{ "Hardness", StructProperty::Integer, offsetof(Element, Hardness ) },
{ "PhotonReflectWavelengths", StructProperty::UInteger, offsetof(Element, PhotonReflectWavelengths ) },
{ "CarriesTypeIn", StructProperty::UInteger, offsetof(Element, CarriesTypeIn ) },
{ "Weight", StructProperty::Integer, offsetof(Element, Weight ) },
{ "Temperature", StructProperty::Float, offsetof(Element, DefaultProperties.temp ) },
Expand Down
2 changes: 0 additions & 2 deletions src/simulation/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class Element
int Explosive;
int Meltable;
int Hardness;
// Photon wavelengths are ANDed with this value when a photon hits an element, meaning that only wavelengths present in both this value and the original photon will remain in the reflected photon
unsigned int PhotonReflectWavelengths;
int Weight;
unsigned char HeatConduct;
String Description;
Expand Down
113 changes: 101 additions & 12 deletions src/simulation/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,12 +1221,12 @@ void Simulation::init_can_move()
can_move[PT_PHOT][PT_LCRY] = 3; //varies according to LCRY life
can_move[PT_PHOT][PT_GPMP] = 3;

can_move[PT_PHOT][PT_BIZR] = 2;
can_move[PT_ELEC][PT_BIZR] = 2;
can_move[PT_PHOT][PT_BIZRG] = 2;
can_move[PT_ELEC][PT_BIZRG] = 2;
can_move[PT_PHOT][PT_BIZRS] = 2;
can_move[PT_ELEC][PT_BIZRS] = 2;
can_move[PT_PHOT][PT_BIZR] = 3;
can_move[PT_ELEC][PT_BIZR] = 3;
can_move[PT_PHOT][PT_BIZRG] = 3;
can_move[PT_ELEC][PT_BIZRG] = 3;
can_move[PT_PHOT][PT_BIZRS] = 3;
can_move[PT_ELEC][PT_BIZRS] = 3;
can_move[PT_BIZR][PT_FILT] = 2;
can_move[PT_BIZRG][PT_FILT] = 2;

Expand Down Expand Up @@ -1268,7 +1268,7 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr)
{
case PT_LCRY:
if (pt==PT_PHOT)
result = (parts[ID(r)].life > 5)? 2 : 0;
result = (parts[ID(r)].life > 5) ? 2 : 0;
break;
case PT_GPMP:
if (pt == PT_PHOT)
Expand Down Expand Up @@ -1313,6 +1313,11 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr)
return 0;
}
break;
case PT_BIZR:
case PT_BIZRG:
case PT_BIZRS:
result = (parts[ID(r)].tmp != 2) ? 2 : 0;
break;
default:
// This should never happen
// If it were to happen, try_move would interpret a 3 as a 1
Expand Down Expand Up @@ -1462,8 +1467,11 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
case PT_BIZR:
case PT_BIZRG:
case PT_BIZRS:
part_change_type(i, x, y, PT_ELEC);
parts[i].ctype = 0;
if (parts[ID(r)].tmp != 1)
{
part_change_type(i, x, y, PT_ELEC);
parts[i].ctype = 0;
}
break;
case PT_H2:
if (!(parts[i].tmp&0x1))
Expand Down Expand Up @@ -3090,15 +3098,96 @@ void Simulation::UpdateParticles(int start, int end)

if (t == PT_PHOT)
{
auto mask = elements[TYP(r)].PhotonReflectWavelengths;
if (TYP(r) == PT_LITH)
unsigned int mask = 0;
if (TYP(r) != PT_LITH && ((elements[TYP(r)].MenuSection != SC_SPECIAL && elements[TYP(r)].MenuSection > SC_FORCE) || (elements[TYP(r)].Properties & PROP_CONDUCTS) || TYP(r) == PT_SPRK) && (!(TYP(r) == PT_BRAY || TYP(r) == PT_BIZR || TYP(r) == PT_BIZRG || TYP(r) == PT_BIZRS) || parts[ID(r)].dcolour))
{
int cr = PIXR(elements[TYP(r)].Colour);
int cg = PIXG(elements[TYP(r)].Colour);
int cb = PIXB(elements[TYP(r)].Colour);
if(TYP(r) == PT_SPRK)
{
cr = PIXR(elements[parts[ID(r)].ctype].Colour);
cg = PIXG(elements[parts[ID(r)].ctype].Colour);
cb = PIXB(elements[parts[ID(r)].ctype].Colour);
}
if(parts[ID(r)].dcolour)
{
int da = (parts[ID(r)].dcolour>>24)&0xFF;
int dr = (parts[ID(r)].dcolour>>16)&0xFF;
int dg = (parts[ID(r)].dcolour>>8)&0xFF;
int db = (parts[ID(r)].dcolour)&0xFF;
cr = (da*dr + (256-da)*cr) >> 8;
cg = (da*dg + (256-da)*cg) >> 8;
cb = (da*db + (256-da)*cb) >> 8;
}
float vl = std::max(std::max(cr, cg), cb);
if (vl == 0.0f)
{
kill_part(i);
continue;
}
int mt = 5;
int best = 1000;
int bestmt = mt;
int vr, vg, vb;
for (; mt < 13; mt++)
{
vr = (int)(cr / vl * mt + 0.5f);
vg = (int)(cg / vl * mt + 0.5f);
vb = (int)(cb / vl * mt + 0.5f);
if ((mt < 7 || vr + vb >= mt - 6) && (mt < 10 || vg >= std::max(vr - 9, 0) + std::max(vb - 9, 0)))
{
int diff = std::abs(cr - vr * vl / mt) + std::abs(cg - vg * vl / mt) + std::abs(cb - vb * vl / mt);
if (diff <= best)
{
best = diff;
bestmt = mt;
}
}
}
mt = bestmt;
vr = (int)(cr / vl * mt + 0.5f);
vg = (int)(cg / vl * mt + 0.5f);
vb = (int)(cb / vl * mt + 0.5f);
int shg = 0;
if (vg > 6)
{
shg = std::min(std::max(std::max(std::min(vr - vb, vg - 6), 6 - vg), -3), 3);
vr -= std::max(shg, 0);
vb += std::min(shg, 0);
}
else
{
if (vb > 9)
vg -= vb - 9;
if (vr > 9)
vg -= vr - 9;
}
mask = ((1 << vr) - 1) << (30 - vr);
mask |= ((1 << vg) - 1) << (12 + shg);
mask |= ((1 << vb) - 1);
mask &= 0x3FFFFFFF;
parts[i].ctype &= mask;
if (parts[i].life > 0)
{
parts[i].life /= (255 / vl);
if (parts[i].life < 2)
{
kill_part(i);
continue;
}
}
}
else if (TYP(r) == PT_LITH)
{
int wl_bin = parts[ID(r)].ctype / 4;
if (wl_bin < 0) wl_bin = 0;
if (wl_bin > 25) wl_bin = 25;
mask = (0x1F << wl_bin);
parts[i].ctype &= mask;
}
parts[i].ctype &= mask;
else if ((TYP(r) == PT_BRAY || TYP(r) == PT_BIZR || TYP(r) == PT_BIZRG || TYP(r) == PT_BIZRS) && !parts[ID(r)].dcolour)
parts[i].ctype &= parts[ID(r)].ctype;
}

if (get_normal_interp(t, parts[i].x, parts[i].y, parts[i].vx, parts[i].vy, &nrx, &nry))
Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/ACID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void Element::Element_ACID()
Explosive = 0;
Meltable = 0;
Hardness = 0;
PhotonReflectWavelengths = 0x1FE001FE;

Weight = 10;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/BCOL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void Element::Element_BCOL()
Explosive = 0;
Meltable = 0;
Hardness = 2;
PhotonReflectWavelengths = 0x00000000;

Weight = 90;

Expand Down
22 changes: 10 additions & 12 deletions src/simulation/elements/BRAY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ static int graphics(GRAPHICS_FUNC_ARGS)
*colr = 0;
for (x=0; x<12; x++) {
*colr += (cpart->ctype >> (x+18)) & 1;
*colg += (cpart->ctype >> (x+9)) & 1;
*colb += (cpart->ctype >> x) & 1;
}
for (x=0; x<12; x++)
*colg += (cpart->ctype >> (x+9)) & 1;
x = 624/(*colr+*colg+*colb+1);
*colr *= x;
*colg *= x;
*colb *= x;
double xl = 255.0 / std::max(std::max(*colr,*colg),*colb);
*colr *= xl;
*colg *= xl;
*colb *= xl;
}
}
else if(cpart->tmp==1)
Expand All @@ -80,14 +79,13 @@ static int graphics(GRAPHICS_FUNC_ARGS)
*colr = 0;
for (x=0; x<12; x++) {
*colr += (cpart->ctype >> (x+18)) & 1;
*colg += (cpart->ctype >> (x+9)) & 1;
*colb += (cpart->ctype >> x) & 1;
}
for (x=0; x<12; x++)
*colg += (cpart->ctype >> (x+9)) & 1;
x = 624/(*colr+*colg+*colb+1);
*colr *= x;
*colg *= x;
*colb *= x;
double xl = 255.0 / std::max(std::max(*colr,*colg),*colb);
*colr *= xl;
*colg *= xl;
*colb *= xl;
}
}
else if(cpart->tmp==2)
Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/COAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void Element::Element_COAL()
Explosive = 0;
Meltable = 0;
Hardness = 20;
PhotonReflectWavelengths = 0x00000000;

Weight = 100;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/DUST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void Element::Element_DUST()
Explosive = 0;
Meltable = 0;
Hardness = 30;
PhotonReflectWavelengths = 0x3FFFFFC0;

Weight = 85;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/GOLD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void Element::Element_GOLD()
Explosive = 0;
Meltable = 1;
Hardness = 0;
PhotonReflectWavelengths = 0x3C038100;

Weight = 100;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/GOO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void Element::Element_GOO()
Explosive = 0;
Meltable = 0;
Hardness = 12;
PhotonReflectWavelengths = 0x3FFAAA00;

Weight = 100;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/LAVA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void Element::Element_LAVA()
Explosive = 0;
Meltable = 0;
Hardness = 2;
PhotonReflectWavelengths = 0x3FF00000;

Weight = 45;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/NBLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void Element::Element_NBLE()
Explosive = 0;
Meltable = 0;
Hardness = 1;
PhotonReflectWavelengths = 0x3FFF8000;

Weight = 1;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/NITR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void Element::Element_NITR()
Explosive = 2;
Meltable = 0;
Hardness = 3;
PhotonReflectWavelengths = 0x0007C000;

Weight = 23;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/NSCN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void Element::Element_NSCN()
Explosive = 0;
Meltable = 1;
Hardness = 1;
PhotonReflectWavelengths = 0x00000000;

Weight = 100;

Expand Down
34 changes: 20 additions & 14 deletions src/simulation/elements/PHOT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,29 @@ static int update(UPDATE_FUNC_ARGS)

static int graphics(GRAPHICS_FUNC_ARGS)
{
int x = 0;
*colr = *colg = *colb = 0;
for (x=0; x<12; x++) {
int x;
for (x=*colr=*colg=*colb=0; x<12; x++) {
*colr += (cpart->ctype >> (x+18)) & 1;
*colg += (cpart->ctype >> (x+9)) & 1;
*colb += (cpart->ctype >> x) & 1;
}
for (x=0; x<12; x++)
*colg += (cpart->ctype >> (x+9)) & 1;
x = 624/(*colr+*colg+*colb+1);
*colr *= x;
*colg *= x;
*colb *= x;

*firea = 100;
*firer = *colr;
*fireg = *colg;
*fireb = *colb;

bool tozero = false;
if (cpart->life <= 0)
{
tozero = true;
cpart->life = 680;
}

double lm = std::min(cpart->life, 680) / 680.0;
double xl = 255.0 / std::max(std::max(*colr,*colg),*colb) * lm;
*firer = *colr = round(*colr * xl);
*fireg = *colg = round(*colg * xl);
*fireb = *colb = round(*colb * xl);
*firea = round(100.0 * lm);

if (tozero)
cpart->life = 0;

*pixel_mode &= ~PMODE_FLAT;
*pixel_mode |= FIRE_ADD | PMODE_ADD | NO_DECO;
Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/PLEX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void Element::Element_PLEX()
Explosive = 2;
Meltable = 50;
Hardness = 1;
PhotonReflectWavelengths = 0x1F00003E;

Weight = 100;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/PLNT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void Element::Element_PLNT()
Explosive = 0;
Meltable = 0;
Hardness = 10;
PhotonReflectWavelengths = 0x0007C000;

Weight = 100;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/PLUT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void Element::Element_PLUT()
Explosive = 0;
Meltable = 0;
Hardness = 0;
PhotonReflectWavelengths = 0x001FCE00;

Weight = 90;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/POLO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void Element::Element_POLO()
Explosive = 0;
Meltable = 1;
Hardness = 0;
PhotonReflectWavelengths = 0x000FF200;

Weight = 90;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/PSCN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void Element::Element_PSCN()
Explosive = 0;
Meltable = 1;
Hardness = 1;
PhotonReflectWavelengths = 0x00000000;

Weight = 100;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/SNOW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void Element::Element_SNOW()
Explosive = 0;
Meltable = 0;
Hardness = 20;
PhotonReflectWavelengths = 0x03FFFFFF;

Weight = 50;

Expand Down
1 change: 0 additions & 1 deletion src/simulation/elements/SPRK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void Element::Element_SPRK()
Explosive = 0;
Meltable = 0;
Hardness = 1;
PhotonReflectWavelengths = 0x00000000;

Weight = 100;

Expand Down