diff --git a/src/simulation/Elements.h b/src/simulation/Elements.h index b05ca5010..bcd5ab576 100644 --- a/src/simulation/Elements.h +++ b/src/simulation/Elements.h @@ -52,13 +52,13 @@ // 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 PMAPMASK ((1<>PMAPBITS) #define TYP(r) ((r)&PMAPMASK) #define PMAP(id, typ) ((id)<>8].type]--; - parts[r>>8] = tempPart; - i = r>>8; + elementCount[parts[ID(r)].type]--; + parts[ID(r)] = tempPart; + i = ID(r); elementCount[tempPart.type]++; } else if ((r = photons[y][x])) { - elementCount[parts[r>>8].type]--; - parts[r>>8] = tempPart; - i = r>>8; + elementCount[parts[ID(r)].type]--; + parts[ID(r)] = tempPart; + i = ID(r); elementCount[tempPart.type]++; } //Allocate new particle @@ -499,9 +499,9 @@ bool Simulation::FloodFillPmapCheck(int x, int y, int type) if (type == 0) return !pmap[y][x] && !photons[y][x]; if (elements[type].Properties&TYPE_ENERGY) - return (photons[y][x]&0xFF) == type; + return TYP(photons[y][x]) == type; else - return (pmap[y][x]&0xFF) == type; + return TYP(pmap[y][x]) == type; } int Simulation::flood_prop(int x, int y, size_t propoffset, PropertyValue propvalue, StructProperty::PropertyType proptype) @@ -513,7 +513,7 @@ int Simulation::flood_prop(int x, int y, size_t propoffset, PropertyValue propva r = photons[y][x]; if (!r) return 0; - int parttype = (r&0xFF); + int parttype = TYP(r); char * bitmap = (char*)malloc(XRES*YRES); //Bitmap for checking if (!bitmap) return -1; memset(bitmap, 0, XRES*YRES); @@ -546,16 +546,16 @@ int Simulation::flood_prop(int x, int y, size_t propoffset, PropertyValue propva continue; switch (proptype) { case StructProperty::Float: - *((float*)(((char*)&parts[i>>8])+propoffset)) = propvalue.Float; + *((float*)(((char*)&parts[ID(i)])+propoffset)) = propvalue.Float; break; case StructProperty::ParticleType: case StructProperty::Integer: - *((int*)(((char*)&parts[i>>8])+propoffset)) = propvalue.Integer; + *((int*)(((char*)&parts[ID(i)])+propoffset)) = propvalue.Integer; break; case StructProperty::UInteger: - *((unsigned int*)(((char*)&parts[i>>8])+propoffset)) = propvalue.UInteger; + *((unsigned int*)(((char*)&parts[ID(i)])+propoffset)) = propvalue.UInteger; break; default: @@ -593,13 +593,13 @@ SimulationSample Simulation::GetSample(int x, int y) { if (photons[y][x]) { - sample.particle = parts[photons[y][x]>>8]; - sample.ParticleID = photons[y][x]>>8; + sample.particle = parts[ID(photons[y][x])]; + sample.ParticleID = ID(photons[y][x]); } else if (pmap[y][x]) { - sample.particle = parts[pmap[y][x]>>8]; - sample.ParticleID = pmap[y][x]>>8; + sample.particle = parts[ID(pmap[y][x])]; + sample.ParticleID = ID(pmap[y][x]); } if (bmap[y/CELL][x/CELL]) { @@ -624,11 +624,11 @@ SimulationSample Simulation::GetSample(int x, int y) return sample; } -#define PMAP_CMP_CONDUCTIVE(pmap, t) (((pmap)&0xFF)==(t) || (((pmap)&0xFF)==PT_SPRK && parts[(pmap)>>8].ctype==(t))) +#define PMAP_CMP_CONDUCTIVE(pmap, t) (TYP(pmap)==(t) || (TYP(pmap)==PT_SPRK && parts[ID(pmap)].ctype==(t))) int Simulation::FloodINST(int x, int y, int fullc, int cm) { - int c = fullc&0xFF; + int c = TYP(fullc); int x1, x2; int coord_stack_limit = XRES*YRES; unsigned short (*coord_stack)[2]; @@ -642,7 +642,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) { if (c==0) { - cm = pmap[y][x]&0xFF; + cm = TYP(pmap[y][x]); if (!cm) return 0; } @@ -650,7 +650,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) cm = 0; } - if ((pmap[y][x]&0xFF)!=cm || parts[pmap[y][x]>>8].life!=0) + if (TYP(pmap[y][x])!=cm || parts[ID(pmap[y][x])].life!=0) return 1; coord_stack = (short unsigned int (*)[2])malloc(sizeof(unsigned short)*2*coord_stack_limit); @@ -667,7 +667,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) // go left as far as possible while (x1>=CELL) { - if ((pmap[y][x1-1]&0xFF)!=cm || parts[pmap[y][x1-1]>>8].life!=0) + if (TYP(pmap[y][x1-1])!=cm || parts[ID(pmap[y][x1-1])].life!=0) { break; } @@ -676,7 +676,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) // go right as far as possible while (x2>8].life!=0) + if (TYP(pmap[y][x2+1])!=cm || parts[ID(pmap[y][x2+1])].life!=0) { break; } @@ -685,7 +685,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) // fill span for (x=x1; x<=x2; x++) { - if (create_part(-1, x, y, c, fullc>>8)>=0) + if (create_part(-1, x, y, c, ID(fullc))>=0) created_something = 1; } @@ -696,7 +696,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) !PMAP_CMP_CONDUCTIVE(pmap[y-2][x1-1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y-2][x1], cm) && !PMAP_CMP_CONDUCTIVE(pmap[y-2][x1+1], cm)) { // travelling vertically up, skipping a horizontal line - if ((pmap[y-2][x1]&0xFF)==cm && !parts[pmap[y-2][x1]>>8].life) + if (TYP(pmap[y-2][x1])==cm && !parts[ID(pmap[y-2][x1])].life) { coord_stack[coord_stack_size][0] = x1; coord_stack[coord_stack_size][1] = y-2; @@ -712,7 +712,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) { for (x=x1; x<=x2; x++) { - if ((pmap[y-1][x]&0xFF)==cm && !parts[pmap[y-1][x]>>8].life) + if (TYP(pmap[y-1][x])==cm && !parts[ID(pmap[y-1][x])].life) { if (x==x1 || x==x2 || y>=YRES-CELL-1 || !PMAP_CMP_CONDUCTIVE(pmap[y+1][x], cm) || PMAP_CMP_CONDUCTIVE(pmap[y+1][x+1], cm) || PMAP_CMP_CONDUCTIVE(pmap[y+1][x-1], cm)) { @@ -735,7 +735,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) !PMAP_CMP_CONDUCTIVE(pmap[y+2][x1-1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y+2][x1], cm) && !PMAP_CMP_CONDUCTIVE(pmap[y+2][x1+1], cm)) { // travelling vertically down, skipping a horizontal line - if ((pmap[y+2][x1]&0xFF)==cm && !parts[pmap[y+2][x1]>>8].life) + if (TYP(pmap[y+2][x1])==cm && !parts[ID(pmap[y+2][x1])].life) { coord_stack[coord_stack_size][0] = x1; coord_stack[coord_stack_size][1] = y+2; @@ -751,7 +751,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) { for (x=x1; x<=x2; x++) { - if ((pmap[y+1][x]&0xFF)==cm && !parts[pmap[y+1][x]>>8].life) + if (TYP(pmap[y+1][x])==cm && !parts[ID(pmap[y+1][x])].life) { if (x==x1 || x==x2 || y<0 || !PMAP_CMP_CONDUCTIVE(pmap[y-1][x], cm) || PMAP_CMP_CONDUCTIVE(pmap[y-1][x+1], cm) || PMAP_CMP_CONDUCTIVE(pmap[y-1][x-1], cm)) { @@ -784,7 +784,7 @@ int Simulation::flood_water(int x, int y, int i, int originaly, int check) while (x1>=CELL) { - if ((elements[(pmap[y][x1-1]&0xFF)].Falldown)!=2) + if ((elements[TYP(pmap[y][x1-1])].Falldown) != 2) { break; } @@ -792,7 +792,7 @@ int Simulation::flood_water(int x, int y, int i, int originaly, int check) } while (x2>8].flags &= ~FLAG_WATEREQUAL;//flag it as checked (different from the original particle's checked flag) + parts[ID(pmap[y][x])].flags &= ~FLAG_WATEREQUAL;//flag it as checked (different from the original particle's checked flag) else - parts[pmap[y][x]>>8].flags |= FLAG_WATEREQUAL; + parts[ID(pmap[y][x])].flags |= FLAG_WATEREQUAL; //check above, maybe around other sides too? if ( ((y-1) > originaly) && !pmap[y-1][x] && eval_move(parts[i].type, x, y-1, NULL)) { @@ -822,12 +822,12 @@ int Simulation::flood_water(int x, int y, int i, int originaly, int check) if (y>=CELL+1) for (x=x1; x<=x2; x++) - if ((elements[(pmap[y-1][x]&0xFF)].Falldown)==2 && (parts[pmap[y-1][x]>>8].flags & FLAG_WATEREQUAL) == check) + if ((elements[TYP(pmap[y-1][x])].Falldown)==2 && (parts[ID(pmap[y-1][x])].flags & FLAG_WATEREQUAL) == check) if (!flood_water(x, y-1, i, originaly, check)) return 0; if (y>8].flags & FLAG_WATEREQUAL) == check) + if ((elements[TYP(pmap[y+1][x])].Falldown)==2 && (parts[ID(pmap[y+1][x])].flags & FLAG_WATEREQUAL) == check) if (!flood_water(x, y+1, i, originaly, check)) return 0; return 1; @@ -880,10 +880,10 @@ void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_, if (!rp) return; - ta = (parts[rp>>8].dcolour>>24)&0xFF; - tr = (parts[rp>>8].dcolour>>16)&0xFF; - tg = (parts[rp>>8].dcolour>>8)&0xFF; - tb = (parts[rp>>8].dcolour)&0xFF; + ta = (parts[ID(rp)].dcolour>>24)&0xFF; + tr = (parts[ID(rp)].dcolour>>16)&0xFF; + tg = (parts[ID(rp)].dcolour>>8)&0xFF; + tb = (parts[ID(rp)].dcolour)&0xFF; ta /= 255.0f; tr /= 255.0f; tg /= 255.0f; tb /= 255.0f; colR /= 255.0f; colG /= 255.0f; colB /= 255.0f; colA /= 255.0f; @@ -936,9 +936,9 @@ void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_, for (rx=-2; rx<3; rx++) for (ry=-2; ry<3; ry++) { - if (abs(rx)+abs(ry) > 2 && (pmap[y+ry][x+rx]&0xFF) && parts[pmap[y+ry][x+rx]>>8].dcolour) + if (abs(rx)+abs(ry) > 2 && TYP(pmap[y+ry][x+rx]) && parts[ID(pmap[y+ry][x+rx])].dcolour) { - Particle part = parts[pmap[y+ry][x+rx]>>8]; + Particle part = parts[ID(pmap[y+ry][x+rx])]; num += 1.0f; tas += ((float)((part.dcolour>>24)&0xFF)); trs += ((float)((part.dcolour>>16)&0xFF)); @@ -952,7 +952,7 @@ void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_, tr = (trs/num)/255.0f; tg = (tgs/num)/255.0f; tb = (tbs/num)/255.0f; - if (!parts[rp>>8].dcolour) + if (!parts[ID(rp)].dcolour) ta -= 3/255.0f; } } @@ -981,7 +981,7 @@ void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_, colB_ = 255; else if(colB_ < 0) colB_ = 0; - parts[rp>>8].dcolour = ((colA_<<24)|(colR_<<16)|(colG_<<8)|colB_); + parts[ID(rp)].dcolour = ((colA_<<24)|(colR_<<16)|(colG_<<8)|colB_); } void Simulation::ApplyDecorationPoint(int positionX, int positionY, int colR, int colG, int colB, int colA, int mode, Brush * cBrush) @@ -1168,9 +1168,9 @@ int Simulation::Tool(int x, int y, int tool, float strength) Particle * cpart = NULL; int r; if ((r = pmap[y][x])) - cpart = &(parts[r>>8]); + cpart = &(parts[ID(r)]); else if ((r = photons[y][x])) - cpart = &(parts[r>>8]); + cpart = &(parts[ID(r)]); return tools[tool]->Perform(this, cpart, x, y, strength); } return 0; @@ -1469,7 +1469,7 @@ int Simulation::CreateParts(int positionX, int positionY, int c, Brush * cBrush, int newlife = radiusX + radiusY; if (newlife > 55) newlife = 55; - c = c|newlife<<8; + c = PMAP(newlife, c); lightningRecreate = currentTick+newlife/4; return CreatePartFlags(positionX, positionY, c, flags); } @@ -1478,7 +1478,7 @@ int Simulation::CreateParts(int positionX, int positionY, int c, Brush * cBrush, int newtmp = (radiusX*4+radiusY*4+7); if (newtmp > 300) newtmp = 300; - c = c|newtmp<<8; + c = PMAP(newtmp, c); } for (int y = sizeY-1; y >=0; y--) @@ -1510,7 +1510,7 @@ int Simulation::CreateParts(int x, int y, int rx, int ry, int c, int flags) int newlife = rx + ry; if (newlife > 55) newlife = 55; - c = c|newlife<<8; + c = PMAP(newlife, c); lightningRecreate = currentTick+newlife/4; rx = ry = 0; } @@ -1519,7 +1519,7 @@ int Simulation::CreateParts(int x, int y, int rx, int ry, int c, int flags) int newtmp = (rx*4+ry*4+7); if (newtmp > 300) newtmp = 300; - c = c|newtmp<<8; + c = PMAP(newtmp, c); } for (int j = -ry; j <= ry; j++) @@ -1537,7 +1537,7 @@ int Simulation::CreatePartFlags(int x, int y, int c, int flags) //specific delete else if ((flags&SPECIFIC_DELETE) && !(flags&REPLACE_MODE)) { - if (!replaceModeSelected || (pmap[y][x]&0xFF) == replaceModeSelected || (photons[y][x]&0xFF) == replaceModeSelected) + if (!replaceModeSelected || TYP(pmap[y][x]) == replaceModeSelected || TYP(photons[y][x]) == replaceModeSelected) delete_part(x, y); } //replace mode @@ -1545,18 +1545,18 @@ int Simulation::CreatePartFlags(int x, int y, int c, int flags) { if (x<0 || y<0 || x>=XRES || y>=YRES) return 0; - if (replaceModeSelected && (pmap[y][x]&0xFF) != replaceModeSelected && (photons[y][x]&0xFF) != replaceModeSelected) + if (replaceModeSelected && TYP(pmap[y][x]) != replaceModeSelected && TYP(photons[y][x]) != replaceModeSelected) return 0; if ((pmap[y][x])) { delete_part(x, y); if (c!=0) - create_part(-2, x, y, c&0xFF, c>>8); + create_part(-2, x, y, TYP(c), ID(c)); } } //normal draw else - if (create_part(-2, x, y, c&0xFF, c>>8) == -1) + if (create_part(-2, x, y, TYP(c), ID(c)) == -1) return 1; return 0; } @@ -1620,8 +1620,8 @@ void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c) bool reverseXY = abs(y2-y1) > abs(x2-x1); int x, y, dx, dy, sy; float e, de; - int v = c>>8; - c = c&0xFF; + int v = ID(c); + c = TYP(c); if (reverseXY) { y = x1; @@ -1693,7 +1693,7 @@ void Simulation::CreateBox(int x1, int y1, int x2, int y2, int c, int flags) int Simulation::FloodParts(int x, int y, int fullc, int cm, int flags) { - int c = fullc&0xFF; + int c = TYP(fullc); int x1, x2, dy = (c>8); + kill_part(ID(photons[y][x])); created_something = 1; } } else if (pmap[y][x]) { - kill_part(pmap[y][x]>>8); + kill_part(ID(pmap[y][x])); created_something = 1; } } @@ -1982,7 +1982,7 @@ int Simulation::parts_avg(int ci, int ni,int t) { int pmr = pmap[((int)(parts[ci].y+0.5f) + (int)(parts[ni].y+0.5f))/2][((int)(parts[ci].x+0.5f) + (int)(parts[ni].x+0.5f))/2]; if (pmr) - return parts[pmr>>8].type; + return parts[ID(pmr)].type; else return PT_NONE; } @@ -1991,7 +1991,7 @@ int Simulation::parts_avg(int ci, int ni,int t) int pmr2 = pmap[(int)((parts[ci].y + parts[ni].y)/2+0.5f)][(int)((parts[ci].x + parts[ni].x)/2+0.5f)];//seems to be more accurate. if (pmr2) { - if (parts[pmr2>>8].type==t) + if (parts[ID(pmr2)].type==t) return t; } else @@ -2256,29 +2256,29 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr) r = pmap[ny][nx]; if (r) - r = (r&~0xFF) | parts[r>>8].type; + r = (r&~PMAPMASK) | parts[ID(r)].type; if (rr) *rr = r; - if (pt>=PT_NUM || (r&0xFF)>=PT_NUM) + if (pt>=PT_NUM || TYP(r)>=PT_NUM) return 0; - result = can_move[pt][r&0xFF]; + result = can_move[pt][TYP(r)]; if (result == 3) { - switch (r&0xFF) + switch (TYP(r)) { case PT_LCRY: if (pt==PT_PHOT) - result = (parts[r>>8].life > 5)? 2 : 0; + result = (parts[ID(r)].life > 5)? 2 : 0; break; case PT_GPMP: if (pt == PT_PHOT) - result = (parts[r>>8].life < 10) ? 2 : 0; + result = (parts[ID(r)].life < 10) ? 2 : 0; break; case PT_INVIS: { float pressureResistance = 0.0f; - if (parts[r>>8].tmp > 0) - pressureResistance = (float)parts[r>>8].tmp; + if (parts[ID(r)].tmp > 0) + pressureResistance = (float)parts[ID(r)].tmp; else pressureResistance = 4.0f; @@ -2289,9 +2289,9 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr) break; } case PT_PVOD: - if (parts[r>>8].life == 10) + if (parts[ID(r)].life == 10) { - if (!parts[r>>8].ctype || (parts[r>>8].ctype==pt)!=(parts[r>>8].tmp&1)) + if (!parts[ID(r)].ctype || (parts[ID(r)].ctype==pt)!=(parts[ID(r)].tmp&1)) result = 1; else result = 0; @@ -2299,7 +2299,7 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr) else result = 0; break; case PT_VOID: - if (!parts[r>>8].ctype || (parts[r>>8].ctype==pt)!=(parts[r>>8].tmp&1)) + if (!parts[ID(r)].ctype || (parts[ID(r)].ctype==pt)!=(parts[ID(r)].tmp&1)) result = 1; else result = 0; @@ -2307,7 +2307,7 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr) case PT_SWCH: if (pt == PT_TRON) { - if (parts[r>>8].life >= 10) + if (parts[ID(r)].life >= 10) return 2; else return 0; @@ -2323,7 +2323,7 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr) { if (IsWallBlocking(nx, ny, pt)) return 0; - if (bmap[ny/CELL][nx/CELL]==WL_EHOLE && !emap[ny/CELL][nx/CELL] && !(elements[pt].Properties&TYPE_SOLID) && !(elements[r&0xFF].Properties&TYPE_SOLID)) + if (bmap[ny/CELL][nx/CELL]==WL_EHOLE && !emap[ny/CELL][nx/CELL] && !(elements[pt].Properties&TYPE_SOLID) && !(elements[TYP(r)].Properties&TYPE_SOLID)) return 2; } return result; @@ -2342,34 +2342,35 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) /* half-silvered mirror */ if (!e && parts[i].type==PT_PHOT && - (((r&0xFF)==PT_BMTL && rand() 5) - part_change_type(r>>8, nx, ny, PT_SAWD); + part_change_type(ID(r), nx, ny, PT_SAWD); } if (!(elements[parts[i].type].Properties & TYPE_ENERGY)) return 0; if (!legacy_enable && parts[i].type==PT_PHOT && r)//PHOT heat conduction { - if ((r & 0xFF) == PT_COAL || (r & 0xFF) == PT_BCOL) - parts[r>>8].temp = parts[i].temp; + if (rt == PT_COAL || rt == PT_BCOL) + parts[ID(r)].temp = parts[i].temp; - if ((r & 0xFF) < PT_NUM && elements[r&0xFF].HeatConduct && ((r&0xFF)!=PT_HSWC||parts[r>>8].life==10) && (r&0xFF)!=PT_FILT) - parts[i].temp = parts[r>>8].temp = restrict_flt((parts[r>>8].temp+parts[i].temp)/2, MIN_TEMP, MAX_TEMP); + if (rt < PT_NUM && elements[rt].HeatConduct && (rt!=PT_HSWC||parts[ID(r)].life==10) && rt!=PT_FILT) + parts[i].temp = parts[ID(r)].temp = restrict_flt((parts[ID(r)].temp+parts[i].temp)/2, MIN_TEMP, MAX_TEMP); } - else if ((parts[i].type==PT_NEUT || parts[i].type==PT_ELEC) && ((r&0xFF)==PT_CLNE || (r&0xFF)==PT_PCLN || (r&0xFF)==PT_BCLN || (r&0xFF)==PT_PBCN)) + else if ((parts[i].type==PT_NEUT || parts[i].type==PT_ELEC) && (rt==PT_CLNE || rt==PT_PCLN || rt==PT_BCLN || rt==PT_PBCN)) { - if (!parts[r>>8].ctype) - parts[r>>8].ctype = parts[i].type; + if (!parts[ID(r)].ctype) + parts[ID(r)].ctype = parts[i].type; } - if ((r&0xFF)==PT_PRTI && (elements[parts[i].type].Properties & TYPE_ENERGY)) + if (rt==PT_PRTI && (elements[parts[i].type].Properties & TYPE_ENERGY)) { int nnx, count; for (count=0; count<8; count++) @@ -2378,13 +2379,13 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) break; } count = count%8; - parts[r>>8].tmp = (int)((parts[r>>8].temp-73.15f)/100+1); - if (parts[r>>8].tmp>=CHANNELS) parts[r>>8].tmp = CHANNELS-1; - else if (parts[r>>8].tmp<0) parts[r>>8].tmp = 0; + parts[ID(r)].tmp = (int)((parts[ID(r)].temp-73.15f)/100+1); + if (parts[ID(r)].tmp>=CHANNELS) parts[ID(r)].tmp = CHANNELS-1; + else if (parts[ID(r)].tmp<0) parts[ID(r)].tmp = 0; for ( nnx=0; nnx<80; nnx++) - if (!portalp[parts[r>>8].tmp][count][nnx].type) + if (!portalp[parts[ID(r)].tmp][count][nnx].type) { - portalp[parts[r>>8].tmp][count][nnx] = parts[i]; + portalp[parts[ID(r)].tmp][count][nnx] = parts[i]; parts[i].type=PT_NONE; break; } @@ -2398,23 +2399,23 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) { case PT_PHOT: { - switch (r&0xFF) + switch (TYP(r)) { case PT_GLOW: - if (!parts[r>>8].life && rand() < RAND_MAX/30) + if (!parts[ID(r)].life && rand() < RAND_MAX/30) { - parts[r>>8].life = 120; + parts[ID(r)].life = 120; create_gain_photon(i); } break; case PT_FILT: - parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype); + parts[i].ctype = Element_FILT::interactWavelengths(&parts[ID(r)], parts[i].ctype); break; case PT_C5: - if (parts[r>>8].life > 0 && (parts[r>>8].ctype & parts[i].ctype & 0xFFFFFFC0)) + if (parts[ID(r)].life > 0 && (parts[ID(r)].ctype & parts[i].ctype & 0xFFFFFFC0)) { - float vx = ((parts[r>>8].tmp << 16) >> 16) / 255.0f; - float vy = (parts[r>>8].tmp >> 16) / 255.0f; + float vx = ((parts[ID(r)].tmp << 16) >> 16) / 255.0f; + float vy = (parts[ID(r)].tmp >> 16) / 255.0f; float vn = parts[i].vx * parts[i].vx + parts[i].vy * parts[i].vy; // if the resulting velocity would be 0, that would cause division by 0 inside the else // shoot the photon off at a 90 degree angle instead (probably particle order dependent) @@ -2425,7 +2426,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) } else { - parts[i].ctype = (parts[r>>8].ctype & parts[i].ctype) >> 6; + parts[i].ctype = (parts[ID(r)].ctype & parts[i].ctype) >> 6; // add momentum of photons to each other parts[i].vx += vx; parts[i].vy += vy; @@ -2435,23 +2436,23 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) parts[i].vx *= vn; parts[i].vy *= vn; } - parts[r>>8].life = 0; - parts[r>>8].ctype = 0; + parts[ID(r)].life = 0; + parts[ID(r)].ctype = 0; } - else if(!parts[r>>8].ctype && parts[i].ctype & 0xFFFFFFC0) + else if(!parts[ID(r)].ctype && parts[i].ctype & 0xFFFFFFC0) { - parts[r>>8].life = 1; - parts[r>>8].ctype = parts[i].ctype; - parts[r>>8].tmp = (0xFFFF & (int)(parts[i].vx * 255.0f)) | (0xFFFF0000 & (int)(parts[i].vy * 16711680.0f)); - parts[r>>8].tmp2 = (0xFFFF & (int)((parts[i].x - x) * 255.0f)) | (0xFFFF0000 & (int)((parts[i].y - y) * 16711680.0f)); + parts[ID(r)].life = 1; + parts[ID(r)].ctype = parts[i].ctype; + parts[ID(r)].tmp = (0xFFFF & (int)(parts[i].vx * 255.0f)) | (0xFFFF0000 & (int)(parts[i].vy * 16711680.0f)); + parts[ID(r)].tmp2 = (0xFFFF & (int)((parts[i].x - x) * 255.0f)) | (0xFFFF0000 & (int)((parts[i].y - y) * 16711680.0f)); kill_part(i); } break; case PT_INVIS: { float pressureResistance = 0.0f; - if (parts[r>>8].tmp > 0) - pressureResistance = (float)parts[r>>8].tmp; + if (parts[ID(r)].tmp > 0) + pressureResistance = (float)parts[ID(r)].tmp; else pressureResistance = 4.0f; if (pv[ny/CELL][nx/CELL] >= -pressureResistance && pv[ny/CELL][nx/CELL] <= pressureResistance) @@ -2474,47 +2475,47 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) parts[i].ctype = 0; parts[i].tmp2 = 0x1; - create_part(r>>8, x, y, PT_ELEC); + create_part(ID(r), x, y, PT_ELEC); return 1; } break; case PT_GPMP: - if (parts[r>>8].life == 0) + if (parts[ID(r)].life == 0) { part_change_type(i, x, y, PT_GRVT); - parts[i].tmp = parts[r>>8].temp - 273.15f; + parts[i].tmp = parts[ID(r)].temp - 273.15f; } break; } break; } case PT_NEUT: - if ((r&0xFF) == PT_GLAS || (r&0xFF) == PT_BGLA) + if (TYP(r) == PT_GLAS || TYP(r) == PT_BGLA) if (rand() < RAND_MAX/10) create_cherenkov_photon(i); break; case PT_ELEC: - if ((r&0xFF) == PT_GLOW) + if (TYP(r) == PT_GLOW) { part_change_type(i, x, y, PT_PHOT); parts[i].ctype = 0x3FFFFFFF; } break; case PT_PROT: - if ((r&0xFF) == PT_INVIS) + if (TYP(r) == PT_INVIS) part_change_type(i, x, y, PT_NEUT); break; case PT_BIZR: case PT_BIZRG: - if ((r&0xFF) == PT_FILT) - parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype); + if (TYP(r) == PT_FILT) + parts[i].ctype = Element_FILT::interactWavelengths(&parts[ID(r)], parts[i].ctype); break; } return 1; } //else e=1 , we are trying to swap the particles, return 0 no swap/move, 1 is still overlap/move, because the swap takes place later - switch (r&0xFF) + switch (TYP(r)) { case PT_VOID: case PT_PVOD: @@ -2527,7 +2528,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) // this is where blackhole eats particles if (!legacy_enable) { - parts[r>>8].temp = restrict_flt(parts[r>>8].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);//3.0f; + parts[ID(r)].temp = restrict_flt(parts[ID(r)].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);//3.0f; } kill_part(i); return 0; @@ -2538,7 +2539,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) { if (!legacy_enable) { - parts[r>>8].temp = restrict_flt(parts[r>>8].temp - (MAX_TEMP-parts[i].temp)/2, MIN_TEMP, MAX_TEMP); + parts[ID(r)].temp = restrict_flt(parts[ID(r)].temp - (MAX_TEMP-parts[i].temp)/2, MIN_TEMP, MAX_TEMP); } kill_part(i); return 0; @@ -2547,9 +2548,9 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) case PT_DEUT: if (parts[i].type == PT_ELEC) { - if(parts[r>>8].life < 6000) - parts[r>>8].life += 1; - parts[r>>8].temp = 0; + if(parts[ID(r)].life < 6000) + parts[ID(r)].life += 1; + parts[ID(r)].temp = 0; kill_part(i); return 0; } @@ -2558,7 +2559,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) case PT_BVBR: if ((elements[parts[i].type].Properties & TYPE_ENERGY)) { - parts[r>>8].tmp += 20; + parts[ID(r)].tmp += 20; kill_part(i); return 0; } @@ -2568,14 +2569,14 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) switch (parts[i].type) { case PT_NEUT: - if (elements[r&0xFF].Properties & PROP_NEUTABSORB) + if (elements[TYP(r)].Properties & PROP_NEUTABSORB) { kill_part(i); return 0; } break; case PT_CNCT: - if (y < ny && (pmap[y+1][x]&0xFF) == PT_CNCT) //check below CNCT for another CNCT + if (y < ny && TYP(pmap[y+1][x]) == PT_CNCT) //check below CNCT for another CNCT return 0; break; case PT_GBMB: @@ -2587,36 +2588,36 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) if ((bmap[y/CELL][x/CELL]==WL_EHOLE && !emap[y/CELL][x/CELL]) && !(bmap[ny/CELL][nx/CELL]==WL_EHOLE && !emap[ny/CELL][nx/CELL])) return 0; - int ri = r >> 8; //ri is the particle number at r (pmap[ny][nx]) + int ri = ID(r); //ri is the particle number at r (pmap[ny][nx]) if (r)//the swap part, if we make it this far, swap { if (parts[i].type==PT_NEUT) { // target material is NEUTPENETRATE, meaning it gets moved around when neutron passes unsigned s = pmap[y][x]; - if (s && !(elements[s&0xFF].Properties&PROP_NEUTPENETRATE)) + if (s && !(elements[TYP(s)].Properties&PROP_NEUTPENETRATE)) return 1; // if the element currently underneath neutron isn't NEUTPENETRATE, don't move anything except the neutron // if nothing is currently underneath neutron, only move target particle if(bmap[y/CELL][x/CELL] == WL_ALLOWENERGY) return 1; // do not drag target particle into an energy only wall if (s) { - pmap[ny][nx] = (s&~(0xFF))|parts[s>>8].type; - parts[s>>8].x = nx; - parts[s>>8].y = ny; + pmap[ny][nx] = (s&~PMAPMASK)|parts[ID(s)].type; + parts[ID(s)].x = nx; + parts[ID(s)].y = ny; } else pmap[ny][nx] = 0; parts[ri].x = x; parts[ri].y = y; - pmap[y][x] = (ri<<8)|parts[ri].type; + pmap[y][x] = PMAP(ri, parts[ri].type); return 1; } - if ((pmap[ny][nx]>>8) == ri) + if (ID(pmap[ny][nx]) == ri) pmap[ny][nx] = 0; parts[ri].x += x-nx; parts[ri].y += y-ny; - pmap[(int)(parts[ri].y+0.5f)][(int)(parts[ri].x+0.5f)] = (ri<<8)|parts[ri].type; + pmap[(int)(parts[ri].y+0.5f)][(int)(parts[ri].x+0.5f)] = PMAP(ri, parts[ri].type); } return 1; } @@ -2654,17 +2655,17 @@ int Simulation::do_move(int i, int x, int y, float nxf, float nyf) parts[i].y = nyf; if (ny!=y || nx!=x) { - if ((pmap[y][x]>>8)==i) pmap[y][x] = 0; - else if ((photons[y][x]>>8)==i) photons[y][x] = 0; + if (ID(pmap[y][x])==i) pmap[y][x] = 0; + else if (ID(photons[y][x])==i) photons[y][x] = 0; if (nx=XRES-CELL || ny=YRES-CELL)//kill_part if particle is out of bounds { kill_part(i); return -1; } if (elements[t].Properties & TYPE_ENERGY) - photons[ny][nx] = t|(i<<8); + photons[ny][nx] = PMAP(i, t); else if (t) - pmap[ny][nx] = t|(i<<8); + pmap[ny][nx] = PMAP(i, t); } } return result; @@ -2673,7 +2674,7 @@ int Simulation::do_move(int i, int x, int y, float nxf, float nyf) int Simulation::pn_junction_sprk(int x, int y, int pt) { int r = pmap[y][x]; - if ((r & 0xFF) != pt) + if (TYP(r) != pt) return 0; r >>= 8; if (parts[r].type != pt) @@ -2691,11 +2692,11 @@ void Simulation::photoelectric_effect(int nx, int ny)//create sparks from PHOT w { unsigned r = pmap[ny][nx]; - if ((r&0xFF) == PT_PSCN) { - if ((pmap[ny][nx-1] & 0xFF) == PT_NSCN || - (pmap[ny][nx+1] & 0xFF) == PT_NSCN || - (pmap[ny-1][nx] & 0xFF) == PT_NSCN || - (pmap[ny+1][nx] & 0xFF) == PT_NSCN) + if (TYP(r) == PT_PSCN) { + if (TYP(pmap[ny][nx-1]) == PT_NSCN || + TYP(pmap[ny][nx+1]) == PT_NSCN || + TYP(pmap[ny-1][nx]) == PT_NSCN || + TYP(pmap[ny+1][nx]) == PT_NSCN) pn_junction_sprk(nx, ny, PT_PSCN); } } @@ -2734,7 +2735,7 @@ int Simulation::is_blocking(int t, int x, int y) if (t & REFRACT) { if (x<0 || y<0 || x>=XRES || y>=YRES) return 0; - if ((pmap[y][x] & 0xFF) == PT_GLAS || (pmap[y][x] & 0xFF) == PT_BGLA) + if (TYP(pmap[y][x]) == PT_GLAS || TYP(pmap[y][x]) == PT_BGLA) return 1; return 0; } @@ -2855,9 +2856,9 @@ void Simulation::kill_part(int i)//kills particle number i int x = (int)(parts[i].x+0.5f); int y = (int)(parts[i].y+0.5f); if (x>=0 && y>=0 && x>8)==i) + if (ID(pmap[y][x]) == i) pmap[y][x] = 0; - else if ((photons[y][x]>>8)==i) + else if (ID(photons[y][x]) == i) photons[y][x] = 0; } @@ -2969,14 +2970,14 @@ void Simulation::part_change_type(int i, int x, int y, int t)//changes the type parts[i].type = t; if (elements[t].Properties & TYPE_ENERGY) { - photons[y][x] = t|(i<<8); - if ((pmap[y][x]>>8)==i) + photons[y][x] = PMAP(i, t); + if (ID(pmap[y][x]) == i) pmap[y][x] = 0; } else { - pmap[y][x] = t|(i<<8); - if ((photons[y][x]>>8)==i) + pmap[y][x] = PMAP(i, t); + if (ID(photons[y][x]) == i) photons[y][x] = 0; } } @@ -3007,8 +3008,8 @@ int Simulation::create_part(int p, int x, int y, int t, int v) } else if (t==PT_SPRK) { - int type = pmap[y][x]&0xFF; - int index = pmap[y][x]>>8; + int type = TYP(pmap[y][x]); + int index = ID(pmap[y][x]); if(type == PT_WIRE) { parts[index].ctype = PT_DUST; @@ -3029,7 +3030,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v) parts[index].type = PT_SPRK; parts[index].life = 4; parts[index].ctype = type; - pmap[y][x] = (pmap[y][x]&~0xFF) | PT_SPRK; + pmap[y][x] = (pmap[y][x]&~PMAPMASK) | PT_SPRK; if (parts[index].temp+10.0f < 673.0f && !legacy_enable && (type==PT_METL || type == PT_BMTL || type == PT_BRMT || type == PT_PSCN || type == PT_NSCN || type == PT_ETRD || type == PT_NBLE || type == PT_IRON)) parts[index].temp = parts[index].temp+10.0f; return index; @@ -3047,7 +3048,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v) // If there's no particle and no wall, assume creation is allowed if (pmap[y][x] ? (eval_move(t, x, y, NULL)!=2) : (bmap[y/CELL][x/CELL] && eval_move(t, x, y, NULL)==0)) { - if ((pmap[y][x]&0xFF)!=PT_SPAWN&&(pmap[y][x]&0xFF)!=PT_SPAWN2) + if (TYP(pmap[y][x]) != PT_SPAWN && TYP(pmap[y][x]) != PT_SPAWN2) { if (t!=PT_STKM&&t!=PT_STKM2&&t!=PT_FIGH) { @@ -3065,7 +3066,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v) if (pmap[y][x]) { //If an element has the PROP_DRAWONCTYPE property, and the element being drawn to it does not have PROP_NOCTYPEDRAW (Also some special cases), set the element's ctype - int drawOn = pmap[y][x]&0xFF; + int drawOn = TYP(pmap[y][x]); if (drawOn == t) return -1; if (((elements[drawOn].Properties & PROP_DRAWONCTYPE) || @@ -3074,34 +3075,34 @@ int Simulation::create_part(int p, int x, int y, int t, int v) (drawOn == PT_PBCN && t != PT_PSCN && t != PT_NSCN)) && (!(elements[t].Properties & PROP_NOCTYPEDRAW))) { - parts[pmap[y][x]>>8].ctype = t; + parts[ID(pmap[y][x])].ctype = t; if (t == PT_LIFE && v >= 0 && v < NGOL) { if (drawOn == PT_CONV) - parts[pmap[y][x]>>8].ctype |= v<<8; + parts[ID(pmap[y][x])].ctype |= PMAPID(v); else if (drawOn != PT_STOR) - parts[pmap[y][x]>>8].tmp = v; + parts[ID(pmap[y][x])].tmp = v; } } else if (drawOn == PT_DTEC || (drawOn == PT_PSTN && t != PT_FRME) || drawOn == PT_DRAY) { - parts[pmap[y][x]>>8].ctype = t; + parts[ID(pmap[y][x])].ctype = t; if (t == PT_LIFE && v >= 0 && v < NGOL) { if (drawOn == PT_DTEC) - parts[pmap[y][x]>>8].tmp = v; + parts[ID(pmap[y][x])].tmp = v; else if (drawOn == PT_DRAY) - parts[pmap[y][x]>>8].ctype |= v<<8; + parts[ID(pmap[y][x])].ctype |= PMAPID(v); } } else if (drawOn == PT_CRAY) { - parts[pmap[y][x]>>8].ctype = t; + parts[ID(pmap[y][x])].ctype = t; if (t == PT_LIFE && v >= 0 && v < NGOL) - parts[pmap[y][x]>>8].ctype |= v<<8; + parts[ID(pmap[y][x])].ctype |= PMAPID(v); if (t == PT_LIGH) - parts[pmap[y][x]>>8].ctype |= 30<<8; - parts[pmap[y][x]>>8].temp = elements[t].Temperature; + parts[ID(pmap[y][x])].ctype |= PMAPID(30); + parts[ID(pmap[y][x])].temp = elements[t].Temperature; } return -1; } @@ -3125,9 +3126,9 @@ int Simulation::create_part(int p, int x, int y, int t, int v) { int oldX = (int)(parts[p].x+0.5f); int oldY = (int)(parts[p].y+0.5f); - if ((pmap[oldY][oldX]>>8)==p) + if (ID(pmap[oldY][oldX]) == p) pmap[oldY][oldX] = 0; - if ((photons[oldY][oldX]>>8)==p) + if (ID(photons[oldY][oldX]) == p) photons[oldY][oldX] = 0; if (parts[p].type == PT_STKM) @@ -3360,8 +3361,8 @@ int Simulation::create_part(int p, int x, int y, int t, int v) parts[i].ctype = 0x3FFFFFFF; parts[i].vx = 3.0f*cosf(a); parts[i].vy = 3.0f*sinf(a); - if ((pmap[y][x]&0xFF) == PT_FILT) - parts[i].ctype = Element_FILT::interactWavelengths(&parts[pmap[y][x]>>8], parts[i].ctype); + if (TYP(pmap[y][x]) == PT_FILT) + parts[i].ctype = Element_FILT::interactWavelengths(&parts[ID(pmap[y][x])], parts[i].ctype); break; } case PT_ELEC: @@ -3442,9 +3443,9 @@ int Simulation::create_part(int p, int x, int y, int t, int v) } //and finally set the pmap/photon maps to the newly created particle if (elements[t].Properties & TYPE_ENERGY) - photons[y][x] = t|(i<<8); + photons[y][x] = PMAP(i, t); else if (t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH) - pmap[y][x] = t|(i<<8); + pmap[y][x] = PMAP(i, t); //Fancy dust effects for powder types if((elements[t].Properties & TYPE_PART) && pretty_powder) @@ -3509,7 +3510,7 @@ void Simulation::create_gain_photon(int pp)//photons from PHOT going through GLO if (nx<0 || ny<0 || nx>=XRES || ny>=YRES) return; - if ((pmap[ny][nx] & 0xFF) != PT_GLOW) + if (TYP(pmap[ny][nx]) != PT_GLOW) return; pfree = parts[i].life; @@ -3521,10 +3522,10 @@ void Simulation::create_gain_photon(int pp)//photons from PHOT going through GLO parts[i].y = yy; parts[i].vx = parts[pp].vx; parts[i].vy = parts[pp].vy; - parts[i].temp = parts[pmap[ny][nx] >> 8].temp; + parts[i].temp = parts[ID(pmap[ny][nx])].temp; parts[i].tmp = 0; parts[i].pavg[0] = parts[i].pavg[1] = 0.0f; - photons[ny][nx] = PT_PHOT|(i<<8); + photons[ny][nx] = PMAP(i, PT_PHOT); temp_bin = (int)((parts[i].temp-273.0f)*0.25f); if (temp_bin < 0) temp_bin = 0; @@ -3543,7 +3544,7 @@ void Simulation::create_cherenkov_photon(int pp)//photons from NEUT going throug nx = (int)(parts[pp].x + 0.5f); ny = (int)(parts[pp].y + 0.5f); - if ((pmap[ny][nx] & 0xFF) != PT_GLAS && (pmap[ny][nx] & 0xFF) != PT_BGLA) + if (TYP(pmap[ny][nx]) != PT_GLAS && TYP(pmap[ny][nx]) != PT_BGLA) return; if (hypotf(parts[pp].vx, parts[pp].vy) < 1.44f) @@ -3559,10 +3560,10 @@ void Simulation::create_cherenkov_photon(int pp)//photons from NEUT going throug parts[i].life = 680; parts[i].x = parts[pp].x; parts[i].y = parts[pp].y; - parts[i].temp = parts[pmap[ny][nx] >> 8].temp; + parts[i].temp = parts[ID(pmap[ny][nx])].temp; parts[i].tmp = 0; parts[i].pavg[0] = parts[i].pavg[1] = 0.0f; - photons[ny][nx] = PT_PHOT|(i<<8); + photons[ny][nx] = PMAP(i, PT_PHOT); if (lr) { parts[i].vx = parts[pp].vx - 2.5f*parts[pp].vy; @@ -3592,7 +3593,7 @@ void Simulation::delete_part(int x, int y)//calls kill_part with the particle lo if (!i) return; - kill_part(i>>8); + kill_part(ID(i)); } void Simulation::UpdateParticles(int start, int end) @@ -3737,9 +3738,9 @@ void Simulation::UpdateParticles(int start, int end) if (nx||ny) { surround[j] = r = pmap[y+ny][x+nx]; j++; - if (!(r&0xFF)) + if (!TYP(r)) surround_space++;//there is empty space - if ((r&0xFF)!=t) + if (TYP(r)!=t) nt++;//there is nothing or a different particle } } @@ -3752,11 +3753,11 @@ void Simulation::UpdateParticles(int start, int end) { if (y-2 >= 0 && y-2 < YRES && (elements[t].Properties&TYPE_LIQUID) && (t!=PT_GEL || gel_scale>(1+rand()%255))) {//some heat convection for liquids r = pmap[y-2][x]; - if (!(!r || parts[i].type != (r&0xFF))) { - if (parts[i].temp>parts[r>>8].temp) { + if (!(!r || parts[i].type != TYP(r))) { + if (parts[i].temp>parts[ID(r)].temp) { swappage = parts[i].temp; - parts[i].temp = parts[r>>8].temp; - parts[r>>8].temp = swappage; + parts[i].temp = parts[ID(r)].temp; + parts[ID(r)].temp = swappage; } } } @@ -3797,23 +3798,23 @@ void Simulation::UpdateParticles(int start, int end) r = surround[j]; if (!r) continue; - rt = r&0xFF; - if (rt&&elements[rt].HeatConduct&&(rt!=PT_HSWC||parts[r>>8].life==10) + rt = TYP(r); + if (rt&&elements[rt].HeatConduct&&(rt!=PT_HSWC||parts[ID(r)].life==10) &&(t!=PT_FILT||(rt!=PT_BRAY&&rt!=PT_BIZR&&rt!=PT_BIZRG)) &&(rt!=PT_FILT||(t!=PT_BRAY&&t!=PT_PHOT&&t!=PT_BIZR&&t!=PT_BIZRG)) &&(t!=PT_ELEC||rt!=PT_DEUT) &&(t!=PT_DEUT||rt!=PT_ELEC)) { - surround_hconduct[j] = r>>8; + surround_hconduct[j] = ID(r); #ifdef REALISTIC if (rt==PT_GEL) - gel_scale = parts[r>>8].tmp*2.55f; + gel_scale = parts[ID(r)].tmp*2.55f; else gel_scale = 1.0f; - c_heat += parts[r>>8].temp*96.645/elements[rt].HeatConduct*gel_scale*fabs(elements[rt].Weight); + c_heat += parts[ID(r)].temp*96.645/elements[rt].HeatConduct*gel_scale*fabs(elements[rt].Weight); c_Cm += 96.645/elements[rt].HeatConduct*gel_scale*fabs(elements[rt].Weight); #else - c_heat += parts[r>>8].temp; + c_heat += parts[ID(r)].temp; #endif h_count++; } @@ -4346,7 +4347,7 @@ killed: //block if particle can't move (0), or some special cases where it returns 1 (can_move = 3 but returns 1 meaning particle will be eaten) //also photons are still blocked (slowed down) by any particle (even ones it can move through), and absorb wall also blocks particles int eval = eval_move(t, fin_x, fin_y, NULL); - if (!eval || (can_move[t][pmap[fin_y][fin_x]&0xFF] == 3 && eval == 1) || (t == PT_PHOT && pmap[fin_y][fin_x]) || bmap[fin_y/CELL][fin_x/CELL]==WL_DESTROYALL || closedEholeStart!=(bmap[fin_y/CELL][fin_x/CELL] == WL_EHOLE && !emap[fin_y/CELL][fin_x/CELL])) + if (!eval || (can_move[t][TYP(pmap[fin_y][fin_x])] == 3 && eval == 1) || (t == PT_PHOT && pmap[fin_y][fin_x]) || bmap[fin_y/CELL][fin_x/CELL]==WL_DESTROYALL || closedEholeStart!=(bmap[fin_y/CELL][fin_x/CELL] == WL_EHOLE && !emap[fin_y/CELL][fin_x/CELL])) { // found an obstacle clear_xf = fin_xf-dx; @@ -4411,17 +4412,19 @@ killed: } if (ny!=y || nx!=x) { - if ((pmap[y][x]>>8)==i) pmap[y][x] = 0; - else if ((photons[y][x]>>8)==i) photons[y][x] = 0; + if (ID(pmap[y][x]) == i) + pmap[y][x] = 0; + else if (ID(photons[y][x]) == i) + photons[y][x] = 0; if (nx=XRES-CELL || ny=YRES-CELL) { kill_part(i); continue; } if (elements[t].Properties & TYPE_ENERGY) - photons[ny][nx] = t|(i<<8); + photons[ny][nx] = PMAP(i, t); else if (t) - pmap[ny][nx] = t|(i<<8); + pmap[ny][nx] = PMAP(i, t); } } else if (elements[t].Properties & TYPE_ENERGY) @@ -4436,8 +4439,8 @@ killed: if (eval_move(PT_PHOT, fin_x, fin_y, NULL)) { - int rt = pmap[fin_y][fin_x] & 0xFF; - int lt = pmap[y][x] & 0xFF; + int rt = TYP(pmap[fin_y][fin_x]); + int lt = TYP(pmap[y][x]); int rt_glas = (rt == PT_GLAS) || (rt == PT_BGLA); int lt_glas = (lt == PT_GLAS) || (lt == PT_BGLA); if ((rt_glas && !lt_glas) || (lt_glas && !rt_glas)) @@ -4500,23 +4503,23 @@ killed: } r = pmap[fin_y][fin_x]; - if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP) && !(parts[r>>8].tmp&0xFF)) + if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && !TYP(parts[ID(r)].tmp)) { - parts[r>>8].tmp = (parts[r>>8].tmp&~0xFF) | parts[i].type; - parts[r>>8].temp = parts[i].temp; - parts[r>>8].tmp2 = parts[i].life; - parts[r>>8].pavg[0] = parts[i].tmp; - parts[r>>8].pavg[1] = parts[i].ctype; + parts[ID(r)].tmp = (parts[ID(r)].tmp&~PMAPMASK) | parts[i].type; + parts[ID(r)].temp = parts[i].temp; + parts[ID(r)].tmp2 = parts[i].life; + parts[ID(r)].pavg[0] = parts[i].tmp; + parts[ID(r)].pavg[1] = parts[i].ctype; kill_part(i); continue; } - if (r&0xFF) - parts[i].ctype &= elements[r&0xFF].PhotonReflectWavelengths; + if (TYP(r)) + parts[i].ctype &= elements[TYP(r)].PhotonReflectWavelengths; if (get_normal_interp(t, parts[i].x, parts[i].y, parts[i].vx, parts[i].vy, &nrx, &nry)) { - if ((r & 0xFF) == PT_CRMC) + if (TYP(r) == PT_CRMC) { float r = (rand() % 101 - 50) * 0.01f, rx, ry, anrx, anry; r = r * r * r; @@ -4646,21 +4649,21 @@ killed: for (j=clear_x+r; j>=0 && j>=clear_x-rt && j0) @@ -4670,7 +4673,7 @@ killed: if (s==1) for (j=ny+r; j>=0 && j=ny-rt && j=XRES || ny >=YRES) break; - if ((pmap[ny][nx]&0xFF)!=t || bmap[ny/CELL][nx/CELL]) + if (TYP(pmap[ny][nx])!=t || bmap[ny/CELL][nx/CELL]) { s = do_move(i, x, y, nxf, nyf); if (s) @@ -4758,7 +4761,7 @@ killed: break; } // A particle of a different type, or a wall, was found. Stop trying to move any further horizontally unless the wall should be completely invisible to particles. - if ((pmap[ny][nx]&0xFF)!=t || bmap[ny/CELL][nx/CELL]!=WL_STREAM) + if (TYP(pmap[ny][nx])!=t || bmap[ny/CELL][nx/CELL]!=WL_STREAM) break; } } @@ -4805,10 +4808,10 @@ killed: if (nx<0 || ny<0 || nx>=XRES || ny>=YRES) break; // If the space is anything except the same element (a wall, empty space, or occupied by a particle of a different element), try to move into it - if ((pmap[ny][nx]&0xFF)!=t || bmap[ny/CELL][nx/CELL]) + if (TYP(pmap[ny][nx])!=t || bmap[ny/CELL][nx/CELL]) { s = do_move(i, clear_x, clear_y, nxf, nyf); - if (s || (pmap[ny][nx]&0xFF)!=t || bmap[ny/CELL][nx/CELL]!=WL_STREAM) + if (s || TYP(pmap[ny][nx])!=t || bmap[ny/CELL][nx/CELL]!=WL_STREAM) break; // found the edge of the liquid and movement into it succeeded, so stop moving down } } @@ -4875,15 +4878,15 @@ void Simulation::SimulateGoL() gol[ny][nx] = 0; continue; } - if ((r&0xFF)==PT_LIFE) + if (TYP(r)==PT_LIFE) { - int golnum = parts[r>>8].ctype+1; + int golnum = parts[ID(r)].ctype+1; if (golnum<=0 || golnum>NGOL) { - kill_part(r>>8); + kill_part(ID(r)); continue; } gol[ny][nx] = golnum; - if (parts[r>>8].tmp == grule[golnum][9]-1) + if (parts[ID(r)].tmp == grule[golnum][9]-1) { for (int nnx = -1; nnx < 2; nnx++) { @@ -4893,7 +4896,7 @@ void Simulation::SimulateGoL() int adx = ((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL; int ady = ((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL; int rt = pmap[ady][adx]; - if (!rt || (rt&0xFF)==PT_LIFE) + if (!rt || TYP(rt)==PT_LIFE) { //the total neighbor count is in 0 gol2[ady][adx][0] ++; @@ -4917,7 +4920,7 @@ void Simulation::SimulateGoL() } else { - parts[r>>8].tmp --; + parts[ID(r)].tmp --; } } } @@ -4928,7 +4931,7 @@ void Simulation::SimulateGoL() for (int nx = CELL; nx < XRES-CELL; nx++) { int r = pmap[ny][nx]; - if (r && (r&0xFF)!=PT_LIFE) + if (r && TYP(r)!=PT_LIFE) continue; int neighbors = gol2[ny][nx][0]; if (neighbors) @@ -4952,15 +4955,15 @@ void Simulation::SimulateGoL() } else if (grule[golnum][neighbors-1]==0 || grule[golnum][neighbors-1]==2)//subtract 1 because it counted itself { - if (parts[r>>8].tmp==grule[golnum][9]-1) - parts[r>>8].tmp --; + if (parts[ID(r)].tmp==grule[golnum][9]-1) + parts[ID(r)].tmp --; } for (int z = 0; z < 9; z++) gol2[ny][nx][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this. } //we still need to kill things with 0 neighbors (higher state life) - if (r && parts[r>>8].tmp<=0) - kill_part(r>>8); + if (r && parts[ID(r)].tmp<=0) + kill_part(ID(r)); } } //memset(gol2, 0, sizeof(gol2)); @@ -4988,13 +4991,13 @@ void Simulation::RecalcFreeParticles(bool do_life_dec) if (x>=0 && y>=0 && xYRES-7||nx>XRES-10)&&(parts[r>>8].type==PT_LOVE||parts[r>>8].type==PT_LOLZ)) - kill_part(r>>8); - else if (parts[r>>8].type==PT_LOVE) + else if ((ny<9||nx<9||ny>YRES-7||nx>XRES-10)&&(parts[ID(r)].type==PT_LOVE||parts[ID(r)].type==PT_LOLZ)) + kill_part(ID(r)); + else if (parts[ID(r)].type==PT_LOVE) { Element_LOVE::love[nx/9][ny/9] = 1; } - else if (parts[r>>8].type==PT_LOLZ) + else if (parts[ID(r)].type==PT_LOLZ) { Element_LOLZ::lolz[nx/9][ny/9] = 1; } @@ -5227,8 +5230,8 @@ void Simulation::BeforeSim() create_part(-1,nx+nnx,ny+nny,PT_LOVE); else if (!rt) continue; - else if (parts[rt>>8].type==PT_LOVE&&Element_LOVE::RuleTable[nnx][nny]==0) - kill_part(rt>>8); + else if (parts[ID(rt)].type==PT_LOVE&&Element_LOVE::RuleTable[nnx][nny]==0) + kill_part(ID(rt)); } } } @@ -5245,8 +5248,8 @@ void Simulation::BeforeSim() create_part(-1,nx+nnx,ny+nny,PT_LOLZ); else if (!rt) continue; - else if (parts[rt>>8].type==PT_LOLZ&&Element_LOLZ::RuleTable[nny][nnx]==0) - kill_part(rt>>8); + else if (parts[ID(rt)].type==PT_LOLZ&&Element_LOLZ::RuleTable[nny][nnx]==0) + kill_part(ID(rt)); } } @@ -5266,8 +5269,8 @@ void Simulation::BeforeSim() int r = pmap[ny][nx]; if (!r) continue; - if(parts[r>>8].type == PT_WIRE) - parts[r>>8].tmp = parts[r>>8].ctype; + if(parts[ID(r)].type == PT_WIRE) + parts[ID(r)].tmp = parts[ID(r)].ctype; } } }