public FloorChunk GetChunkAt(int x, int y, int z) { int Hash = HASH(x, y, z); if (CachePositionToChunk.ContainsKey(Hash)) { int ChunkId = CachePositionToChunk[Hash].ChunkId; return(GetChunk(ChunkId)); } else { return(null); } }
/** Create the cache for faster access */ public void CacheChunkPositions() { List <FloorChunk> Chunks = new List <FloorChunk>(); GetChunks(Chunks); foreach (FloorChunk Chunk in Chunks) { int X0 = Chunk.Bounds.Location.x; int Z0 = Chunk.Bounds.Location.z; int X1 = X0 + Chunk.Bounds.Size.x; int Z1 = Z0 + Chunk.Bounds.Size.z; int y = Chunk.Bounds.Location.y; List <IntVector> BoundCells = Chunk.BoundCells; if (BoundCells.Count == 0) { for (int x = X0; x < X1; x++) { for (int z = Z0; z < Z1; z++) { BoundCells.Add(new IntVector(x, y, z)); } } } foreach (IntVector Cell in BoundCells) { int Hash = HASH(Cell.x, Cell.y, Cell.z); if (!CachePositionToChunk.ContainsKey(Hash)) { CachePositionToChunk.Add(Hash, new FChunkCacheNode(Chunk.Id, Chunk.Priority)); } else { // Entry already exists. Override if the priority is higher FChunkCacheNode Node = CachePositionToChunk[Hash]; if (Node.Priority < Chunk.Priority) { Node.ChunkId = Chunk.Id; Node.Priority = Chunk.Priority; } } } } }