forked from mirrors/NBTExplorer
Added some chunk/region creation support
This commit is contained in:
parent
3d0caa7a28
commit
e88ea3c69a
8 changed files with 88 additions and 2 deletions
|
@ -189,6 +189,11 @@ namespace NBToolkit
|
|||
return _cm.GetChunkRef(cx, cz);
|
||||
}
|
||||
|
||||
public ChunkRef CreateChunk (int cx, int cz)
|
||||
{
|
||||
return _cm.CreateChunk(cx, cz);
|
||||
}
|
||||
|
||||
public bool ChunkExists (int cx, int cz)
|
||||
{
|
||||
return _cm.ChunkExists(cx, cz);
|
||||
|
|
|
@ -123,6 +123,19 @@ namespace Substrate
|
|||
}
|
||||
}
|
||||
|
||||
public ChunkRef CreateChunk (int cx, int cz)
|
||||
{
|
||||
DeleteChunk(cx, cz);
|
||||
Chunk c = new Chunk(cx, cz);
|
||||
c.Save(GetChunkOutStream(cx, cz));
|
||||
|
||||
ChunkRef cr = new ChunkRef(this, this, cx, cz);
|
||||
ChunkKey k = new ChunkKey(cx, cz);
|
||||
_cache[k] = new WeakReference(cr);
|
||||
|
||||
return cr;
|
||||
}
|
||||
|
||||
public bool ChunkExists (int cx, int cz)
|
||||
{
|
||||
return new ChunkFile(_mapPath, cx, cz).Exists();
|
||||
|
|
|
@ -39,6 +39,7 @@ namespace Substrate
|
|||
|
||||
Chunk GetChunk (int cx, int cz);
|
||||
ChunkRef GetChunkRef (int cx, int cz);
|
||||
ChunkRef CreateChunk (int cx, int cz);
|
||||
|
||||
bool ChunkExists (int cx, int cz);
|
||||
|
||||
|
|
|
@ -85,6 +85,18 @@ namespace Substrate
|
|||
return r.ChunkExists(cx & REGION_XMASK, cz & REGION_ZMASK);
|
||||
}
|
||||
|
||||
public ChunkRef CreateChunk (int cx, int cz)
|
||||
{
|
||||
Region 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, this);
|
||||
}
|
||||
|
||||
public bool MarkChunkDirty (ChunkRef chunk)
|
||||
{
|
||||
Region r = GetRegion(chunk.X, chunk.Z);
|
||||
|
|
|
@ -213,6 +213,25 @@ namespace Substrate
|
|||
}
|
||||
}
|
||||
|
||||
public ChunkRef CreateChunk (int lcx, int lcz)
|
||||
{
|
||||
return CreateChunk(lcx, lcz, this);
|
||||
}
|
||||
|
||||
public ChunkRef CreateChunk (int lcx, int lcz, IChunkCache cache)
|
||||
{
|
||||
DeleteChunk(lcx, lcz);
|
||||
|
||||
Chunk c = new Chunk(ChunkGlobalX(lcx), ChunkGlobalZ(lcz));
|
||||
c.Save(GetChunkOutStream(lcx, lcz));
|
||||
|
||||
ChunkRef cr = new ChunkRef(this, cache, lcx, lcz);
|
||||
ChunkKey k = new ChunkKey(lcx, lcz);
|
||||
_cache[k] = new WeakReference(cr);
|
||||
|
||||
return cr;
|
||||
}
|
||||
|
||||
|
||||
#region IChunkCollection Members
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace Substrate
|
|||
protected void ReadFile ()
|
||||
{
|
||||
// Get last udpate time
|
||||
long newModified = 0;
|
||||
long newModified = -1;
|
||||
try {
|
||||
if (File.Exists(fileName)) {
|
||||
newModified = Timestamp(File.GetLastWriteTime(fileName));
|
||||
|
|
|
@ -5,7 +5,17 @@ using System.Collections;
|
|||
|
||||
namespace Substrate
|
||||
{
|
||||
public class RegionManager : IEnumerable<Region>
|
||||
public interface IRegionContainer
|
||||
{
|
||||
bool RegionExists (int rx, int rz);
|
||||
|
||||
Region GetRegion (int rx, int rz);
|
||||
Region CreateRegion (int rx, int rz);
|
||||
|
||||
bool DeleteRegion (int rx, int rz);
|
||||
}
|
||||
|
||||
public class RegionManager : IRegionContainer, IEnumerable<Region>
|
||||
{
|
||||
protected string _regionPath;
|
||||
|
||||
|
@ -35,6 +45,26 @@ namespace Substrate
|
|||
}
|
||||
}
|
||||
|
||||
public bool RegionExists (int rx, int rz)
|
||||
{
|
||||
Region r = GetRegion(rx, rz);
|
||||
return r != null;
|
||||
}
|
||||
|
||||
public Region CreateRegion (int rx, int rz)
|
||||
{
|
||||
Region r = GetRegion(rx, rz);
|
||||
if (r == null) {
|
||||
string fp = "r." + rx + "." + rz + ".mcr";
|
||||
new RegionFile(Path.Combine(_regionPath, fp));
|
||||
|
||||
r = new Region(this, rx, rz);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
public Region GetRegion (string filename)
|
||||
{
|
||||
int rx, rz;
|
||||
|
@ -45,6 +75,7 @@ namespace Substrate
|
|||
return GetRegion(rx, rz);
|
||||
}
|
||||
|
||||
|
||||
public string GetRegionPath ()
|
||||
{
|
||||
return _regionPath;
|
||||
|
|
|
@ -119,6 +119,11 @@ namespace Substrate
|
|||
private string _dim;
|
||||
private string _regionDir;
|
||||
|
||||
public RegionManager RegionManager
|
||||
{
|
||||
get { return _regionMan; }
|
||||
}
|
||||
|
||||
public BetaWorld (string path)
|
||||
: this(path, "region", "")
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue