public CompressedTile AddTile(TileCacheData data, CompressedTileFlagTypes flags) { // Make sure the data is in right format. var header = data.Header; if (header.Magic != DetourTileCache.DT_TILECACHE_MAGIC) { throw new EngineException("DT_WRONG_MAGIC"); } if (header.Version != DetourTileCache.DT_TILECACHE_VERSION) { throw new EngineException("DT_WRONG_VERSION"); } // Make sure the location is free. if (GetTileAt(header.TX, header.TY, header.TLayer) != null) { throw new EngineException("DT_FAILURE"); } // Allocate a tile. CompressedTile tile = null; if (m_nextFreeTile != null) { tile = m_nextFreeTile; m_nextFreeTile = tile.Next; tile.Next = null; } else { tile = new CompressedTile(); } // Insert tile into the position lut. int h = Detour.ComputeTileHash(header.TX, header.TY, m_tileLutMask); tile.Next = m_posLookup[h]; m_posLookup[h] = tile; // Init tile. tile.Header = data.Header; tile.Data = data.Data; tile.Flags = flags; return(tile); }
private CompressedTile GetTileAt(int tx, int ty, int tlayer) { // Find tile based on hash. int h = Detour.ComputeTileHash(tx, ty, m_tileLutMask); var tile = m_posLookup[h]; while (tile != null) { if (tile.Header.TX == tx && tile.Header.TY == ty && tile.Header.TLayer == tlayer) { return(tile); } tile = tile.Next; } return(null); }
public int GetTilesAt(int tx, int ty, out CompressedTile[] tiles, int maxTiles) { tiles = new CompressedTile[maxTiles]; int n = 0; // Find tile based on hash. int h = Detour.ComputeTileHash(tx, ty, m_tileLutMask); var tile = m_posLookup[h]; while (tile != null) { if (tile.Header.TX == tx && tile.Header.TY == ty && n < maxTiles) { tiles[n++] = tile; } tile = tile.Next; } return(n); }