// Notify adjacent chunks that chunk is unloading by nulling reference private void ReleaseAdjChunks() { for (int i = 0; i < ADJ_CHUNK_SIZE; i++) { adjChunks[i] = null; Chunk invAdjChunk = voxelEngineManager.GetChunk(chunkPos - adjChunkVectors[i]); if (invAdjChunk != null) { invAdjChunk.UpdateAdjChunk(null, i); } } }
// Try to find adjacent chunks to inform them of this chunk and fill the adjChunk lookup public void FillAdjChunks() { bool adjReady = true; FillType adjType = fillType; // Adjacent chunks are needed to mesh the chunk for (int i = 0; i < ADJ_CHUNK_SIZE; i++) { adjChunks[i] = voxelEngineManager.GetChunk(chunkPos + adjChunkVectors[i]); if (adjChunks[i] != null) { adjType = adjChunks[i].fillType == adjType ? adjType : FillType.Mixed; } else { adjReady = false; } Chunk invAdjChunk = voxelEngineManager.GetChunk(chunkPos - adjChunkVectors[i]); if (invAdjChunk != null) { invAdjChunk.UpdateAdjChunk(this, i); } } // Cancel meshing if not all adjacent chunks are loaded if (!adjReady) { return; } // If adjacent chunks are all full or all empty no meshing is needed if (adjType != FillType.Mixed) { dirtyMesh = false; return; } if (dirtyMesh) { voxelEngineManager.QueueChunkMeshing(chunkPos); } }