private void _updateChunk() { threadLocked = true; while (modifications.Count > 0) { CubeMod v = modifications.Dequeue(); Vector3 pos = v.position -= position; cubeMap[(int)pos.x, (int)pos.y, (int)pos.z] = v.id; } ClearMeshData(); for (int y = 0; y < CubeData.ChunkHeight; y++) { for (int x = 0; x < CubeData.ChunkWidth; x++) { for (int z = 0; z < CubeData.ChunkWidth; z++) { if (world.blockTypes[cubeMap[x, y, z]].isSolid) { UpdateMeshData(new Vector3(x, y, z)); } } } } lock (world.chunksToDraw){ world.chunksToDraw.Enqueue(this); } threadLocked = false; }
void ApplyModifications() { applyingModifications = true; while (modifications.Count > 0) { Queue <CubeMod> queue = modifications.Dequeue(); while (queue.Count > 0) { CubeMod v = queue.Dequeue(); ChunkCoord c = GetChunkCoordFromVector3(v.position); if (chunks[c.x, c.z] == null) { chunks[c.x, c.z] = new Chunk(c, this, true); activeChunks.Add(c); } chunks[c.x, c.z].modifications.Enqueue(v); if (!chunksToUpdate.Contains(chunks[c.x, c.z])) { chunksToUpdate.Add(chunks[c.x, c.z]); } } } applyingModifications = false; }