Float rounding strikes again - set destination coords using integers when moving particles with PSTN

instead of adding a delta value to the current position, which might not give the correct result. Particles (except solids) were on rare occasions ending up at a point 1 pixel away from where they should be after being pushed by PSTN. This led to stacking, and in the case of save 1732622 after changing BIZS to a liquid, to disintegration of the save.

(TPT++ version of commit 2ad996dfe621887355f8532f1262c306421bc2de in jacksonmj fork)
This commit is contained in:
jacksonmj 2015-02-23 13:35:17 +00:00
parent d71a0d98eb
commit cd71a6dff7

View File

@ -282,10 +282,12 @@ int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int direct
//Move particles //Move particles
for(int j = 0; j < currentPos; j++) { for(int j = 0; j < currentPos; j++) {
int jP = tempParts[j]; int jP = tempParts[j];
sim->pmap[(int)(sim->parts[jP].y + 0.5f)][(int)(sim->parts[jP].x + 0.5f)] = 0; int srcX = (int)(sim->parts[jP].x + 0.5f), srcY = (int)(sim->parts[jP].y + 0.5f);
sim->parts[jP].x += (float)((-directionX)*amount); int destX = srcX-directionX*amount, destY = srcY-directionY*amount;
sim->parts[jP].y += (float)((-directionY)*amount); sim->pmap[srcY][srcX] = 0;
sim->pmap[(int)(sim->parts[jP].y + 0.5f)][(int)(sim->parts[jP].x + 0.5f)] = sim->parts[jP].type|(jP<<8); sim->parts[jP].x = destX;
sim->parts[jP].y = destY;
sim->pmap[destY][destX] = sim->parts[jP].type|(jP<<8);
} }
return amount; return amount;
} }
@ -304,10 +306,12 @@ int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int direct
} }
if(!possibleMovement) if(!possibleMovement)
continue; continue;
sim->pmap[(int)(sim->parts[jP].y + 0.5f)][(int)(sim->parts[jP].x + 0.5f)] = 0; int srcX = (int)(sim->parts[jP].x + 0.5f), srcY = (int)(sim->parts[jP].y + 0.5f);
sim->parts[jP].x += (float)(directionX*possibleMovement); int destX = srcX+directionX*possibleMovement, destY = srcY+directionY*possibleMovement;
sim->parts[jP].y += (float)(directionY*possibleMovement); sim->pmap[srcY][srcX] = 0;
sim->pmap[(int)(sim->parts[jP].y + 0.5f)][(int)(sim->parts[jP].x + 0.5f)] = sim->parts[jP].type|(jP<<8); sim->parts[jP].x = destX;
sim->parts[jP].y = destY;
sim->pmap[destY][destX] = sim->parts[jP].type|(jP<<8);
} }
return possibleMovement; return possibleMovement;
} }