Exemplo n.º 1
0
        public static WorldChunk CreateWorldChunk(ChunkLocation l, BlockWorld w)
        {
            WorldChunk c = pool.Get();

            c.SetUp(l, w);
            return(c);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        private void UpdateChunkQueues()
        {
            for (int x = -LoadDistance; x <= LoadDistance; x++)
            {
                for (int z = -LoadDistance; z <= LoadDistance; z++)
                {
                    for (int y = 0; y < Height; y++)
                    {
                        ChunkLocation l = new ChunkLocation(centerX + x, y, centerZ + z);
                        if (GetDistanceSquared(l) <= LoadDistance * LoadDistance && !currentlyLoading.Contains(l) && !chunkMap.ContainsKey(l))
                        {
                            if (chunkLoadQueue.Contains(l))
                            {
                                chunkLoadQueue.TryUpdatePriority(l, GetDistanceSquared(l, true));
                            }
                            else
                            {
                                chunkLoadQueue.Enqueue(l, GetDistanceSquared(l, true));
                            }
                        }
                    }
                }
            }

            foreach (Chunk chunk in chunkMap.Values.Where(c => GetDistanceSquared(c.Location) > UnloadDistance * UnloadDistance))
            {
                chunkUnloadStack.Push(chunk);
            }
        }
Exemplo n.º 4
0
 private void SetUp(ChunkLocation l, BlockWorld world)
 {
     location       = l;
     this.world     = world;
     renderedblocks = 0;
     meshready      = false;
     for (int i = 0; i < blocks.Length; i++)
     {
         blocks[i] = Blocks.Air;
     }
     for (int i = 0; i < metadata.Length; i++)
     {
         metadata[i] = 0;
     }
 }
Exemplo n.º 5
0
        public Block GetBlock(int x, int y, int z)
        {
            ChunkLocation l = ChunkLocation.FromPos(x, y, z);

            return(GetChunk(l).GetBlockDirect(x - l.WX, y - l.WY, z - l.WZ));
        }
Exemplo n.º 6
0
 private int GetDistanceSquared(ChunkLocation l, bool y = false)
 {
     return((l.X - centerX) * (l.X - centerX) +
            (l.Z - centerZ) * (l.Z - centerZ) +
            (y ? (l.Y - Height / 2) * (l.Y - Height / 2) : 0));
 }
Exemplo n.º 7
0
 private Chunk GetChunk(ChunkLocation l)
 {
     return(chunkMap.TryGetValue(l, out Chunk c) ? c : BorderChunk.Instance);
 }
Exemplo n.º 8
0
        public bool SetBlock(int x, int y, int z, Block b, byte m)
        {
            ChunkLocation l = ChunkLocation.FromPos(x, y, z);

            return(GetChunk(l).SetBlockDirect(x - l.WX, y - l.WY, z - l.WZ, b, m));
        }