Advertisement
Guest User

Mocha Doom PathTrasverse

a guest
Dec 4th, 2011
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.53 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.     boolean PathTraverse ( int x1,int y1,int x2,int y2,int flags,PTR_InterceptFunc trav)
  9.     {
  10.    //   System.out.println("Pathtraverse "+x1+" , " +y1+" to "+x2 +" , " +y2);
  11.      int xt1,yt1;
  12.      int xt2, yt2;
  13.      long _x1, _x2, _y1, _y2;    
  14.      int xstep,ystep;
  15.      
  16.      int partial;
  17.      
  18.      int xintercept, yintercept;
  19.      
  20.      int     mapx;
  21.      int     mapy;
  22.      
  23.      int     mapxstep;
  24.      int     mapystep;
  25.  
  26.      int     count;
  27.          
  28.      earlyout = flags(flags ,PT_EARLYOUT);
  29.          
  30.      R.increaseValidCount(1);
  31.      intercept_p = 0;
  32.      
  33.      if ( ((x1-LL.bmaporgx)&(MAPBLOCKSIZE-1)) == 0)
  34.      x1 += FRACUNIT; // don't side exactly on a line
  35.      
  36.      if ( ((y1-LL.bmaporgy)&(MAPBLOCKSIZE-1)) == 0)
  37.      y1 += FRACUNIT; // don't side exactly on a line
  38.  
  39.      trace.x = x1;
  40.      trace.y = y1;
  41.      trace.dx = x2 - x1;
  42.      trace.dy = y2 - y1;
  43.  
  44.      /*
  45.      _x1 = (long)x1 - LL.bmaporgx;
  46.      _y1 = (long)y1 - LL.bmaporgy;
  47.      x1 -= LL.bmaporgx;
  48.      y1 -= LL.bmaporgy;
  49.      xt1 = LL.getSafeBlockX(_x1);
  50.      yt1 = LL.getSafeBlockY(_y1);
  51.  
  52.      _x2 = (long)x2 - LL.bmaporgx;
  53.      _y2 = (long)y2 - LL.bmaporgy;
  54.      x2 -= LL.bmaporgx;
  55.      y2 -= LL.bmaporgy;
  56.      
  57.      
  58.      xt2 = LL.getSafeBlockX(_x2);
  59.      yt2 = LL.getSafeBlockY(_y2);
  60.      */
  61.      {
  62.  
  63.             _x1 = (long)x1 - LL.bmaporgx;
  64.             _y1 = (long)y1 - LL.bmaporgy;
  65.             xt1 = (int)(_x1>>MAPBLOCKSHIFT);
  66.             yt1 = (int)(_y1>>MAPBLOCKSHIFT);
  67.          
  68.           //  mapx1 = (int)(_x1>>MAPBTOFRAC);
  69.           //  mapy1 = (int)(_y1>>MAPBTOFRAC);
  70.          
  71.             _x2 = (long)x2 - LL.bmaporgx;
  72.             _y2 = (long)y2 - LL.bmaporgy;
  73.             xt2 = (int)(_x2>>MAPBLOCKSHIFT);
  74.             yt2 = (int)(_y2>>MAPBLOCKSHIFT);
  75.          
  76.             x1 -= LL.bmaporgx;
  77.             y1 -= LL.bmaporgy;
  78.             x2 -= LL.bmaporgx;
  79.             y2 -= LL.bmaporgy;
  80.           }
  81.  
  82.     // System.out.printf("Block: %d %d %d %d\n",xt1,yt1,xt2,yt2);
  83.      
  84.      if (xt2 > xt1)
  85.      {
  86.      mapxstep = 1;
  87.      partial = FRACUNIT - ((x1>>MAPBTOFRAC)&(FRACUNIT-1));
  88.      ystep = FixedDiv ((int)(y2-y1),Math.abs((int)(x2-x1)));
  89.      }
  90.      else if (xt2 < xt1)
  91.      {
  92.      mapxstep = -1;
  93.      partial = (x1>>MAPBTOFRAC)&(FRACUNIT-1);
  94.      ystep = FixedDiv ((int)(y2-y1),Math.abs((int)(x2-x1)));
  95.      }
  96.      else
  97.      {
  98.      mapxstep = 0;
  99.      partial = FRACUNIT;
  100.      ystep = 256*FRACUNIT;
  101.      }  
  102.  
  103.      yintercept = (int) ((_y1>>MAPBTOFRAC) + FixedMul (partial, ystep));
  104.  
  105.      
  106.      if (yt2 > yt1)
  107.      {
  108.      mapystep = 1;
  109.      partial = FRACUNIT - ((y1>>MAPBTOFRAC)&(FRACUNIT-1));
  110.      xstep = FixedDiv ((int)(x2-x1),Math.abs((int)(y2-y1)));
  111.      }
  112.      else if (yt2 < yt1)
  113.      {
  114.      mapystep = -1;
  115.      partial = (y1>>MAPBTOFRAC)&(FRACUNIT-1);
  116.      xstep = FixedDiv ((int)(x2-x1),Math.abs((int)(y2-y1)));
  117.      }
  118.      else
  119.      {
  120.      mapystep = 0;
  121.      partial = FRACUNIT;
  122.      xstep = 256*FRACUNIT;
  123.      }  
  124.      xintercept = (int) ((_x1>>MAPBTOFRAC) + FixedMul (partial, xstep));
  125.      
  126.     // System.out.printf("xstep %d ystep %d partial %d xintercept %d yintercept %d\n",xstep,ystep,partial,xintercept,yintercept);
  127.      
  128.      // Step through map blocks.
  129.      // Count is present to prevent a round off error
  130.      // from skipping the break.
  131.      mapx = xt1;
  132.      mapy = yt1;
  133.      
  134.      for (count = 0 ; count < 64 ; count++)
  135.      {
  136.      if (flags(flags ,PT_ADDLINES))
  137.      {
  138.          if (!BlockLinesIterator (mapx, mapy,AddLineIntercepts))
  139.          return false;   // early out
  140.      }
  141.      
  142.      if (flags(flags ,PT_ADDTHINGS))
  143.      {
  144.          if (!BlockThingsIterator (mapx, mapy,AddThingIntercepts))
  145.          return false;   // early out
  146.      }
  147.          
  148.      if (mapx == xt2
  149.          && mapy == yt2)
  150.      {
  151.          break;
  152.      }
  153.      
  154.      boolean changeX = (yintercept >> FRACBITS) == mapy;
  155.      boolean changeY = (xintercept >> FRACBITS) == mapx;
  156.      if (changeX) // _D_ there is a rare case when changeX and changeY are both true, that is why I modified this section
  157.      {
  158.          yintercept += ystep;
  159.          mapx += mapxstep;
  160.      }
  161.      if (changeY)
  162.      {
  163.          xintercept += xstep;
  164.          mapy += mapystep;
  165.      }
  166.          
  167.      }
  168.      // go through the sorted list
  169.      //System.out.println("Some intercepts found");
  170.      return TraverseIntercepts ( trav, FRACUNIT );
  171.     } // end method
  172.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement