Advertisement
Guest User

Untitled

a guest
Dec 4th, 2011
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.29 KB | None | 0 0
  1. dboolean P_PathTraverse(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2,
  2.                        int flags, dboolean trav(intercept_t *))
  3. {
  4.   fixed_t xt1, yt1;
  5.   fixed_t xt2, yt2;
  6.   fixed_t xstep, ystep;
  7.   fixed_t partial;
  8.   fixed_t xintercept, yintercept;
  9.   int     mapx, mapy;
  10.   int     mapx1, mapy1;
  11.   int     mapxstep, mapystep;
  12.   int     count;
  13.  
  14.   validcount++;
  15.   intercept_p = intercepts;
  16.  
  17.   if (!((x1-bmaporgx)&(MAPBLOCKSIZE-1)))
  18.     x1 += FRACUNIT;     // don't side exactly on a line
  19.  
  20.   if (!((y1-bmaporgy)&(MAPBLOCKSIZE-1)))
  21.     y1 += FRACUNIT;     // don't side exactly on a line
  22.  
  23.   trace.x = x1;
  24.   trace.y = y1;
  25.   trace.dx = x2 - x1;
  26.   trace.dy = y2 - y1;
  27.  
  28.   if (COMPBAD(comperr_blockmap))
  29.   {
  30.     int_64_t _x1, _x2, _y1, _y2;
  31.  
  32.     _x1 = (int_64_t)x1 - bmaporgx;
  33.     _y1 = (int_64_t)y1 - bmaporgy;
  34.     xt1 = (int)(_x1>>MAPBLOCKSHIFT);
  35.     yt1 = (int)(_y1>>MAPBLOCKSHIFT);
  36.  
  37.     mapx1 = (int)(_x1>>MAPBTOFRAC);
  38.     mapy1 = (int)(_y1>>MAPBTOFRAC);
  39.  
  40.     _x2 = (int_64_t)x2 - bmaporgx;
  41.     _y2 = (int_64_t)y2 - bmaporgy;
  42.     xt2 = (int)(_x2>>MAPBLOCKSHIFT);
  43.     yt2 = (int)(_y2>>MAPBLOCKSHIFT);
  44.  
  45.     x1 -= bmaporgx;
  46.     y1 -= bmaporgy;
  47.     x2 -= bmaporgx;
  48.     y2 -= bmaporgy;
  49.   }
  50.   else
  51.   {
  52.     x1 -= bmaporgx;
  53.     y1 -= bmaporgy;
  54.     xt1 = x1>>MAPBLOCKSHIFT;
  55.     yt1 = y1>>MAPBLOCKSHIFT;
  56.  
  57.     mapx1 = x1>>MAPBTOFRAC;
  58.     mapy1 = y1>>MAPBTOFRAC;
  59.  
  60.     x2 -= bmaporgx;
  61.     y2 -= bmaporgy;
  62.     xt2 = x2>>MAPBLOCKSHIFT;
  63.     yt2 = y2>>MAPBLOCKSHIFT;
  64.   }
  65.  
  66.   if (xt2 > xt1)
  67.     {
  68.       mapxstep = 1;
  69.       partial = FRACUNIT - (mapx1&(FRACUNIT-1));
  70.       ystep = FixedDiv (y2-y1,D_abs(x2-x1));
  71.     }
  72.   else
  73.     if (xt2 < xt1)
  74.       {
  75.         mapxstep = -1;
  76.         partial = mapx1&(FRACUNIT-1);
  77.         ystep = FixedDiv (y2-y1,D_abs(x2-x1));
  78.       }
  79.     else
  80.       {
  81.         mapxstep = 0;
  82.         partial = FRACUNIT;
  83.         ystep = 256*FRACUNIT;
  84.       }
  85.  
  86.   yintercept = mapy1 + FixedMul(partial, ystep);
  87.  
  88.   if (yt2 > yt1)
  89.     {
  90.       mapystep = 1;
  91.       partial = FRACUNIT - (mapy1&(FRACUNIT-1));
  92.       xstep = FixedDiv (x2-x1,D_abs(y2-y1));
  93.     }
  94.   else
  95.     if (yt2 < yt1)
  96.       {
  97.         mapystep = -1;
  98.         partial = mapy1&(FRACUNIT-1);
  99.         xstep = FixedDiv (x2-x1,D_abs(y2-y1));
  100.       }
  101.     else
  102.       {
  103.         mapystep = 0;
  104.         partial = FRACUNIT;
  105.         xstep = 256*FRACUNIT;
  106.       }
  107.  
  108.   xintercept = mapx1 + FixedMul(partial, xstep);
  109.  
  110.   // Step through map blocks.
  111.   // Count is present to prevent a round off error
  112.   // from skipping the break.
  113.  
  114.   mapx = xt1;
  115.   mapy = yt1;
  116.  
  117.   for (count = 0; count < 64; count++)
  118.     {
  119.       if (flags & PT_ADDLINES)
  120.         if (!P_BlockLinesIterator(mapx, mapy,PIT_AddLineIntercepts))
  121.           return false; // early out
  122.  
  123.       if (flags & PT_ADDTHINGS)
  124.         if (!P_BlockThingsIterator(mapx, mapy,PIT_AddThingIntercepts))
  125.           return false; // early out
  126.  
  127.       if (mapx == xt2 && mapy == yt2)
  128.         break;
  129.  
  130.       if ((yintercept >> FRACBITS) == mapy)
  131.         {
  132.           yintercept += ystep;
  133.           mapx += mapxstep;
  134.         }
  135.       else
  136.         if ((xintercept >> FRACBITS) == mapx)
  137.           {
  138.             xintercept += xstep;
  139.             mapy += mapystep;
  140.           }
  141.     }
  142.  
  143.   // go through the sorted list
  144.   return P_TraverseIntercepts(trav, FRACUNIT);
  145. }
  146.  
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement