示例#1
0
        private void Chunk_OnChunkUpdate(Chunk sender, int index)
        {
            var position = TilePosition.FromIndex(index);

            position.X += sender.Position.TileX;
            position.Y += sender.Position.TileY;

            var tile  = sender.GetTile(index);
            var order = new BuildOrder(position, tile);

            OnBuildOrder?.Invoke(this, sender, order);
        }
示例#2
0
        private void ApplyBuildOrders()
        {
            while (_buildOrders.Count > 0)
            {
                BuildOrder    order    = _buildOrders.Dequeue();
                ChunkPosition chunkPos = order.Position;
                if (TryGetChunk(chunkPos, out Chunk chunk))
                {
                    chunk.TrySetTile(order.Position, order.Tile);
                    OnBuildOrder?.Invoke(this, chunk, order);
                }
                else
                {
                    _buildOrderBuffer.Push(order);
                }
            }

            while (_buildOrderBuffer.Count > 0)
            {
                BuildOrder order = _buildOrderBuffer.Pop();
                _buildOrders.Enqueue(order);
            }
        }