Ejemplo n.º 1
0
        /// <summary>
        /// Convert a given WorldSpace co-ordinate to an in-chunk coordinate (an ItemSpace coordinate)
        /// </summary>
        /// <param name="coordinate"></param>
        /// <returns></returns>
        private ItemSpace WorldSpaceToItem(WorldSpace coordinate)
        {
            var blockX = Math.Abs(coordinate.X) % _chunkHeight;
            var blockY = Math.Abs(coordinate.Y) % _chunkWidth;
            var blockZ = Math.Abs(coordinate.Z) % _chunkDepth;

            return(new ItemSpace((byte)blockX, (byte)blockY, (byte)blockZ));
        }
Ejemplo n.º 2
0
        public void UnloadArea(WorldSpace begin, WorldSpace end)
        {
            var sequence = base.ChunksWithin(begin, end, createIfNull: false)
                           .Select(chunk => TranslateWorldToChunk(chunk.Item1));

            foreach (var chunk in sequence)
            {
                UnloadChunk(chunk);
            }
        }
Ejemplo n.º 3
0
        public void UnloadAreaOutside(WorldSpace begin, WorldSpace end)
        {
            var localChunks = base.ChunksWithin(begin, end, createIfNull: false)
                              .Select(tuple => TranslateWorldToChunk(tuple.Item1))
                              .ToList();

            var worldChunks = All(chunk => !localChunks.Contains(chunk.Item1)).ToList();

            foreach (var chunk in worldChunks)
            {
                UnloadChunk(chunk.Key);
            }
        }
Ejemplo n.º 4
0
        public T this[WorldSpace coordinate]
        {
            get
            {
                // Translate from world-space to item-space
                var chunkSpace = WorldSpaceToItem(coordinate);
                var blockX     = chunkSpace.X;
                var blockY     = chunkSpace.Y;
                var blockZ     = chunkSpace.Z;

                // Flat array, so walk the stride length for the Y component.
                return(_blocks[blockX + (blockY + blockZ * _chunkWidth) * _chunkHeight]);
            }
            set
            {
                var chunkSpace = WorldSpaceToItem(coordinate);
                var blockX     = chunkSpace.X;
                var blockY     = chunkSpace.Y;
                var blockZ     = chunkSpace.Z;

                _blocks[blockX + (blockY + blockZ * _chunkWidth) * _chunkHeight] = value;
            }
        }
Ejemplo n.º 5
0
 public IEnumerable <IEntityLocationData> GetEntitiesAt(WorldSpace coordinates)
 {
     return(_items.Where(item => item.ToWorldSpace() == coordinates));
 }
Ejemplo n.º 6
0
 public new T this[WorldSpace coordinate]
 {
     get { return(base[coordinate]); }
     set { base[coordinate] = value; }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Return a list of chunk sized enumerations from the specified area.
 /// </summary>
 /// <param name="createIfNull">If true, give the user a chance to create chunks</param>
 /// <param name="begin">Starting position</param>
 /// <param name="end">Ending position</param>
 /// <returns>A list of chunk sized enumerations from a specified area as (x,y,z,IEnumerable{T}) in chunk-space coordinates</returns>
 public new IEnumerable <Tuple <ChunkSpace, IEnumerable <T> > > ChunksWithin(WorldSpace begin, WorldSpace end, bool createIfNull)
 {
     return(base.ChunksWithin(begin, end, createIfNull)
            .Select(s => Tuple.Create(TranslateWorldToChunk(s.Item1), s.Item2.AsEnumerable())));
 }
Ejemplo n.º 8
0
 protected virtual T this[WorldSpace coordinates]
 {
     get { return(Get(coordinates)); }
     set { Put(coordinates, value); }
 }