Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * P_PathTraverse
- * Traces a line from x1,y1 to x2,y2,
- * calling the traverser function for each.
- * Returns true if the traverser function returns true
- * for all lines.
- */
- private final boolean PathTraverse(int x1, int y1, int x2, int y2, int flags,
- PTR_InterceptFunc trav) {
- // System.out.println("Pathtraverse "+x1+" , " +y1+" to "+x2 +" , "
- // +y2);
- final int xt1, yt1;
- final int xt2, yt2;
- final long _x1, _x2, _y1, _y2;
- final int mapx1, mapy1;
- final int xstep, ystep;
- int partial;
- int xintercept, yintercept;
- int mapx;
- int mapy;
- int mapxstep;
- int mapystep;
- int count;
- earlyout = eval(flags& PT_EARLYOUT);
- R.increaseValidCount(1);
- intercept_p = 0;
- if (((x1 - LL.bmaporgx) & (MAPBLOCKSIZE - 1)) == 0)
- x1 += FRACUNIT; // don't side exactly on a line
- if (((y1 - LL.bmaporgy) & (MAPBLOCKSIZE - 1)) == 0)
- y1 += FRACUNIT; // don't side exactly on a line
- trace.x = x1;
- trace.y = y1;
- trace.dx = x2 - x1;
- trace.dy = y2 - y1;
- // Code developed in common with entryway
- // for prBoom+
- _x1 = (long) x1 - LL.bmaporgx;
- _y1 = (long) y1 - LL.bmaporgy;
- xt1 = (int) (_x1 >> MAPBLOCKSHIFT);
- yt1 = (int) (_y1 >> MAPBLOCKSHIFT);
- mapx1 = (int) (_x1 >> MAPBTOFRAC);
- mapy1 = (int) (_y1 >> MAPBTOFRAC);
- _x2 = (long) x2 - LL.bmaporgx;
- _y2 = (long) y2 - LL.bmaporgy;
- xt2 = (int) (_x2 >> MAPBLOCKSHIFT);
- yt2 = (int) (_y2 >> MAPBLOCKSHIFT);
- x1 -= LL.bmaporgx;
- y1 -= LL.bmaporgy;
- x2 -= LL.bmaporgx;
- y2 -= LL.bmaporgy;
- if (xt2 > xt1)
- {
- mapxstep = 1;
- partial = FRACUNIT - (mapx1&(FRACUNIT-1));
- ystep = FixedDiv (y2-y1,Math.abs(x2-x1));
- }
- else if (xt2 < xt1)
- {
- mapxstep = -1;
- partial = mapx1&(FRACUNIT-1);
- ystep = FixedDiv (y2-y1,Math.abs(x2-x1));
- }
- else
- {
- mapxstep = 0;
- partial = FRACUNIT;
- ystep = 256*FRACUNIT;
- }
- yintercept = (int) (mapy1 + FixedMul (partial, ystep));
- if (yt2 > yt1)
- {
- mapystep = 1;
- partial = FRACUNIT - (mapy1&(FRACUNIT-1));
- xstep = FixedDiv (x2-x1,Math.abs(y2-y1));
- }
- else if (yt2 < yt1)
- {
- mapystep = -1;
- partial = mapy1&(FRACUNIT-1);
- xstep = FixedDiv (x2-x1,Math.abs(y2-y1));
- }
- else
- {
- mapystep = 0;
- partial = FRACUNIT;
- xstep = 256*FRACUNIT;
- }
- xintercept = (int) (mapx1 + FixedMul (partial, xstep));
- // Step through map blocks.
- // Count is present to prevent a round off error
- // from skipping the break.
- mapx = xt1;
- mapy = yt1;
- for (count = 0 ; count < 64 ; count++)
- {
- if (eval(flags &PT_ADDLINES))
- {
- if (!BlockLinesIterator (mapx, mapy,AddLineIntercepts))
- return false; // early out
- }
- if (eval(flags &PT_ADDTHINGS))
- {
- if (!BlockThingsIterator (mapx, mapy,AddThingIntercepts))
- return false; // early out
- }
- if (mapx == xt2
- && mapy == yt2)
- {
- break;
- }
- boolean changeX = (yintercept >> FRACBITS) == mapy;
- boolean changeY = (xintercept >> FRACBITS) == mapx;
- if (changeX)
- {
- yintercept += ystep;
- mapx += mapxstep;
- }
- if (changeY)
- {
- xintercept += xstep;
- mapy += mapystep;
- }
- }
- // go through the sorted list
- //System.out.println("Some intercepts found");
- return TraverseIntercepts ( trav, FRACUNIT );
- } // end method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement