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
        /// <inheritdoc/>
        public ChunkRef CreateChunk(int cx, int cz)
        {
            IRegion r = GetRegion(cx, cz);

            if (r == null)
            {
                int rx = cx >> REGION_XLOG;
                int rz = cz >> REGION_ZLOG;
                r = _regionMan.CreateRegion(rx, rz);
            }

            return(r.CreateChunk(cx & REGION_XMASK, cz & REGION_ZMASK));
        }
Esempio n. 3
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);
        }