// 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); }
/// <summary> /// Copies a chunk from one location to another. /// </summary> /// <param name="src_cx">The global X-coordinate of the source chunk.</param> /// <param name="src_cz">The global Z-coordinate of the source chunk.</param> /// <param name="dst_cx">The global X-coordinate of the destination chunk.</param> /// <param name="dst_cz">The global Z-coordinate of the destination chunk.</param> /// <returns>A <see cref="ChunkRef"/> for the destination chunk.</returns> public ChunkRef CopyChunk(int src_cx, int src_cz, int dst_cx, int dst_cz) { IRegion src_r = GetRegion(src_cx, src_cz); if (src_r == null) { return(null); } IRegion dst_r = GetRegion(dst_cx, dst_cz); if (dst_r == null) { int rx = dst_cx >> REGION_XLOG; int rz = dst_cz >> REGION_ZLOG; dst_r = _regionMan.CreateRegion(rx, rz); } IChunk c = src_r.GetChunk(src_cx & REGION_XMASK, src_cz & REGION_ZMASK); c.SetLocation(dst_cx, dst_cz); dst_r.SaveChunk(c); return(dst_r.GetChunkRef(dst_cx & REGION_XMASK, dst_cz & REGION_ZMASK)); }
public virtual bool MoveNext() { if (_region == null) { return(false); } if (_enum == null) { return(MoveNextInRegion()); } else { while (true) { if (_x >= RegionChunkManager.REGION_XLEN) { if (!_enum.MoveNext()) { return(false); } _x = 0; _z = -1; _region = _enum.Current; } if (MoveNextInRegion()) { _chunk = _region.GetChunkRef(_x, _z); return(true); } } } }
/// <inheritdoc/> public ChunkRef GetChunkRef(int cx, int cz) { IRegion r = GetRegion(cx, cz); if (r == null) { return(null); } return(r.GetChunkRef(cx & REGION_XMASK, cz & REGION_ZMASK)); }
/// <inheritdoc/> public ChunkRef SetChunk(int cx, int cz, IChunk chunk) { IRegion r = GetRegion(cx, cz); if (r == null) { int rx = cx >> REGION_XLOG; int rz = cz >> REGION_ZLOG; r = _regionMan.CreateRegion(rx, rz); } chunk.SetLocation(cx, cz); r.SaveChunk(chunk); return(r.GetChunkRef(cx & REGION_XMASK, cz & REGION_ZMASK)); }