Exemplo n.º 1
0
        private void LoadChunks()
        {
            while (currentlyLoading.Count <= MaxLoadTasks && chunkLoadQueue.Count > 0)
            {
                ChunkLocation l = chunkLoadQueue.Dequeue();

                if (GetDistanceSquared(l) > UnloadDistance * UnloadDistance)
                {
                    continue;
                }

                currentlyLoading.Add(l);

                WorldChunk chunk = WorldChunk.CreateWorldChunk(l, this);

                Task.Run(() => {
                    generator.FillChunk(chunk);
                    loadedChunks.Enqueue(chunk);
                });
            }

            while (!loadedChunks.IsEmpty)
            {
                loadedChunks.TryDequeue(out WorldChunk chunk);
                for (int d = 0; d < 6; d++)
                {
                    chunk.SetNeighbor(d, GetChunk(chunk.Location.GetAdjecent(d)));
                }
                chunk.SetMeshUpdates(true);
                chunkMap.Add(chunk.Location, chunk);
                currentlyLoading.Remove(chunk.Location);
            }
        }