示例#1
0
        public WorldGrid()
        {
            _chunks = new Chunk[NumberOfChunksHigh * NumberOfChunksWide];

            for (int y = 0; y < NumberOfChunksHigh; y++)
            {
                for (int x = 0; x < NumberOfChunksWide; x++)
                {
                    var chunkCoordinate = new ChunkCoordinate(x, y);
                    this[chunkCoordinate] = ChunkLoader.LoadChunk(chunkCoordinate);
                }
            }
        }
示例#2
0
        public static Chunk LoadChunk(ChunkCoordinate chunkCoordinate)
        {
            var chunk = new Chunk(chunkCoordinate);

            // for (int y = 0; y < Chunk.NumberOfGridItemsHigh; y++)
            // {
            //   for (int x = 0; x < Chunk.NumberOfGridItemsWide; x++)
            //   {
            //     var gridPosition = new GridCoordinate(chunkCoordinate, new InnerChunkGridCoordinate(x, y));
            //     var gridItem = CreateGridItemFor(gridPosition);
            //
            //     chunk[gridPosition.InnerChunkGridCoordinate] = gridItem;
            //   }
            // }

            return(chunk);
        }
示例#3
0
 /// <summary>
 ///  Gets the chunk at the specified coordinate.
 /// </summary>
 public ref Chunk this[ChunkCoordinate coordinate]
 => ref _chunks[CalculateAbsoluteChunkIndex(coordinate.X, coordinate.Y)];
示例#4
0
 /// <summary>
 ///  Returns true if the given coordinate is a valid coordinate that can be used in this grid.
 /// </summary>
 public bool IsValid(ChunkCoordinate chunkCoordinate)
 {
     return(chunkCoordinate.X >= 0 && chunkCoordinate.X < NumberOfChunksWide &&
            chunkCoordinate.Y >= 0 && chunkCoordinate.Y < NumberOfChunksWide);
 }
示例#5
0
 /// <summary> Constructor. </summary>
 /// <param name="position"> The position of the given chunk. </param>
 public Chunk(ChunkCoordinate position)
 {
     Position      = position;
     _items        = new UnsafeGridItemArray(NumberOfGridItemsWide * NumberOfGridItemsHigh);
     AbsoluteIndex = WorldGrid.CalculateAbsoluteChunkIndex(Position.X, Position.Y);
 }
示例#6
0
 public GridCoordinate(ChunkCoordinate chunkCoordinate, InnerChunkGridCoordinate innerCoordinate)
 {
     X = (chunkCoordinate.X << Chunk.XGridCoordinateToChunkCoordinateBitShift) + innerCoordinate.X;
     Y = (chunkCoordinate.Y << Chunk.YGridCoordinateToChunkCoordinateBitShift) + innerCoordinate.Y;
 }