Skip to content

Commit

Permalink
use macros for the rest of the necessary >>8/<<8 in src/simulation/el…
Browse files Browse the repository at this point in the history
…ements
  • Loading branch information
jacob1 committed Dec 28, 2017
1 parent ac24810 commit 4b1c929
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/simulation/elements/BANG.cpp
Expand Up @@ -69,7 +69,7 @@ int Element_BANG::update(UPDATE_FUNC_ARGS)
}
else if(parts[i].tmp==1)
{
if ((pmap[y][x]>>8 == i))
if ((ID(pmap[y][x]) == i))
{
PropertyValue value;
value.Integer = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/BOMB.cpp
Expand Up @@ -76,7 +76,7 @@ int Element_BOMB::update(UPDATE_FUNC_ARGS)
if (nt!=PT_DMND && nt!=PT_CLNE && nt!=PT_PCLN && nt!=PT_BCLN && nt!=PT_VIBR)
{
if (nt)
sim->kill_part(pmap[ynxj][xnxi]>>8);
sim->kill_part(ID(pmap[ynxj][xnxi]));
sim->pv[(ynxj)/CELL][(xnxi)/CELL] += 0.1f;
nb = sim->create_part(-3, xnxi, ynxj, PT_EMBR);
if (nb!=-1)
Expand Down
6 changes: 3 additions & 3 deletions src/simulation/elements/CONV.cpp
Expand Up @@ -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 = parts[i].ctype>>8;
int ctype = parts[i].ctype&0xFF, 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++)
Expand All @@ -67,7 +67,7 @@ int Element_CONV::update(UPDATE_FUNC_ARGS)
{
parts[i].ctype = r&0xFF;
if ((r&0xFF)==PT_LIFE)
parts[i].ctype |= (parts[ID(r)].ctype << 8);
parts[i].ctype |= PMAPID(parts[ID(r)].ctype);
}
}
}
Expand All @@ -85,7 +85,7 @@ int Element_CONV::update(UPDATE_FUNC_ARGS)
continue;
if((r&0xFF)!=PT_CONV && (r&0xFF)!=PT_DMND && (r&0xFF)!=ctype)
{
sim->create_part(ID(r), x+rx, y+ry, parts[i].ctype&0xFF, parts[i].ctype>>8);
sim->create_part(ID(r), x+rx, y+ry, parts[i].ctype&0xFF, ID(parts[i].ctype));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/CRAY.cpp
Expand Up @@ -92,7 +92,7 @@ int Element_CRAY::update(UPDATE_FUNC_ARGS)
}
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, parts[i].ctype>>8);
int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, parts[i].ctype&0xFF, ID(parts[i].ctype));
if (nr!=-1) {
if (colored)
parts[nr].dcolour = colored;
Expand Down
20 changes: 10 additions & 10 deletions src/simulation/elements/DMG.cpp
Expand Up @@ -75,29 +75,29 @@ int Element_DMG::update(UPDATE_FUNC_ARGS)
angle = atan2((float)nxj, nxi);
fx = cos(angle) * 7.0f;
fy = sin(angle) * 7.0f;
parts[rr>>8].vx += fx;
parts[rr>>8].vy += fy;
parts[ID(rr)].vx += fx;
parts[ID(rr)].vy += fy;
sim->vx[(y+nxj)/CELL][(x+nxi)/CELL] += fx;
sim->vy[(y+nxj)/CELL][(x+nxi)/CELL] += fy;
sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 1.0f;
t = rr&0xFF;
if (t && sim->elements[t].HighPressureTransition>-1 && sim->elements[t].HighPressureTransition<PT_NUM)
sim->part_change_type(rr>>8, x+nxi, y+nxj, sim->elements[t].HighPressureTransition);
sim->part_change_type(ID(rr), x+nxi, y+nxj, sim->elements[t].HighPressureTransition);
else if (t == PT_BMTL)
sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_BRMT);
sim->part_change_type(ID(rr), x+nxi, y+nxj, PT_BRMT);
else if (t == PT_GLAS)
sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_BGLA);
sim->part_change_type(ID(rr), x+nxi, y+nxj, PT_BGLA);
else if (t == PT_COAL)
sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_BCOL);
sim->part_change_type(ID(rr), x+nxi, y+nxj, PT_BCOL);
else if (t == PT_QRTZ)
sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_PQRT);
sim->part_change_type(ID(rr), x+nxi, y+nxj, PT_PQRT);
else if (t == PT_TUNG)
{
sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_BRMT);
parts[rr>>8].ctype = PT_TUNG;
sim->part_change_type(ID(rr), x+nxi, y+nxj, PT_BRMT);
parts[ID(rr)].ctype = PT_TUNG;
}
else if (t == PT_WOOD)
sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_SAWD);
sim->part_change_type(ID(rr), x+nxi, y+nxj, PT_SAWD);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/simulation/elements/DRAY.cpp
Expand Up @@ -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 = parts[i].ctype>>8, copyLength = parts[i].tmp, copySpaces = parts[i].tmp2;
int ctype = parts[i].ctype&0xFF, ctypeExtra = ID(parts[i].ctype), copyLength = parts[i].tmp, copySpaces = parts[i].tmp2;
if (copySpaces < 0)
copySpaces = parts[i].tmp2 = 0;
if (copyLength < 0)
Expand Down Expand Up @@ -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[rr>>8].ctype == ctypeExtra))
if ((!copyLength && (rr&0xFF) == ctype && (ctype != PT_LIFE || parts[ID(rr)].ctype == ctypeExtra))
|| !(--partsRemaining && InBounds(xCurrent+xStep, yCurrent+yStep)))
{
copyLength -= partsRemaining;
Expand All @@ -133,12 +133,12 @@ int Element_DRAY::update(UPDATE_FUNC_ARGS)
if (isEnergy)
{
if (sim->photons[yCopyTo][xCopyTo])
sim->kill_part(sim->photons[yCopyTo][xCopyTo]>>8);
sim->kill_part(ID(sim->photons[yCopyTo][xCopyTo]));
}
else
{
if (pmap[yCopyTo][xCopyTo])
sim->kill_part(pmap[yCopyTo][xCopyTo]>>8);
sim->kill_part(ID(pmap[yCopyTo][xCopyTo]));
}
}
if (type == PT_SPRK) // spark hack
Expand All @@ -154,9 +154,9 @@ int Element_DRAY::update(UPDATE_FUNC_ARGS)
if (type == PT_SPRK) // spark hack
sim->part_change_type(p, xCopyTo, yCopyTo, PT_SPRK);
if (isEnergy)
parts[p] = parts[sim->photons[yCurrent][xCurrent]>>8];
parts[p] = parts[ID(sim->photons[yCurrent][xCurrent])];
else
parts[p] = parts[pmap[yCurrent][xCurrent]>>8];
parts[p] = parts[ID(pmap[yCurrent][xCurrent])];
parts[p].x = xCopyTo;
parts[p].y = yCopyTo;
}
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/EMP.cpp
Expand Up @@ -136,7 +136,7 @@ int Element_EMP::Trigger(Simulation *sim, int triggerCount)
if (!n)
continue;
int ntype = n&0xFF;
n = n >> 8;
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
if (is_elec)
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/GOLD.cpp
Expand Up @@ -91,7 +91,7 @@ int Element_GOLD::update(UPDATE_FUNC_ARGS)
{
if (!(rand()%7))
{
sim->kill_part(sim->photons[y][x]>>8);
sim->kill_part(ID(sim->photons[y][x]));
}
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/HEAC.cpp
Expand Up @@ -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[b>>8].life != 10));
return b && (a->elements[b&0xFF].HeatConduct == 0 || ((b&0xFF) == PT_HSWC && a->parts[ID(b)].life != 10));
}
};
//#TPT-Directive ElementHeader Element_HEAC static IsInsulator isInsulator
Expand Down
10 changes: 5 additions & 5 deletions src/simulation/elements/PPIP.cpp
Expand Up @@ -83,7 +83,7 @@ void Element_PPIP::flood_trigger(Simulation * sim, int x, int y, int sparkedBy)
else if (sparkedBy==PT_NSCN) prop = PPIP_TMPFLAG_TRIGGER_OFF << 3;
else if (sparkedBy==PT_INST) prop = PPIP_TMPFLAG_TRIGGER_REVERSE << 3;

if (prop==0 || (pmap[y][x]&0xFF)!=PT_PPIP || (parts[pmap[y][x]>>8].tmp & prop))
if (prop==0 || (pmap[y][x]&0xFF)!=PT_PPIP || (parts[ID(pmap[y][x])].tmp & prop))
return;

coord_stack = new unsigned short[coord_stack_limit][2];
Expand Down Expand Up @@ -118,17 +118,17 @@ void Element_PPIP::flood_trigger(Simulation * sim, int x, int y, int sparkedBy)
// fill span
for (x=x1; x<=x2; x++)
{
if (!(parts[pmap[y][x]>>8].tmp & prop))
if (!(parts[ID(pmap[y][x])].tmp & prop))
ppip_changed = 1;
parts[pmap[y][x]>>8].tmp |= prop;
parts[ID(pmap[y][x])].tmp |= prop;
}

// add adjacent pixels to stack
// +-1 to x limits to include diagonally adjacent pixels
// Don't need to check x bounds here, because already limited to [CELL, XRES-CELL]
if (y>=CELL+1)
for (x=x1-1; x<=x2+1; x++)
if ((pmap[y-1][x]&0xFF)==PT_PPIP && !(parts[pmap[y-1][x]>>8].tmp & prop))
if ((pmap[y-1][x]&0xFF)==PT_PPIP && !(parts[ID(pmap[y-1][x])].tmp & prop))
{
coord_stack[coord_stack_size][0] = x;
coord_stack[coord_stack_size][1] = y-1;
Expand All @@ -141,7 +141,7 @@ void Element_PPIP::flood_trigger(Simulation * sim, int x, int y, int sparkedBy)
}
if (y<YRES-CELL-1)
for (x=x1-1; x<=x2+1; x++)
if ((pmap[y+1][x]&0xFF)==PT_PPIP && !(parts[pmap[y+1][x]>>8].tmp & prop))
if ((pmap[y+1][x]&0xFF)==PT_PPIP && !(parts[ID(pmap[y+1][x])].tmp & prop))
{
coord_stack[coord_stack_size][0] = x;
coord_stack[coord_stack_size][1] = y+1;
Expand Down
39 changes: 20 additions & 19 deletions src/simulation/elements/PROT.cpp
Expand Up @@ -51,38 +51,39 @@ int Element_PROT::update(UPDATE_FUNC_ARGS)
sim->pv[y/CELL][x/CELL] -= .003f;
int under = pmap[y][x];
int utype = under & 0xFF;
int uID = ID(under);
switch (utype)
{
case PT_SPRK:
{
//remove active sparks
int sparked = parts[under>>8].ctype;
int sparked = parts[uID].ctype;
if (sparked > 0 && sparked < PT_NUM && sim->elements[sparked].Enabled)
{
sim->part_change_type(under>>8, x, y, sparked);
parts[under>>8].life = 44 + parts[under>>8].life;
parts[under>>8].ctype = 0;
sim->part_change_type(uID, x, y, sparked);
parts[uID].life = 44 + parts[uID].life;
parts[uID].ctype = 0;
}
break;
}
case PT_DEUT:
if ((-((int)sim->pv[y / CELL][x / CELL] - 4) + (parts[under>>8].life / 100)) > rand() % 200)
if ((-((int)sim->pv[y / CELL][x / CELL] - 4) + (parts[uID].life / 100)) > rand() % 200)
{
DeutImplosion(sim, parts[under>>8].life, x, y, restrict_flt(parts[under>>8].temp + parts[under>>8].life * 500, MIN_TEMP, MAX_TEMP), PT_PROT);
sim->kill_part(under>>8);
DeutImplosion(sim, parts[uID].life, x, y, restrict_flt(parts[uID].temp + parts[uID].life * 500, MIN_TEMP, MAX_TEMP), PT_PROT);
sim->kill_part(uID);
}
break;
case PT_LCRY:
//Powered LCRY reaction: PROT->PHOT
if (parts[under>>8].life > 5 && !(rand() % 10))
if (parts[uID].life > 5 && !(rand() % 10))
{
sim->part_change_type(i, x, y, PT_PHOT);
parts[i].life *= 2;
parts[i].ctype = 0x3FFFFFFF;
}
break;
case PT_EXOT:
parts[under>>8].ctype = PT_PROT;
parts[uID].ctype = PT_PROT;
break;
case PT_WIFI:
float change;
Expand All @@ -91,7 +92,7 @@ int Element_PROT::update(UPDATE_FUNC_ARGS)
else if (parts[i].temp > 473.15f) change = 1000.0f;
else if (parts[i].temp > 373.15f) change = 100.0f;
else change = 0.0f;
parts[under>>8].temp = restrict_flt(parts[under>>8].temp + change, MIN_TEMP, MAX_TEMP);
parts[uID].temp = restrict_flt(parts[uID].temp + change, MIN_TEMP, MAX_TEMP);
break;
case PT_NONE:
//slowly kill if it's not inside an element
Expand All @@ -105,20 +106,20 @@ int Element_PROT::update(UPDATE_FUNC_ARGS)
//set off explosives (only when hot because it wasn't as fun when it made an entire save explode)
if (parts[i].temp > 273.15f + 500.0f && (sim->elements[utype].Flammable || sim->elements[utype].Explosive || utype == PT_BANG))
{
sim->create_part(under>>8, x, y, PT_FIRE);
parts[under>>8].temp += restrict_flt(sim->elements[utype].Flammable * 5, MIN_TEMP, MAX_TEMP);
sim->create_part(uID, x, y, PT_FIRE);
parts[uID].temp += restrict_flt(sim->elements[utype].Flammable * 5, MIN_TEMP, MAX_TEMP);
sim->pv[y / CELL][x / CELL] += 1.00f;
}
//prevent inactive sparkable elements from being sparked
else if ((sim->elements[utype].Properties&PROP_CONDUCTS) && parts[under>>8].life <= 4)
else if ((sim->elements[utype].Properties&PROP_CONDUCTS) && parts[uID].life <= 4)
{
parts[under>>8].life = 40 + parts[under>>8].life;
parts[uID].life = 40 + parts[uID].life;
}
break;
}
//make temp of other things closer to it's own temperature. This will change temp of things that don't conduct, and won't change the PROT's temperature
if (utype && utype != PT_WIFI)
parts[under>>8].temp = restrict_flt(parts[under>>8].temp-(parts[under>>8].temp-parts[i].temp)/4.0f, MIN_TEMP, MAX_TEMP);
parts[uID].temp = restrict_flt(parts[uID].temp-(parts[uID].temp-parts[i].temp)/4.0f, MIN_TEMP, MAX_TEMP);


//if this proton has collided with another last frame, change it into a heavier element
Expand Down Expand Up @@ -149,17 +150,17 @@ int Element_PROT::update(UPDATE_FUNC_ARGS)
}
//collide with other protons to make heavier materials
int ahead = sim->photons[y][x];
if ((ahead>>8) != i && (ahead&0xFF) == PT_PROT)
if (ID(ahead) != i && (ahead&0xFF) == PT_PROT)
{
float velocity1 = powf(parts[i].vx, 2.0f)+powf(parts[i].vy, 2.0f);
float velocity2 = powf(parts[ahead>>8].vx, 2.0f)+powf(parts[ahead>>8].vy, 2.0f);
float velocity2 = powf(parts[ID(ahead)].vx, 2.0f)+powf(parts[ID(ahead)].vy, 2.0f);
float direction1 = atan2f(-parts[i].vy, parts[i].vx);
float direction2 = atan2f(-parts[ahead>>8].vy, parts[ahead>>8].vx);
float direction2 = atan2f(-parts[ID(ahead)].vy, parts[ID(ahead)].vx);
float difference = direction1 - direction2; if (difference < 0) difference += 6.28319f;

if (difference > 3.12659f && difference < 3.15659f && velocity1 + velocity2 > 10.0f)
{
parts[ahead>>8].tmp += (int)(velocity1 + velocity2);
parts[ID(ahead)].tmp += (int)(velocity1 + velocity2);
sim->kill_part(i);
return 1;
}
Expand Down
14 changes: 7 additions & 7 deletions src/simulation/elements/PSTN.cpp
Expand Up @@ -263,26 +263,26 @@ int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int direct
for(int c = 1; c < maxRight; c++) {
posY = stackY + (c*newY);
posX = stackX + (c*newX);
MoveStack(sim, posX, posY, directionX, directionY, maxSize, amount, retract, block, !sim->parts[sim->pmap[posY][posX]>>8].tmp, 1);
MoveStack(sim, posX, posY, directionX, directionY, maxSize, amount, retract, block, !sim->parts[ID(sim->pmap[posY][posX])].tmp, 1);
}
for(int c = 1; c < maxLeft; c++) {
posY = stackY - (c*newY);
posX = stackX - (c*newX);
MoveStack(sim, posX, posY, directionX, directionY, maxSize, amount, retract, block, !sim->parts[sim->pmap[posY][posX]>>8].tmp, 1);
MoveStack(sim, posX, posY, directionX, directionY, maxSize, amount, retract, block, !sim->parts[ID(sim->pmap[posY][posX])].tmp, 1);
}

//Remove arm section if retracting with FRME
if (retract)
for(int j = 1; j <= amount; j++)
sim->kill_part(sim->pmap[stackY+(directionY*-j)][stackX+(directionX*-j)]>>8);
return MoveStack(sim, stackX, stackY, directionX, directionY, maxSize, amount, retract, block, !sim->parts[sim->pmap[stackY][stackX]>>8].tmp, 1);
sim->kill_part(ID(sim->pmap[stackY+(directionY*-j)][stackX+(directionX*-j)]));
return MoveStack(sim, stackX, stackY, directionX, directionY, maxSize, amount, retract, block, !sim->parts[ID(sim->pmap[stackY][stackX])].tmp, 1);
}
if(retract){
bool foundParts = false;
//Remove arm section if retracting without FRME
if (!callDepth)
for(int j = 1; j <= amount; j++)
sim->kill_part(sim->pmap[stackY+(directionY*-j)][stackX+(directionX*-j)]>>8);
sim->kill_part(ID(sim->pmap[stackY+(directionY*-j)][stackX+(directionX*-j)]));
int currentPos = 0;
for(posX = stackX, posY = stackY; currentPos < maxSize && currentPos < XRES-1; posX += directionX, posY += directionY) {
if (!(posX < XRES && posY < YRES && posX >= 0 && posY >= 0)) {
Expand All @@ -305,7 +305,7 @@ int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int direct
sim->pmap[srcY][srcX] = 0;
sim->parts[jP].x = destX;
sim->parts[jP].y = destY;
sim->pmap[destY][destX] = sim->parts[jP].type|(jP<<8);
sim->pmap[destY][destX] = PMAP(jP, sim->parts[jP].type);
}
return amount;
}
Expand All @@ -328,7 +328,7 @@ int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int direct
sim->pmap[srcY][srcX] = 0;
sim->parts[jP].x = destX;
sim->parts[jP].y = destY;
sim->pmap[destY][destX] = sim->parts[jP].type|(jP<<8);
sim->pmap[destY][destX] = PMAP(jP, sim->parts[jP].type);
}
return possibleMovement;
}
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/SHLD1.cpp
Expand Up @@ -68,7 +68,7 @@ int Element_SHLD1::update(UPDATE_FUNC_ARGS)
if (!pmap[y+ry+nny][x+rx+nnx])
{
sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1);
//parts[pmap[y+ny+nny][x+nx+nnx]>>8].life=7;
//parts[ID(pmap[y+ny+nny][x+nx+nnx])].life=7;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/SWCH.cpp
Expand Up @@ -47,7 +47,7 @@ Element_SWCH::Element_SWCH()

bool isRedBRAY(UPDATE_FUNC_ARGS, int xc, int yc)
{
return (pmap[yc][xc]&0xFF) == PT_BRAY && parts[pmap[yc][xc]>>8].tmp == 2;
return (pmap[yc][xc]&0xFF) == PT_BRAY && parts[ID(pmap[yc][xc])].tmp == 2;
}

//#TPT-Directive ElementHeader Element_SWCH static int update(UPDATE_FUNC_ARGS)
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/WARP.cpp
Expand Up @@ -75,7 +75,7 @@ int Element_WARP::update(UPDATE_FUNC_ARGS)
parts[ID(r)].vy = (rand()%4)-2;
parts[i].life += 4;
pmap[y][x] = r;
pmap[y+ry][x+rx] = (i<<8)|parts[i].type;
pmap[y+ry][x+rx] = PMAP(i, parts[i].type);
trade = 5;
}
}
Expand Down

0 comments on commit 4b1c929

Please sign in to comment.