Ejemplo n.º 1
0
        private void TryToDeleteQueuedChunks()
        {
            var chunksToRemove = ChunksToRemove.ToList();

            foreach (var chunkPosition in chunksToRemove)
            {
                if (RequestedChunks.ContainsKey(chunkPosition))
                {
                    RequestedChunks.Remove(chunkPosition);
                    ChunksToRemove.Remove(chunkPosition);
                }
                else if (LoadedChunks.ContainsKey(chunkPosition))
                {
                    var chunk = LoadedChunks[chunkPosition];
                    chunk.Remove();

                    LoadedChunks.Remove(chunkPosition);
                    ChunksToRemove.Remove(chunkPosition);
                }
                else if (!ChunksBeingGenerated.ContainsKey(chunkPosition))
                {
                    ChunksToRemove.Remove(chunkPosition);
                }
            }
        }
Ejemplo n.º 2
0
        private void CreateTerrainForReadyChunks()
        {
            var anyTerrainCreated = false;

            var chunks = ChunksBeingGenerated.ToList();

            foreach (var chunk in chunks)
            {
                if (chunk.Value.IsHeightmapReady())
                {
                    ChunksBeingGenerated.Remove(chunk.Key);
                    LoadedChunks.Add(chunk.Key, chunk.Value);

                    chunk.Value.CreateTerrain();

                    anyTerrainCreated = true;
                    if (OnChunkGenerated != null)
                    {
                        OnChunkGenerated.Invoke(ChunksBeingGenerated.Count);
                    }

                    SetChunkNeighborhood(chunk.Value);
                }
            }

            if (anyTerrainCreated)
            {
                UpdateAllChunkNeighbors();
            }
        }
Ejemplo n.º 3
0
 public bool ChunkCanBeRemoved(int x, int z)
 {
     var key = new Vector2i(x, z);
     return
         RequestedChunks.ContainsKey(key)
         || ChunksBeingGenerated.ContainsKey(key)
         || LoadedChunks.ContainsKey(key);
 }
Ejemplo n.º 4
0
    /// <summary>
    /// Chunks the can be added.
    /// </summary>
    /// <returns><c>true</c>, if can be added was chunked, <c>false</c> otherwise.</returns>
    /// <param name="x">The x coordinate.</param>
    /// <param name="z">The z coordinate.</param>
    public bool                     ChunkCanBeAdded(int x, int z)
    {
        var key = new XVec2I(x, z);

        return
            (!(RequestedChunks.ContainsKey(key) ||
               ChunksBeingGenerated.ContainsKey(key) ||
               LoadedChunks.ContainsKey(key)));
    }
Ejemplo n.º 5
0
        private void GenerateHeightmapForAvailableChunks()
        {
            var requestedChunks = RequestedChunks.ToList();
            if (requestedChunks.Count > 0 && ChunksBeingGenerated.Count < MaxChunkThreads)
            {
                var chunksToAdd = requestedChunks.Take(MaxChunkThreads - ChunksBeingGenerated.Count);
                foreach (var chunkEntry in chunksToAdd)
                {
                    ChunksBeingGenerated.Add(chunkEntry.Key, chunkEntry.Value);
                    RequestedChunks.Remove(chunkEntry.Key);

                    chunkEntry.Value.GenerateHeightmap();
                }
            }
        }