Esempio n. 1
0
        /// <summary>
        /// Saves an existing <see cref="IChunk"/> to the region at the given local coordinates.
        /// </summary>
        /// <param name="lcx">The local X-coordinate of a chunk relative to this region.</param>
        /// <param name="lcz">The local Z-coordinate of a chunk relative to this region.</param>
        /// <param name="chunk">A <see cref="IChunk"/> to save to the given location.</param>
        /// <returns>A <see cref="ChunkRef"/> represneting the <see cref="IChunk"/> at its new location.</returns>
        /// <remarks>If the local coordinates are out of bounds for this region, the action will be forwarded to the correct region
        /// transparently.  The <see cref="IChunk"/>'s internal global coordinates will be updated to reflect the new location.</remarks>
        public ChunkRef SetChunk(int lcx, int lcz, IChunk chunk)
        {
            if (!LocalBoundsCheck(lcx, lcz))
            {
                IRegion alt = GetForeignRegion(lcx, lcz);
                return((alt == null) ? null : alt.CreateChunk(ForeignX(lcx), ForeignZ(lcz)));
            }

            DeleteChunk(lcx, lcz);

            int cx = lcx + _rx * XDIM;
            int cz = lcz + _rz * ZDIM;

            chunk.SetLocation(cx, cz);
            using (Stream chunkOutStream = GetChunkOutStream(lcx, lcz))
            {
                chunk.Save(chunkOutStream);
            }

            ChunkRef cr = ChunkRef.Create(this, lcx, lcz);

            _cache.Insert(cr);

            return(cr);
        }
Esempio n. 2
0
 // XXX: Allows a chunk not part of this region to be saved to it
 /// <exclude/>
 public bool SaveChunk(IChunk chunk)
 {
     using (Stream chunkOutStream = GetChunkOutStream(ForeignX(chunk.X), ForeignZ(chunk.Z)))
     {
         //Console.WriteLine("Region[{0}, {1}].Save({2}, {3})", _rx, _rz, ForeignX(chunk.X),ForeignZ(chunk.Z));
         return(chunk.Save(chunkOutStream));
     }
 }
Esempio n. 3
0
        /// <inheritdoc/>
        public bool SaveChunk(IChunk chunk)
        {
            if (chunk.Save(GetChunkOutStream(ChunkGlobalX(chunk.X), ChunkGlobalZ(chunk.Z))))
            {
                _dirty.Remove(new ChunkKey(chunk.X, chunk.Z));
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        /// <inheritdoc/>
        public ChunkRef SetChunk(int cx, int cz, IChunk chunk)
        {
            DeleteChunk(cx, cz);
            chunk.SetLocation(cx, cz);
            chunk.Save(GetChunkOutStream(cx, cz));

            ChunkRef cr = ChunkRef.Create(this, cx, cz);
            ChunkKey k  = new ChunkKey(cx, cz);

            _cache[k] = cr;

            return(cr);
        }
Esempio n. 5
0
        /// <inherits />
        public ChunkRef CreateChunk(int lcx, int lcz)
        {
            if (!LocalBoundsCheck(lcx, lcz))
            {
                IRegion alt = GetForeignRegion(lcx, lcz);
                return((alt == null) ? null : alt.CreateChunk(ForeignX(lcx), ForeignZ(lcz)));
            }

            DeleteChunk(lcx, lcz);

            int cx = lcx + _rx * XDIM;
            int cz = lcz + _rz * ZDIM;

            IChunk c = CreateChunkCore(cx, cz);

            c.Save(GetChunkOutStream(lcx, lcz));

            ChunkRef cr = ChunkRef.Create(this, lcx, lcz);

            _cache.Insert(cr);

            return(cr);
        }
Esempio n. 6
0
        /// <summary>
        /// Saves an existing <see cref="IChunk"/> to the region at the given local coordinates.
        /// </summary>
        /// <param name="lcx">The local X-coordinate of a chunk relative to this region.</param>
        /// <param name="lcz">The local Z-coordinate of a chunk relative to this region.</param>
        /// <param name="chunk">A <see cref="IChunk"/> to save to the given location.</param>
        /// <returns>A <see cref="ChunkRef"/> represneting the <see cref="IChunk"/> at its new location.</returns>
        /// <remarks>If the local coordinates are out of bounds for this region, the action will be forwarded to the correct region
        /// transparently.  The <see cref="IChunk"/>'s internal global coordinates will be updated to reflect the new location.</remarks>
        public ChunkRef SetChunk(int lcx, int lcz, IChunk chunk)
        {
            if (!LocalBoundsCheck(lcx, lcz)) {
                IRegion alt = GetForeignRegion(lcx, lcz);
                return (alt == null) ? null : alt.CreateChunk(ForeignX(lcx), ForeignZ(lcz));
            }

            DeleteChunk(lcx, lcz);

            int cx = lcx + _rx * XDIM;
            int cz = lcz + _rz * ZDIM;

            chunk.SetLocation(cx, cz);
            chunk.Save(GetChunkOutStream(lcx, lcz));

            ChunkRef cr = ChunkRef.Create(this, lcx, lcz);
            _cache.Insert(cr);

            return cr;
        }
Esempio n. 7
0
 // XXX: Allows a chunk not part of this region to be saved to it
 /// <exclude/>
 public bool SaveChunk(IChunk chunk)
 {
     //Console.WriteLine("Region[{0}, {1}].Save({2}, {3})", _rx, _rz, ForeignX(chunk.X),ForeignZ(chunk.Z));
     return chunk.Save(GetChunkOutStream(ForeignX(chunk.X), ForeignZ(chunk.Z)));
 }