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, to disintegration of the save.

int d; float f;  (int)(f)+d does not necessarily equal (int)(f+d)
  • Loading branch information
jacksonmj committed Feb 15, 2015
1 parent 5b5a4be commit 2ad996d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/simulation/elements/PSTN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ int PSTN_MoveStack(Simulation * sim, int stackX, int stackY, int directionX, int
break;
}
int rcount, ri, rnext;
float moveX = -directionX*amount, moveY = -directionY*amount;
int destPosX = posX-directionX*amount, destPosY = posY-directionY*amount;
FOR_PMAP_POSITION_NOENERGY(sim, posX, posY, rcount, ri, rnext)
{
sim->part_set_pos(ri, posX, posY, parts[ri].x+moveX, parts[ri].y+moveY);
sim->part_set_pos(ri, posX, posY, destPosX, destPosY);
}
}
return amount;
Expand All @@ -150,19 +150,19 @@ int PSTN_MoveStack(Simulation * sim, int stackX, int stackY, int directionX, int
int destPos = currentPos-1;
int srcPos = destPos-1;
int srcPosX, srcPosY;
float moveX, moveY;
int destPosX, destPosY;
int rcount, ri, rnext;
for (; srcPos>=0; srcPos--)
{
srcPosX = stackX + directionX*srcPos;
srcPosY = stackY + directionY*srcPos;
if (sim->pmap[srcPosY][srcPosX].count_notEnergy)
{
moveX = directionX*(destPos-srcPos);
moveY = directionY*(destPos-srcPos);
destPosX = stackX + directionX*destPos;
destPosY = stackY + directionY*destPos;
FOR_PMAP_POSITION_NOENERGY(sim, srcPosX, srcPosY, rcount, ri, rnext)
{
sim->part_set_pos(ri, srcPosX, srcPosY, parts[ri].x+moveX, parts[ri].y+moveY);
sim->part_set_pos(ri, srcPosX, srcPosY, destPosX, destPosY);
}
destPos--;
}
Expand Down

0 comments on commit 2ad996d

Please sign in to comment.