public PathFinderFast(byte[,] grid)
        {
            if (grid == null)
            {
                throw new Exception("Grid cannot be null");
            }

            mGrid        = grid;
            mGridX       = (ushort)(mGrid.GetUpperBound(0) + 1);
            mGridY       = (ushort)(mGrid.GetUpperBound(1) + 1);
            mGridXMinus1 = (ushort)(mGridX - 1);
            mGridYLog2   = (ushort)Math.Log(mGridY, 2);

            // This should be done at the constructor, for now we leave it here.
            if (Math.Log(mGridX, 2) != (int)Math.Log(mGridX, 2) ||
                Math.Log(mGridY, 2) != (int)Math.Log(mGridY, 2))
            {
                throw new Exception("Invalid Grid, size in X and Y must be power of 2");
            }

            if (mCalcGrid == null || mCalcGrid.Length != (mGridX * mGridY))
            {
                mCalcGrid = new PathFinderNodeFast[mGridX * mGridY];
            }

            mOpen = new PriorityQueueB <int>(new ComparePFNodeMatrix(mCalcGrid));
        }
Example #2
0
        public PathFinderFast(Level level)
        {
            if (level == null)
            {
                throw new Exception("Map cannot be null");
            }
            if (level.mapTiles == null)
            {
                throw new Exception("Grid cannot be null");
            }

            mLevel       = level;
            mGrid        = level.mapTiles;
            mGridX       = (ushort)(mGrid.GetUpperBound(0) + 1);
            mGridY       = (ushort)(mGrid.GetUpperBound(1) + 1);
            mGridXMinus1 = (ushort)(mGridX - 1);
            mGridXLog2   = (ushort)Math.Log(mGridX, 2);

            if (Math.Log(mGridX, 2) != (int)Math.Log(mGridX, 2) ||
                Math.Log(mGridY, 2) != (int)Math.Log(mGridY, 2))
            {
                throw new Exception("Invalid Grid, size in X and Y must be power of 2");
            }

            if (nodes == null || nodes.Length != (mGridX * mGridY))
            {
                nodes            = new List <PathFinderNodeFast> [mGridX * mGridY];
                touchedLocations = new Stack <int>(mGridX * mGridY);
                mClose           = new List <Vector2i>(mGridX * mGridY);
            }

            for (var i = 0; i < nodes.Length; ++i)
            {
                nodes[i] = new List <PathFinderNodeFast>(1);
            }

            mOpen = new PriorityQueueB <Location>(new ComparePFNodeMatrix(nodes));
        }