Ejemplo n.º 1
0
 /// <summary>
 ///     Constructs a new instance of TileRef.
 /// </summary>
 /// <param name="mapId">Identifier of the map this tile belongs to.</param>
 /// <param name="gridId">Identifier of the grid this tile belongs to.</param>
 /// <param name="gridIndices">Positional indices of this tile on the grid.</param>
 /// <param name="tile">Actual data of this tile.</param>
 internal TileRef(MapId mapId, GridId gridId, MapIndices gridIndices, Tile tile)
 {
     MapIndex    = mapId;
     GridIndex   = gridId;
     GridIndices = gridIndices;
     Tile        = tile;
 }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public MapIndices GridTileToChunkTile(MapIndices gridTile)
        {
            var size = ChunkSize;
            var x    = MathHelper.Mod(gridTile.X, size);
            var y    = MathHelper.Mod(gridTile.Y, size);

            return(new MapIndices(x, y));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Constructs an instance of a MapGrid chunk.
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="chunkSize"></param>
        public MapChunk(IMapGridInternal grid, int x, int y, ushort chunkSize)
        {
            _grid            = grid;
            LastModifiedTick = grid.CurTick;
            _gridIndices     = new MapIndices(x, y);
            ChunkSize        = chunkSize;

            _tiles    = new Tile[ChunkSize, ChunkSize];
            _snapGrid = new SnapGridCell[ChunkSize, ChunkSize];
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public TileRef GetTileRef(MapIndices indices)
        {
            if (indices.X >= ChunkSize || indices.X < 0 || indices.Y >= ChunkSize || indices.Y < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(indices), "Tile indices out of bounds.");
            }

            var chunkIndices = ChunkTileToGridTile(indices);

            return(new TileRef(_grid.ParentMapId, _grid.Index, chunkIndices, _tiles[indices.X, indices.Y]));
        }
Ejemplo n.º 5
0
 /// <inheritdoc />
 public MapIndices ChunkTileToGridTile(MapIndices chunkTile)
 {
     return(chunkTile + _gridIndices * ChunkSize);
 }