void Update() { Vector2 currentChunkPos = GlobalPosToChunkCoord(transform.position); if (currentChunkPos != CenterChunkPos) { LoadNewChunks(); CenterChunkPos = currentChunkPos; } if (LoadRenderChunkQueue.Count > 0) // New chunks { RenderChunk rc = LoadRenderChunkQueue.Dequeue(); rc.GenerateProceduralTerrain(Seed, Variance, Threshold, Scale, 5); rc.InitializeGameObject(mat); rc.RefreshChunkMesh(); if (LoadRenderChunkQueue.Count == 0) { GC.Collect(); } } if (UpdateRenderChunkQueue.Count > 0) // Existing chunks { RenderChunk rc = UpdateRenderChunkQueue.Dequeue(); rc.RefreshChunkMesh(); //Debug.Log("Refreshed renderchunk"); } }
public Chunk(Vector3 lowerCoord) { LowerGlobalCoord = lowerCoord; RenderChunks = new RenderChunk[numRenderChunks]; for (int i = 0; i < numRenderChunks; i++) { RenderChunks[i] = new RenderChunk(new Vector3(LowerGlobalCoord.x, i * 16, LowerGlobalCoord.z)); } }
public bool RemoveBlock(Vector3 globalPos) { Vector2 chunkPos = GlobalPosToChunkCoord(globalPos); Chunk chunk = Chunks[chunkPos]; RenderChunk renderChunk = chunk.GetRenderChunkByCoord(globalPos); if (renderChunk.RemoveBlock(globalPos)) { UpdateRenderChunkQueue.Enqueue(renderChunk); return(true); } return(false); }
public bool AddBlock(Vector3 globalPos, VoxelType voxelType) { Vector2 chunkPos = GlobalPosToChunkCoord(globalPos); Chunk chunk = Chunks[chunkPos]; RenderChunk renderChunk = chunk.GetRenderChunkByCoord(globalPos); if (renderChunk.AddBlock(globalPos, voxelType)) { UpdateRenderChunkQueue.Enqueue(renderChunk); return(true); } return(false); }