From cd71a6dff7abfd88e96ad1dc4cb587d9b544f96b Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Mon, 23 Feb 2015 13:35:17 +0000 Subject: [PATCH] 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) --- src/simulation/elements/PSTN.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/simulation/elements/PSTN.cpp b/src/simulation/elements/PSTN.cpp index 21fb8fb8fc..3a5e3c0349 100644 --- a/src/simulation/elements/PSTN.cpp +++ b/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; }