Permalink
Browse files

last src/simulation/element changes

PSTN, CRAY, and possibly some others will need to be modified to account for this without breaking saves. The save format will need to include PMAPBITS and adjust properly
  • Loading branch information...
jacob1 committed Dec 29, 2017
1 parent 208cf14 commit da45e0e46924d7f6e1d870682d5c07e4fbf0a585
@@ -50,7 +50,14 @@
#define OLD_PT_WIND 147
//#define PT_NUM 161
// Change this to change the amount of bits used to store type in pmap (and a few elements such as PIPE and CRAY)
#define PMAPBITS 8
#define PMAPMASK ((2<<(PMAPBITS-1))-1)
#define ID(r) ((r)>>PMAPBITS)
#define TYP(r) ((r)&PMAPMASK)
#define PMAP(id, typ) ((id)<<PMAPBITS | ((typ)&PMAPMASK))
#define PMAPID(id) ((id)<<PMAPBITS)
#define PT_NUM 256
struct playerst;
@@ -128,11 +128,6 @@
#define REPLACE_MODE 0x1
#define SPECIFIC_DELETE 0x2
#define ID(r) ((r)>>8)
#define TYP(r) ((r)&0xFF)
#define PMAP(id, typ) ((id)<<8 | ((typ)&0xFF))
#define PMAPID(id) ((id)<<8)
#ifndef SIMULATIONDATA_H
#define SIMULATIONDATA_H
@@ -139,7 +139,7 @@ int Element_ARAY::update(UPDATE_FUNC_ARGS)
{
for (int rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1 - rx1 + 1)
{
int np = sim->create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, parts[r].tmp&0xFF);
int np = sim->create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, TYP(parts[r].tmp));
if (np != -1)
{
parts[np].temp = parts[r].temp;
@@ -84,7 +84,7 @@ int Element_BCLN::update(UPDATE_FUNC_ARGS)
if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_LIFE, parts[i].tmp);
else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0)
{
int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF);
int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, TYP(parts[i].ctype));
if (np>=0)
{
if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA)
@@ -72,7 +72,7 @@ int Element_BOMB::update(UPDATE_FUNC_ARGS)
if ((ynxj < 0) || (ynxj >= YRES) || (xnxi <= 0) || (xnxi >= XRES))
continue;
nt = pmap[ynxj][xnxi]&0xFF;
nt = TYP(pmap[ynxj][xnxi]);
if (nt!=PT_DMND && nt!=PT_CLNE && nt!=PT_PCLN && nt!=PT_BCLN && nt!=PT_VIBR)
{
if (nt)
@@ -89,7 +89,7 @@ int Element_BOMB::update(UPDATE_FUNC_ARGS)
}
for (nxj=-(rad+1); nxj<=(rad+1); nxj++)
for (nxi=-(rad+1); nxi<=(rad+1); nxi++)
if ((pow((float)nxi,2))/(pow((float)(rad+1),2))+(pow((float)nxj,2))/(pow((float)(rad+1),2))<=1 && !(pmap[y+nxj][x+nxi]&0xFF))
if ((pow((float)nxi,2))/(pow((float)(rad+1),2))+(pow((float)nxj,2))/(pow((float)(rad+1),2))<=1 && !TYP(pmap[y+nxj][x+nxi]))
{
nb = sim->create_part(-3, x+nxi, y+nxj, PT_EMBR);
if (nb!=-1)
@@ -75,7 +75,7 @@ int Element_CLNE::update(UPDATE_FUNC_ARGS)
if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_LIFE, parts[i].tmp);
else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0)
{
int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF);
int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, TYP(parts[i].ctype));
if (np>=0)
{
if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA)
@@ -48,7 +48,7 @@ Element_CONV::Element_CONV()
int Element_CONV::update(UPDATE_FUNC_ARGS)
{
int r, rx, ry;
int ctype = parts[i].ctype&0xFF, ctypeExtra = ID(parts[i].ctype);
int ctype = TYP(parts[i].ctype), ctypeExtra = ID(parts[i].ctype);
if (ctype<=0 || ctype>=PT_NUM || !sim->elements[ctype].Enabled || ctype==PT_CONV || (ctype==PT_LIFE && (ctypeExtra<0 || ctypeExtra>=NGOL)))
{
for (rx=-1; rx<2; rx++)
@@ -86,7 +86,7 @@ int Element_CONV::update(UPDATE_FUNC_ARGS)
continue;
if (TYP(r) != PT_CONV && TYP(r) != PT_DMND && TYP(r) != ctype)
{
sim->create_part(ID(r), x+rx, y+ry, parts[i].ctype&0xFF, ID(parts[i].ctype));
sim->create_part(ID(r), x+rx, y+ry, TYP(parts[i].ctype), ID(parts[i].ctype));
}
}
}
@@ -49,7 +49,7 @@ int Element_CRAY::update(UPDATE_FUNC_ARGS)
{
int nxx, nyy, docontinue, nxi, nyi;
// set ctype to things that touch it if it doesn't have one already
if (parts[i].ctype<=0 || !sim->elements[parts[i].ctype&0xFF].Enabled)
if (parts[i].ctype<=0 || !sim->elements[TYP(parts[i].ctype)].Enabled)
{
for (int rx = -1; rx <= 1; rx++)
for (int ry = -1; ry <= 1; ry++)
@@ -91,8 +91,8 @@ int Element_CRAY::update(UPDATE_FUNC_ARGS)
break;
}
r = pmap[y+nyi+nyy][x+nxi+nxx];
if (!sim->IsWallBlocking(x+nxi+nxx, y+nyi+nyy, parts[i].ctype&0xFF) && (!sim->pmap[y+nyi+nyy][x+nxi+nxx] || createSpark)) { // create, also set color if it has passed through FILT
int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, parts[i].ctype&0xFF, ID(parts[i].ctype));
if (!sim->IsWallBlocking(x+nxi+nxx, y+nyi+nyy, TYP(parts[i].ctype)) && (!sim->pmap[y+nyi+nyy][x+nxi+nxx] || createSpark)) { // create, also set color if it has passed through FILT
int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, TYP(parts[i].ctype), ID(parts[i].ctype));
if (nr!=-1) {
if (colored)
parts[nr].dcolour = colored;
@@ -54,7 +54,7 @@ bool InBounds(int x, int y)
//#TPT-Directive ElementHeader Element_DRAY static int update(UPDATE_FUNC_ARGS)
int Element_DRAY::update(UPDATE_FUNC_ARGS)
{
int ctype = parts[i].ctype&0xFF, ctypeExtra = ID(parts[i].ctype), copyLength = parts[i].tmp, copySpaces = parts[i].tmp2;
int ctype = TYP(parts[i].ctype), ctypeExtra = ID(parts[i].ctype), copyLength = parts[i].tmp, copySpaces = parts[i].tmp2;
if (copySpaces < 0)
copySpaces = parts[i].tmp2 = 0;
if (copyLength < 0)
@@ -106,7 +106,7 @@ int Element_DRAY::update(UPDATE_FUNC_ARGS)
// 1: if .tmp isn't set, and the element in this spot is the ctype, then stop
// 2: if .tmp is set, stop when the length limit reaches 0
// 3. Stop when we are out of bounds
if ((!copyLength && (rr&0xFF) == ctype && (ctype != PT_LIFE || parts[ID(rr)].ctype == ctypeExtra))
if ((!copyLength && TYP(rr) == ctype && (ctype != PT_LIFE || parts[ID(rr)].ctype == ctypeExtra))
|| !(--partsRemaining && InBounds(xCurrent+xStep, yCurrent+yStep)))
{
copyLength -= partsRemaining;
@@ -123,9 +123,9 @@ int Element_DRAY::update(UPDATE_FUNC_ARGS)
{
// get particle to copy
if (isEnergy)
type = sim->photons[yCurrent][xCurrent]&0xFF;
type = TYP(sim->photons[yCurrent][xCurrent]);
else
type = pmap[yCurrent][xCurrent]&0xFF;
type = TYP(pmap[yCurrent][xCurrent]);
// if sparked by PSCN, overwrite whatever is in the target location, instead of just ignoring it
if (overwrite)
@@ -53,7 +53,7 @@ int Element_DSTW::update(UPDATE_FUNC_ARGS)
if (BOUNDS_CHECK && (rx || ry))
{
r = pmap[y+ry][x+rx];
switch (r&0xFF)
switch (TYP(r))
{
case PT_SALT:
if (!(rand()%50))
@@ -135,7 +135,7 @@ int Element_EMP::Trigger(Simulation *sim, int triggerCount)
int n = sim->pmap[ry+ny][rx+nx];
if (!n)
continue;
int ntype = n&0xFF;
int ntype = TYP(n);
n = ID(n);
//Some elements should only be affected by wire/swch, or by a spark on inst/semiconductor
//So not affected by spark on metl, watr etc
@@ -87,7 +87,7 @@ int Element_GOLD::update(UPDATE_FUNC_ARGS)
}
}
}
if ((sim->photons[y][x]&0xFF) == PT_NEUT)
if (TYP(sim->photons[y][x]) == PT_NEUT)
{
if (!(rand()%7))
{
@@ -115,7 +115,7 @@ int Element_H2::update(UPDATE_FUNC_ARGS)
parts[j].temp = temp;
parts[j].tmp = 0x1;
}
rx = x+rand()%3-1, ry = y+rand()%3-1, rt = pmap[ry][rx]&0xFF;
rx = x+rand()%3-1, ry = y+rand()%3-1, rt = TYP(pmap[ry][rx]);
if (sim->can_move[PT_PLSM][rt] || rt == PT_H2)
{
j = sim->create_part(-3,rx,ry,PT_PLSM);
@@ -52,7 +52,7 @@ Element_HEAC::Element_HEAC()
struct Element_HEAC::IsInsulator : public std::binary_function<Simulation*,int,bool> {
bool operator() (Simulation* a, int b)
{
return b && (a->elements[b&0xFF].HeatConduct == 0 || ((b&0xFF) == PT_HSWC && a->parts[ID(b)].life != 10));
return b && (a->elements[TYP(b)].HeatConduct == 0 || (TYP(b) == PT_HSWC && a->parts[ID(b)].life != 10));
}
};
//#TPT-Directive ElementHeader Element_HEAC static IsInsulator isInsulator
@@ -73,7 +73,7 @@ int Element_NBLE::update(UPDATE_FUNC_ARGS)
parts[j].temp = temp;
parts[j].tmp = 0x1;
}
int rx = x+rand()%3-1, ry = y+rand()%3-1, rt = pmap[ry][rx]&0xFF;
int rx = x+rand()%3-1, ry = y+rand()%3-1, rt = TYP(pmap[ry][rx]);
if (sim->can_move[PT_PLSM][rt] || rt == PT_NBLE)
{
j = sim->create_part(-3,rx,ry,PT_PLSM);
@@ -55,7 +55,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS)
if (BOUNDS_CHECK)
{
r = pmap[y+ry][x+rx];
switch (r&0xFF)
switch (TYP(r))
{
case PT_WATR:
if (3>(rand()%20))
@@ -90,7 +90,7 @@ int Element_O2::update(UPDATE_FUNC_ARGS)
parts[j].temp = MAX_TEMP;
parts[j].tmp = 0x1;
}
rx = x+rand()%3-1, ry = y+rand()%3-1, r = pmap[ry][rx]&0xFF;
rx = x+rand()%3-1, ry = y+rand()%3-1, r = TYP(pmap[ry][rx]);
if (sim->can_move[PT_PLSM][r] || r == PT_O2)
{
j = sim->create_part(-3,rx,ry,PT_PLSM);
@@ -134,7 +134,7 @@ int Element_PBCN::update(UPDATE_FUNC_ARGS)
else if (parts[i].ctype!=PT_LIGH || !(rand()%30))
{
int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF);
int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, TYP(parts[i].ctype));
if (np>-1)
{
if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA)
@@ -125,7 +125,7 @@ int Element_PCLN::update(UPDATE_FUNC_ARGS)
else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0)
{
int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF);
int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, TYP(parts[i].ctype));
if (np>=0)
{
if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA)
@@ -75,8 +75,8 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS)
{
int r, rx, ry, np;
int rnd, rndstore;
if ((parts[i].tmp&0xFF)>=PT_NUM || !sim->elements[parts[i].tmp&0xFF].Enabled)
parts[i].tmp &= ~0xFF;
if (TYP(parts[i].tmp)>=PT_NUM || !sim->elements[TYP(parts[i].tmp)].Enabled)
parts[i].tmp &= ~PMAPMASK;
if (parts[i].tmp & PPIP_TMPFLAG_TRIGGERS)
{
int pause_changed = 0;
@@ -193,23 +193,23 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx];
if(!r)
r = sim->photons[y+ry][x+rx];
if (surround_space && !r && (parts[i].tmp&0xFF)!=0) //creating at end
if (surround_space && !r && TYP(parts[i].tmp)!=0) //creating at end
{
np = sim->create_part(-1,x+rx,y+ry,parts[i].tmp&0xFF);
np = sim->create_part(-1, x+rx, y+ry, TYP(parts[i].tmp));
if (np!=-1)
{
transfer_pipe_to_part(sim, parts+i, parts+np);
}
}
//try eating particle at entrance
else if ((parts[i].tmp&0xFF) == 0 && (sim->elements[TYP(r)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)))
else if (TYP(parts[i].tmp) == 0 && (sim->elements[TYP(r)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)))
{
if (TYP(r)==PT_SOAP)
Element_SOAP::detach(sim, ID(r));
transfer_part_to_pipe(parts+(ID(r)), parts+i);
sim->kill_part(ID(r));
}
else if ((parts[i].tmp&0xFF) == 0 && TYP(r)==PT_STOR && parts[ID(r)].tmp>0 && sim->IsValidElement(parts[ID(r)].tmp) && (sim->elements[parts[ID(r)].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)))
else if (TYP(parts[i].tmp) == 0 && TYP(r)==PT_STOR && parts[ID(r)].tmp>0 && sim->IsValidElement(parts[ID(r)].tmp) && (sim->elements[parts[ID(r)].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)))
{
// STOR stores properties in the same places as PIPE does
transfer_pipe_to_pipe(parts+(ID(r)), parts+i);
@@ -278,7 +278,7 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS)
//#TPT-Directive ElementHeader Element_PIPE static int graphics(GRAPHICS_FUNC_ARGS)
int Element_PIPE::graphics(GRAPHICS_FUNC_ARGS)
{
int t = cpart->tmp & 0xFF;
int t = TYP(cpart->tmp);
if (t>0 && t<PT_NUM && ren->sim->elements[t].Enabled)
{
if (t == PT_STKM || t == PT_STKM2 || t == PT_FIGH)
@@ -318,9 +318,9 @@ int Element_PIPE::graphics(GRAPHICS_FUNC_ARGS)
Element::defaultGraphics(ren, &tpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb);
}
}
//*colr = PIXR(elements[cpart->tmp&0xFF].pcolors);
//*colg = PIXG(elements[cpart->tmp&0xFF].pcolors);
//*colb = PIXB(elements[cpart->tmp&0xFF].pcolors);
//*colr = PIXR(elements[t].pcolors);
//*colg = PIXG(elements[t].pcolors);
//*colb = PIXB(elements[t].pcolors);
}
else
{
@@ -350,12 +350,12 @@ int Element_PIPE::graphics(GRAPHICS_FUNC_ARGS)
//#TPT-Directive ElementHeader Element_PIPE static void transfer_pipe_to_part(Simulation * sim, Particle *pipe, Particle *part)
void Element_PIPE::transfer_pipe_to_part(Simulation * sim, Particle *pipe, Particle *part)
{
part->type = (pipe->tmp & 0xFF);
part->type = TYP(pipe->tmp);
part->temp = pipe->temp;
part->life = pipe->tmp2;
part->tmp = pipe->pavg[0];
part->ctype = pipe->pavg[1];
pipe->tmp &= ~0xFF;
pipe->tmp &= ~PMAPMASK;
if (!(sim->elements[part->type].Properties & TYPE_ENERGY))
{
@@ -372,7 +372,7 @@ void Element_PIPE::transfer_pipe_to_part(Simulation * sim, Particle *pipe, Parti
//#TPT-Directive ElementHeader Element_PIPE static void transfer_part_to_pipe(Particle *part, Particle *pipe)
void Element_PIPE::transfer_part_to_pipe(Particle *part, Particle *pipe)
{
pipe->tmp = (pipe->tmp&~0xFF) | part->type;
pipe->tmp = (pipe->tmp&~PMAPMASK) | part->type;
pipe->temp = part->temp;
pipe->tmp2 = part->life;
pipe->pavg[0] = part->tmp;
@@ -382,19 +382,19 @@ void Element_PIPE::transfer_part_to_pipe(Particle *part, Particle *pipe)
//#TPT-Directive ElementHeader Element_PIPE static void transfer_pipe_to_pipe(Particle *src, Particle *dest)
void Element_PIPE::transfer_pipe_to_pipe(Particle *src, Particle *dest)
{
dest->tmp = (dest->tmp&~0xFF) | (src->tmp&0xFF);
dest->tmp = (dest->tmp&~PMAPMASK) | TYP(src->tmp);
dest->temp = src->temp;
dest->tmp2 = src->tmp2;
dest->pavg[0] = src->pavg[0];
dest->pavg[1] = src->pavg[1];
src->tmp &= ~0xFF;
src->tmp &= ~PMAPMASK;
}
//#TPT-Directive ElementHeader Element_PIPE static void pushParticle(Simulation * sim, int i, int count, int original)
void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original)
{
int rndstore, rnd, rx, ry, r, x, y, np, q, notctype=(((sim->parts[i].ctype)%3)+2);
if ((sim->parts[i].tmp&0xFF) == 0 || count >= 2)//don't push if there is nothing there, max speed of 2 per frame
if (TYP(sim->parts[i].tmp) == 0 || count >= 2)//don't push if there is nothing there, max speed of 2 per frame
return;
x = (int)(sim->parts[i].x+0.5f);
y = (int)(sim->parts[i].y+0.5f);
@@ -415,7 +415,7 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original
r = sim->pmap[y+ry][x+rx];
if (!r)
continue;
else if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && sim->parts[ID(r)].ctype!=notctype && (sim->parts[ID(r)].tmp&0xFF)==0)
else if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && sim->parts[ID(r)].ctype!=notctype && TYP(sim->parts[ID(r)].tmp)==0)
{
transfer_pipe_to_pipe(sim->parts+i, sim->parts+(ID(r)));
if (ID(r) > original)
@@ -445,7 +445,7 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original
{
int coords = 7 - ((sim->parts[i].tmp>>10)&7);
r = sim->pmap[y+ pos_1_ry[coords]][x+ pos_1_rx[coords]];
if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && sim->parts[ID(r)].ctype!=notctype && (sim->parts[ID(r)].tmp&0xFF)==0)
if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && sim->parts[ID(r)].ctype!=notctype && TYP(sim->parts[ID(r)].tmp)==0)
{
transfer_pipe_to_pipe(sim->parts+i, sim->parts+(ID(r)));
if (ID(r) > original)
@@ -468,11 +468,11 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original
break;
}
}
else if (TYP(r) == PT_NONE) //Move particles out of pipe automatically, much faster at ends
else if (!r) //Move particles out of pipe automatically, much faster at ends
{
rx = pos_1_rx[coords];
ry = pos_1_ry[coords];
np = sim->create_part(-1,x+rx,y+ry,sim->parts[i].tmp&0xFF);
np = sim->create_part(-1,x+rx,y+ry,TYP(sim->parts[i].tmp));
if (np!=-1)
{
transfer_pipe_to_part(sim, sim->parts+i, sim->parts+np);
@@ -48,16 +48,18 @@ Element_PLNT::Element_PLNT()
Graphics = &Element_PLNT::graphics;
}
#include <iostream>
//#TPT-Directive ElementHeader Element_PLNT static int update(UPDATE_FUNC_ARGS)
int Element_PLNT::update(UPDATE_FUNC_ARGS)
{
int r, rx, ry, np, rndstore;
std::cout << PMAPBITS << ", " << PMAPMASK << std::endl;
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
if (BOUNDS_CHECK && (rx || ry))
{
r = pmap[y+ry][x+rx];
switch (r&0xFF)
switch (TYP(r))
{
case PT_WATR:
if (!(rand()%50))
Oops, something went wrong.

0 comments on commit da45e0e

Please sign in to comment.