Permalink
Browse files

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 2ad996d in jacksonmj fork)
  • Loading branch information...
jacksonmj committed Feb 23, 2015
1 parent d71a0d9 commit cd71a6dff7abfd88e96ad1dc4cb587d9b544f96b
Showing with 12 additions and 8 deletions.
  1. +12 −8 src/simulation/elements/PSTN.cpp
@@ -282,10 +282,12 @@ int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int direct
//Move particles
for(int j = 0; j < currentPos; j++) {
int jP = tempParts[j];
sim->pmap[(int)(sim->parts[jP].y + 0.5f)][(int)(sim->parts[jP].x + 0.5f)] = 0;
sim->parts[jP].x += (float)((-directionX)*amount);
sim->parts[jP].y += (float)((-directionY)*amount);
sim->pmap[(int)(sim->parts[jP].y + 0.5f)][(int)(sim->parts[jP].x + 0.5f)] = sim->parts[jP].type|(jP<<8);
int srcX = (int)(sim->parts[jP].x + 0.5f), srcY = (int)(sim->parts[jP].y + 0.5f);
int destX = srcX-directionX*amount, destY = srcY-directionY*amount;
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);
}
return amount;
}
@@ -304,10 +306,12 @@ int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int direct
}
if(!possibleMovement)
continue;
sim->pmap[(int)(sim->parts[jP].y + 0.5f)][(int)(sim->parts[jP].x + 0.5f)] = 0;
sim->parts[jP].x += (float)(directionX*possibleMovement);
sim->parts[jP].y += (float)(directionY*possibleMovement);
sim->pmap[(int)(sim->parts[jP].y + 0.5f)][(int)(sim->parts[jP].x + 0.5f)] = sim->parts[jP].type|(jP<<8);
int srcX = (int)(sim->parts[jP].x + 0.5f), srcY = (int)(sim->parts[jP].y + 0.5f);
int destX = srcX+directionX*possibleMovement, destY = srcY+directionY*possibleMovement;
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);
}
return possibleMovement;
}

0 comments on commit cd71a6d

Please sign in to comment.