Exemplo n.º 1
0
        /// <summary>
        /// Deletes a chunk from the underlying data store at the given local coordinates relative to this region.
        /// </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>
        /// <returns>True if there is a chunk was deleted; false otherwise.</returns>
        /// <remarks>If the local coordinates are out of bounds for this region, the action will be forwarded to the correct region
        /// transparently.</remarks>
        public bool DeleteChunk(int lcx, int lcz)
        {
            if (!LocalBoundsCheck(lcx, lcz))
            {
                IRegion alt = GetForeignRegion(lcx, lcz);
                return((alt == null) ? false : alt.DeleteChunk(ForeignX(lcx), ForeignZ(lcz)));
            }

            RegionFile rf = GetRegionFile();

            if (!rf.HasChunk(lcx, lcz))
            {
                return(false);
            }

            rf.DeleteChunk(lcx, lcz);

            ChunkKey k = new ChunkKey(ChunkGlobalX(lcx), ChunkGlobalZ(lcz));

            _cache.Remove(k);

            if (ChunkCount() == 0)
            {
                _regionMan.DeleteRegion(X, Z);
                _regionFile.Target = null;
            }

            return(true);
        }
Exemplo n.º 2
0
        // XXX: Consider revising foreign lookup support
        /// <inherits />
        public ChunkRef GetChunkRef(int lcx, int lcz)
        {
            if (!LocalBoundsCheck(lcx, lcz))
            {
                IRegion alt = GetForeignRegion(lcx, lcz);
                return((alt == null) ? null : alt.GetChunkRef(ForeignX(lcx), ForeignZ(lcz)));
            }

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

            ChunkKey k = new ChunkKey(cx, cz);
            ChunkRef c = _cache.Fetch(k);

            if (c != null)
            {
                return(c);
            }

            c = ChunkRef.Create(this, lcx, lcz);
            if (c != null)
            {
                _cache.Insert(c);
            }

            return(c);
        }
        public ChunkRef Fetch(ChunkKey key)
        {
            ChunkRef c;

            if (!_cache.TryGetValue(key, out c))
            {
                return(null);
            }

            return(c);
        }
        public bool Insert(ChunkRef chunk)
        {
            ChunkKey key = new ChunkKey(chunk.X, chunk.Z);

            ChunkRef c;

            if (!_cache.TryGetValue(key, out c))
            {
                _cache[key] = chunk;
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        private IBoundedDataBlockCollection GetChunk(int x, int z)
        {
            int cx = x / _xdim + (x >> 31);
            int cz = z / _zdim + (z >> 31);

            ChunkKey key = new ChunkKey(cx, cz);

            IBoundedDataBlockCollection chunk;

            if (!_chunks.TryGetValue(key, out chunk))
            {
                chunk        = OnResolveNeighbor(cx, 0, cz);
                _chunks[key] = chunk;
            }

            return(chunk);
        }
 public bool Remove(ChunkKey key)
 {
     _dirty.Remove(key);
     return(_cache.Remove(key));
 }