Пример #1
0
        private ChunkBuilder AddBuilder(IntVector2 worldPosition)
        {
            var chunkBuilder = new ChunkBuilder(worldPosition, World.CHUNK_SIZE);

            if (_chunkBuildersByWorldPosition.ContainsKey(worldPosition) ||
                _chunksByWorldPosition.ContainsKey(worldPosition))
            {
                throw new InvalidOperationException($"This world already has a chunk registered at {worldPosition}.");
            }

            Register(chunkBuilder);

            return(chunkBuilder);
        }
Пример #2
0
        private void Register(ChunkBuilder chunkBuilder)
        {
            _builderCache.Add(chunkBuilder);
            _chunkBuildersByWorldPosition[chunkBuilder.Position] = chunkBuilder;

            foreach (var direction in Directions.Cardinals)
            {
                var neighborPos = chunkBuilder.Position + (direction * World.CHUNK_SIZE);

                if (_chunkBuildersByWorldPosition.TryGetValue(neighborPos, out var neighborBuilder))
                {
                    chunkBuilder.AddNeighbor(neighborBuilder, direction);
                    neighborBuilder.AddNeighbor(chunkBuilder, -direction);
                }
                else if (_chunksByWorldPosition.TryGetValue(neighborPos, out var neighborChunk))
                {
                    chunkBuilder.AddNeighbor(neighborChunk, direction);
                }
            }
        }
Пример #3
0
 public bool TryGetNeighborBuilder(IntVector2 direction, out ChunkBuilder neighbor) => _neighborBuilders.TryGetValue(direction, out neighbor);
Пример #4
0
 public void AddNeighbor(ChunkBuilder neighbor, IntVector2 direction) => _neighborBuilders[direction] = neighbor;