Пример #1
0
    // Called by main thread
    // newRequests can be empty
    public void queueChunks(Queue <ChunkRequest> newRequests, Vector3Int playerChunkPosition, Vector3Int playerDirection)
    {
        List <ChunkRequest> ignoredRequests = new List <ChunkRequest>();

        lock (chunkRequests)
        {
            // Remove chunks which are outside the render distance
            for (int i = 0; i < chunkRequests.Count; i++)
            {
                ChunkRequest r    = chunkRequests[i];
                int          dist = (int)(playerChunkPosition - new Vector3Int(r.cx, r.cy, r.cz)).magnitude;
                if (dist > Constants.RENDER_DISTANCE)
                {
                    ignoredRequests.Add(chunkRequests[i]);
                    chunkRequests.RemoveAt(i);
                }
            }

            // Add new chunks - it is known that they are within the render distance
            chunkRequests.InsertRange(0, newRequests);
            newRequests.Clear();

            chunkRequests.Sort(delegate(ChunkRequest x, ChunkRequest y)
            {
                int a = x.GetPriority(playerChunkPosition, playerDirection);
                int b = y.GetPriority(playerChunkPosition, playerDirection);
                return(a - b);
            });

            Monitor.Pulse(chunkRequests);
        }

        if (ignoredRequests.Count > 0)
        {
            TerrainGen.IgnoredChunkRequests(ignoredRequests);
        }
    }