示例#1
0
        /// <summary>
        /// Initialize the Tiled Navigation Mesh variables and arrays.
        /// </summary>
        /// <param name="parameters">Tiled Navigation Mesh attributes</param>
        /// <returns>True if initialization is successful</returns>
        public bool InitTileNavMesh()
        {
            //init tiles
            tileLookupTableSize = MathHelper.NextPowerOfTwo(maxTiles / 4);
            if (tileLookupTableSize == 0)
            {
                tileLookupTableSize = 1;
            }
            tileLookupTableMask = tileLookupTableSize - 1;

            tiles     = new MeshTile[maxTiles];
            posLookup = new MeshTile[tileLookupTableSize];
            for (int i = 0; i < tiles.Length; i++)
            {
                tiles[i] = new MeshTile();
            }
            for (int i = 0; i < posLookup.Length; i++)
            {
                posLookup[i] = null;
            }

            //create a linked list of tiles
            nextFree = null;
            for (int i = maxTiles - 1; i >= 0; i--)
            {
                tiles[i].Salt = 1;
                tiles[i].Next = nextFree;
                nextFree      = tiles[i];
            }

            //init ID generator values
            tileBits = MathHelper.Log2(MathHelper.NextPowerOfTwo(maxTiles));
            polyBits = MathHelper.Log2(MathHelper.NextPowerOfTwo(maxPolys));

            //only allow 31 salt bits, since salt mask is calculated using 32-bit int and it will overflow
            saltBits = Math.Min(31, 32 - tileBits - polyBits);
            if (saltBits < 10)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public void Log2_PositiveIntegerUint_Success()
        {
            uint num = MathHelper.Log2((uint)65);

            Assert.AreEqual(num, 6);
        }