Exemplo n.º 1
0
        public Status Init(NavMeshBuilder data, int flags)
        {
            if (data.Header.Magic != Helper.NavMeshMagic)
            {
                throw new ArgumentException("Wrong Magic Number");
            }
            if (data.Header.Version != Helper.NavMeshVersion)
            {
                throw new ArgumentException("Wrong Version Number");
            }

            NavMeshParams param = new NavMeshParams();

            Array.Copy(data.Header.BMin, param.Orig, 3);
            param.TileWidth  = data.Header.BMax[0] - data.Header.BMin[0];
            param.TileHeight = data.Header.BMax[2] - data.Header.BMin[2];
            param.MaxTiles   = 1;
            param.MaxPolys   = data.Header.PolyCount;

            Status status = Init(param);

            if ((status & Status.Failure) == Status.Failure)
            {
                return(status);
            }

            long temp = 0;

            return(AddTile(data, flags, 0, ref temp));
        }
Exemplo n.º 2
0
        public Status Init(NavMeshParams param)
        {
            _param = param;
            Array.Copy(param.Orig, _orig, 3);
            _tileWidth  = param.TileWidth;
            _tileHeight = param.TileHeight;

            _maxTiles    = param.MaxTiles;
            _tileLutSize = (int)Helper.NextPow2(param.MaxTiles / 4);
            if (_tileLutSize <= 0)
            {
                _tileLutSize = 1;
            }
            _tileLutMask = _tileLutSize - 1;

            _tiles     = new MeshTile[_maxTiles];
            _posLookup = new MeshTile[_tileLutSize];

            for (int i = 0; i < _tileLutSize; i++)
            {
                _posLookup[i] = new MeshTile();
            }

            _nextFree = null;
            for (int i = _maxTiles - 1; i >= 0; i--)
            {
                _tiles[i] = new MeshTile {
                    Salt = 1, Next = _nextFree
                };
                _nextFree = _tiles[i];
            }

            _tileBits = Helper.Ilog2(Helper.NextPow2(param.MaxTiles));
            _polyBits = Helper.Ilog2(Helper.NextPow2(param.MaxPolys));
            _saltBits = Math.Min(31, 32 - _tileBits - _polyBits);
            if (_saltBits < 10)
            {
                return(Status.Failure | Status.InvalidParam);
            }
            return(Status.Success);
        }