public TiledNavMesh(Vector3 origin, float tileWidth, float tileHeight, int maxTiles, int maxPolys) { this.origin = origin; this.tileWidth = tileWidth; this.tileHeight = tileHeight; this.maxTiles = maxTiles; this.maxPolys = maxPolys; //init tiles tileSet = new Dictionary <Vector2i, List <MeshTile> >(); tileRefs = new Dictionary <MeshTile, PolyId>(); tileList = new List <MeshTile>(); //init ID generator values int tileBits = MathHelper.Log2(MathHelper.NextPowerOfTwo(maxTiles)); int polyBits = MathHelper.Log2(MathHelper.NextPowerOfTwo(maxPolys)); //only allow 31 salt bits, since salt mask is calculated using 32-bit int and it will overflow int saltBits = Math.Min(31, 32 - tileBits - polyBits); //TODO handle this in a sane way/do we need this? if (saltBits < 10) { return; } idManager = new PolyIdManager(polyBits, tileBits, saltBits); }
/// <summary> /// Initializes a new instance of the <see cref="TiledNavMesh"/> class. /// </summary> /// <param name="data">The Navigation Mesh data</param> public TiledNavMesh(NavMeshBuilder data) { this.origin = data.Header.Bounds.Min; this.tileWidth = data.Header.Bounds.Max.X - data.Header.Bounds.Min.X; this.tileHeight = data.Header.Bounds.Max.Z - data.Header.Bounds.Min.Z; this.maxTiles = 1; this.maxPolys = data.Header.PolyCount; //init tiles tileSet = new Dictionary <Vector2i, List <MeshTile> >(); tileRefs = new Dictionary <MeshTile, PolyId>(); tileList = new List <MeshTile>(); //init ID generator values int tileBits = MathHelper.Log2(MathHelper.NextPowerOfTwo(maxTiles)); int polyBits = MathHelper.Log2(MathHelper.NextPowerOfTwo(maxPolys)); //only allow 31 salt bits, since salt mask is calculated using 32-bit int and it will overflow int saltBits = Math.Min(31, 32 - tileBits - polyBits); //TODO handle this in a sane way/do we need this? if (saltBits < 10) { return; } idManager = new PolyIdManager(polyBits, tileBits, saltBits); AddTile(data); }
/// <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); }
public void NextPowerOfTwo_PositiveIntegerInt_Sucess() { int num = MathHelper.NextPowerOfTwo(5); Assert.AreEqual(num, 8); }