Advertisement
Guest User

Mochadoom P_PathTrasverse

a guest
Mar 26th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.59 KB | None | 0 0
  1. /**
  2.      * P_PathTraverse
  3.      * Traces a line from x1,y1 to x2,y2,
  4.      * calling the traverser function for each.
  5.      * Returns true if the traverser function returns true
  6.      * for all lines.
  7.      */
  8.     private final boolean PathTraverse(int x1, int y1, int x2, int y2, int flags,
  9.             PTR_InterceptFunc trav) {
  10.         // System.out.println("Pathtraverse "+x1+" , " +y1+" to "+x2 +" , "
  11.         // +y2);
  12.         final int xt1, yt1;
  13.         final int xt2, yt2;
  14.         final long _x1, _x2, _y1, _y2;
  15.         final int mapx1, mapy1;
  16.         final int xstep, ystep;
  17.  
  18.         int partial;
  19.  
  20.         int xintercept, yintercept;
  21.  
  22.         int mapx;
  23.         int mapy;
  24.  
  25.         int mapxstep;
  26.         int mapystep;
  27.  
  28.         int count;
  29.  
  30.         earlyout = eval(flags& PT_EARLYOUT);
  31.  
  32.         R.increaseValidCount(1);
  33.         intercept_p = 0;
  34.  
  35.         if (((x1 - LL.bmaporgx) & (MAPBLOCKSIZE - 1)) == 0)
  36.             x1 += FRACUNIT; // don't side exactly on a line
  37.  
  38.         if (((y1 - LL.bmaporgy) & (MAPBLOCKSIZE - 1)) == 0)
  39.             y1 += FRACUNIT; // don't side exactly on a line
  40.  
  41.         trace.x = x1;
  42.         trace.y = y1;
  43.         trace.dx = x2 - x1;
  44.         trace.dy = y2 - y1;
  45.  
  46.         // Code developed in common with entryway
  47.         // for prBoom+
  48.        
  49.         _x1 = (long) x1 - LL.bmaporgx;
  50.         _y1 = (long) y1 - LL.bmaporgy;
  51.         xt1 = (int) (_x1 >> MAPBLOCKSHIFT);
  52.         yt1 = (int) (_y1 >> MAPBLOCKSHIFT);
  53.  
  54.         mapx1 = (int) (_x1 >> MAPBTOFRAC);
  55.         mapy1 = (int) (_y1 >> MAPBTOFRAC);
  56.  
  57.         _x2 = (long) x2 - LL.bmaporgx;
  58.         _y2 = (long) y2 - LL.bmaporgy;
  59.         xt2 = (int) (_x2 >> MAPBLOCKSHIFT);
  60.         yt2 = (int) (_y2 >> MAPBLOCKSHIFT);
  61.  
  62.         x1 -= LL.bmaporgx;
  63.         y1 -= LL.bmaporgy;
  64.         x2 -= LL.bmaporgx;
  65.         y2 -= LL.bmaporgy;
  66.        
  67.      if (xt2 > xt1)
  68.      {
  69.      mapxstep = 1;
  70.      partial = FRACUNIT - (mapx1&(FRACUNIT-1));
  71.      ystep = FixedDiv (y2-y1,Math.abs(x2-x1));
  72.      }
  73.      else if (xt2 < xt1)
  74.      {
  75.      mapxstep = -1;
  76.      partial = mapx1&(FRACUNIT-1);
  77.      ystep = FixedDiv (y2-y1,Math.abs(x2-x1));
  78.      }
  79.      else
  80.      {
  81.      mapxstep = 0;
  82.      partial = FRACUNIT;
  83.      ystep = 256*FRACUNIT;
  84.      }  
  85.  
  86.      yintercept = (int) (mapy1 + FixedMul (partial, ystep));
  87.  
  88.      
  89.      if (yt2 > yt1)
  90.      {
  91.      mapystep = 1;
  92.      partial = FRACUNIT - (mapy1&(FRACUNIT-1));
  93.      xstep = FixedDiv (x2-x1,Math.abs(y2-y1));
  94.      }
  95.      else if (yt2 < yt1)
  96.      {
  97.      mapystep = -1;
  98.      partial = mapy1&(FRACUNIT-1);
  99.      xstep = FixedDiv (x2-x1,Math.abs(y2-y1));
  100.      }
  101.      else
  102.      {
  103.      mapystep = 0;
  104.      partial = FRACUNIT;
  105.      xstep = 256*FRACUNIT;
  106.      }  
  107.      xintercept = (int) (mapx1 + FixedMul (partial, xstep));
  108.      
  109.      // Step through map blocks.
  110.      // Count is present to prevent a round off error
  111.      // from skipping the break.
  112.      mapx = xt1;
  113.      mapy = yt1;
  114.      
  115.      for (count = 0 ; count < 64 ; count++)
  116.      {
  117.      if (eval(flags &PT_ADDLINES))
  118.      {
  119.          if (!BlockLinesIterator (mapx, mapy,AddLineIntercepts))
  120.          return false;   // early out
  121.      }
  122.      
  123.      if (eval(flags &PT_ADDTHINGS))
  124.      {
  125.          if (!BlockThingsIterator (mapx, mapy,AddThingIntercepts))
  126.          return false;   // early out
  127.      }
  128.          
  129.      if (mapx == xt2
  130.          && mapy == yt2)
  131.      {
  132.          break;
  133.      }
  134.      
  135.      boolean changeX = (yintercept >> FRACBITS) == mapy;
  136.      boolean changeY = (xintercept >> FRACBITS) == mapx;
  137.      if (changeX)
  138.      {
  139.          yintercept += ystep;
  140.          mapx += mapxstep;
  141.      }
  142.      if (changeY)
  143.      {
  144.          xintercept += xstep;
  145.          mapy += mapystep;
  146.      }
  147.          
  148.      }
  149.      // go through the sorted list
  150.      //System.out.println("Some intercepts found");
  151.      return TraverseIntercepts ( trav, FRACUNIT );
  152.     } // end method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement