private void Update() { lock (ChunksAwaitingMeshApplying) { // When chunks are queued for re-generation run the below while (ChunksAwaitingMeshApplying.Count > 0) { if (_update >= _updatesPerFrame) { _update = 0; break; } TerrainChunk chunk = ChunksAwaitingMeshApplying.Dequeue(); chunk.GenerateChunkNeighbours(_generateChunkNeighboursSteps); if (!IsMultiThreaded) chunk.GenerateChunkMesh(chunk.LODLevel, true); // Check if a chunk should generation or delete objects if (MathUtility.CompareLodLevel(chunk.LODLevel, FarLodSize)) { ObjectManager.RemoveObjectsAtChunk(chunk); } else { if (chunk.IsForcedObjectGeneration) { chunk.IsForcedObjectGeneration = false; ObjectManager.PlaceObjectsAtChunk(chunk); } } chunk.UpdateChunkMesh(); _update++; } } }
/// <summary> /// Returns the neighbours for a chunk /// We do a recursive call incase they have not spawned and when they do they will add themselfs to the neighbours /// </summary> /// <param name="chunk"></param> public void GenerateChunkNeighbours(int nSteps = 1) { for (int i = 0; i < _getneighbours.Length; i++) { _neighbourPositionCache.x = (int)_getneighbours[i].x + ChunkPosition.x; _neighbourPositionCache.y = (int)_getneighbours[i].z + ChunkPosition.y; if (TerrainGeneration.Chunks.ContainsKey(_neighbourPositionCache)) { TerrainChunk neighbourChunk = TerrainGeneration.Chunks[_neighbourPositionCache]; if (nSteps > 1) { neighbourChunk.GenerateChunkNeighbours(nSteps - 1); } ChunkNeighbours[i] = neighbourChunk; } else { ChunkNeighbours[i] = null; } } }