Exemplo n.º 1
0
        //private readonly AStar.ISearchCache cacheAbstract;

        /* Debug Vis Stuff
         *
         * void KD_AddCircle(Vec2I pt, bool big)
         * {
         *  GameObject child = new GameObject();
         *  child.transform.SetParent(transform, false);
         *
         *  var color = Color.red * (big ? .8f : .4f);
         *  float rad = big ? .5f : .4f;
         *
         *  List<Vec2> pts = new List<Vec2>();
         *  for (int i = 0; i < 32; ++i)
         *  {
         *      float theta = i * 2 * Mathf.PI / 32f;
         *      float x = Mathf.Cos(theta) * rad;
         *      float y = Mathf.Sin(theta) * rad;
         *      pts.Add(new Vec2(x + pt.x + .5f, y + pt.y + .5f));
         *  }
         *
         *
         *  child.AddLineRenderer("Highlight", 2001, color, 1 / 32f, true, true, pts.ToArray());
         * }
         *
         * void KD_AddPath(IEnumerable<Vec2I> path)
         * {
         *  GameObject child = new GameObject();
         *  child.transform.SetParent(transform, false);
         *  child.AddLineRenderer("Highlight", 2000, Color.black, 1 / 32f, false, true,
         *      path.Select(pt => pt + new Vec2(.5f, .5f)).ToArray());
         * }
         *
         * void KD_AddSquare(Vec2I o)
         * {
         *  GameObject child = new GameObject();
         *  child.transform.SetParent(transform, false);
         *  child.AddLineRenderer("Highlight", 1999, Color.white, 1 / 32f, true, true,
         *      new Vec2[] {o, new Vec2(o.x + 8, o.y), new Vec2(o.x+8, o.y+8), new Vec2(o.x, o.y+8)} );
         * }
         *
         *      // K_deubg vis
         *      for (int xa = 0; xa < 8; ++xa)
         *      {
         *          for (int ya = 0; ya < 8; ++ya)
         *          {
         *              int x = 8 * xa;
         *              int y = 8 * ya;
         *              Vec2I o = new Vec2I(x, y);
         *              KD_AddSquare(o);
         *              var tile = nav.atiles[xa, ya];
         *              for (int ea = 0; ea < 4; ++ea)
         *              {
         *                  var edgeA = tile.edges[ea];
         *                  if (edgeA == null) continue;
         *
         *                  for (int i = 0; i < edgeA.pts.Length; ++i)
         *                      KD_AddCircle(o + edgeA.pts[i], ea % 2 == 0);
         *
         *                  for (int eb = ea + 1; eb < 4; ++eb)
         *                  {
         *                      var path = edgeA.pathsToEdge[eb];
         *                      if (path != null)
         *                          KD_AddPath(path.pts.Select(pt => pt + o));
         *                  }
         *              }
         *          }
         *      }*/


        public Nav__Unfinished(Vec2I size, Func <Vec2I, bool> passFn)
        {
            BB.Assert(size.x % aDim == 0);
            BB.Assert(size.y % aDim == 0);

            //this.size = size;
            this.passFn = passFn;

            this.asize  = new Vec2I(size.x / aDim, size.y / aDim);
            this.atiles = new ATile[asize.x, asize.y];
            for (int x = 0; x < asize.x; ++x)
            {
                for (int y = 0; y < asize.y; ++y)
                {
                    atiles[x, y] = new ATile(passFn, x, y);
                }
            }

            this.cacheInternal = AStar.CreateSearchCache(new Vec2I(aDim, aDim));
            //this.cacheAbstract = AStar.CreateSearchCache(asize);

            ComputeAbstract(); // ???
        }
Exemplo n.º 2
0
 public Nav(Map map)
 {
     searchCache = AStar.CreateSearchCache(map.size);
     passFn      = pt => map.GetTile(pt).passable;
 }