Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dboolean P_PathTraverse(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2,
- int flags, dboolean trav(intercept_t *))
- {
- fixed_t xt1, yt1;
- fixed_t xt2, yt2;
- fixed_t xstep, ystep;
- fixed_t partial;
- fixed_t xintercept, yintercept;
- int mapx, mapy;
- int mapx1, mapy1;
- int mapxstep, mapystep;
- int count;
- validcount++;
- intercept_p = intercepts;
- if (!((x1-bmaporgx)&(MAPBLOCKSIZE-1)))
- x1 += FRACUNIT; // don't side exactly on a line
- if (!((y1-bmaporgy)&(MAPBLOCKSIZE-1)))
- y1 += FRACUNIT; // don't side exactly on a line
- trace.x = x1;
- trace.y = y1;
- trace.dx = x2 - x1;
- trace.dy = y2 - y1;
- if (COMPBAD(comperr_blockmap))
- {
- int_64_t _x1, _x2, _y1, _y2;
- _x1 = (int_64_t)x1 - bmaporgx;
- _y1 = (int_64_t)y1 - bmaporgy;
- xt1 = (int)(_x1>>MAPBLOCKSHIFT);
- yt1 = (int)(_y1>>MAPBLOCKSHIFT);
- mapx1 = (int)(_x1>>MAPBTOFRAC);
- mapy1 = (int)(_y1>>MAPBTOFRAC);
- _x2 = (int_64_t)x2 - bmaporgx;
- _y2 = (int_64_t)y2 - bmaporgy;
- xt2 = (int)(_x2>>MAPBLOCKSHIFT);
- yt2 = (int)(_y2>>MAPBLOCKSHIFT);
- x1 -= bmaporgx;
- y1 -= bmaporgy;
- x2 -= bmaporgx;
- y2 -= bmaporgy;
- }
- else
- {
- x1 -= bmaporgx;
- y1 -= bmaporgy;
- xt1 = x1>>MAPBLOCKSHIFT;
- yt1 = y1>>MAPBLOCKSHIFT;
- mapx1 = x1>>MAPBTOFRAC;
- mapy1 = y1>>MAPBTOFRAC;
- x2 -= bmaporgx;
- y2 -= bmaporgy;
- xt2 = x2>>MAPBLOCKSHIFT;
- yt2 = y2>>MAPBLOCKSHIFT;
- }
- if (xt2 > xt1)
- {
- mapxstep = 1;
- partial = FRACUNIT - (mapx1&(FRACUNIT-1));
- ystep = FixedDiv (y2-y1,D_abs(x2-x1));
- }
- else
- if (xt2 < xt1)
- {
- mapxstep = -1;
- partial = mapx1&(FRACUNIT-1);
- ystep = FixedDiv (y2-y1,D_abs(x2-x1));
- }
- else
- {
- mapxstep = 0;
- partial = FRACUNIT;
- ystep = 256*FRACUNIT;
- }
- yintercept = mapy1 + FixedMul(partial, ystep);
- if (yt2 > yt1)
- {
- mapystep = 1;
- partial = FRACUNIT - (mapy1&(FRACUNIT-1));
- xstep = FixedDiv (x2-x1,D_abs(y2-y1));
- }
- else
- if (yt2 < yt1)
- {
- mapystep = -1;
- partial = mapy1&(FRACUNIT-1);
- xstep = FixedDiv (x2-x1,D_abs(y2-y1));
- }
- else
- {
- mapystep = 0;
- partial = FRACUNIT;
- xstep = 256*FRACUNIT;
- }
- xintercept = 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 (flags & PT_ADDLINES)
- if (!P_BlockLinesIterator(mapx, mapy,PIT_AddLineIntercepts))
- return false; // early out
- if (flags & PT_ADDTHINGS)
- if (!P_BlockThingsIterator(mapx, mapy,PIT_AddThingIntercepts))
- return false; // early out
- if (mapx == xt2 && mapy == yt2)
- break;
- if ((yintercept >> FRACBITS) == mapy)
- {
- yintercept += ystep;
- mapx += mapxstep;
- }
- else
- if ((xintercept >> FRACBITS) == mapx)
- {
- xintercept += xstep;
- mapy += mapystep;
- }
- }
- // go through the sorted list
- return P_TraverseIntercepts(trav, FRACUNIT);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement