Skip to content

Commit

Permalink
Float rounding strikes again - set destination coords using integers …
Browse files Browse the repository at this point in the history
…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 cd71a6d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/simulation/elements/PSTN.cpp
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit cd71a6d

Please sign in to comment.