forked from mirrors/NBTExplorer
ChunkRef switched to factory method to fix performance defect
This commit is contained in:
parent
324d997f52
commit
9355a016ca
6 changed files with 44 additions and 30 deletions
|
@ -66,6 +66,11 @@ namespace Substrate
|
|||
|
||||
bool SetBlockLight (int x, int y, int z, int light);
|
||||
bool SetBlockSkyLight (int x, int y, int z, int light);
|
||||
|
||||
//---
|
||||
|
||||
//void ResetBlockLight ();
|
||||
//void ResetSkyLight ();
|
||||
}
|
||||
|
||||
public interface IPropertyBlockContainer : IBlockContainer
|
||||
|
|
|
@ -113,14 +113,12 @@ namespace Substrate
|
|||
return c;
|
||||
}
|
||||
|
||||
try {
|
||||
c = new ChunkRef(this, this, cx, cz);
|
||||
c = ChunkRef.Create(this, this, cx, cz);
|
||||
if (c != null) {
|
||||
_cache[k].Target = c;
|
||||
return c;
|
||||
}
|
||||
catch (MissingChunkException) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public ChunkRef CreateChunk (int cx, int cz)
|
||||
|
@ -129,7 +127,7 @@ namespace Substrate
|
|||
Chunk c = new Chunk(cx, cz);
|
||||
c.Save(GetChunkOutStream(cx, cz));
|
||||
|
||||
ChunkRef cr = new ChunkRef(this, this, cx, cz);
|
||||
ChunkRef cr = ChunkRef.Create(this, this, cx, cz);
|
||||
ChunkKey k = new ChunkKey(cx, cz);
|
||||
_cache[k] = new WeakReference(cr);
|
||||
|
||||
|
|
|
@ -181,44 +181,47 @@ namespace Substrate
|
|||
|
||||
public void RelightDirtyChunks ()
|
||||
{
|
||||
List<ChunkRef> dirty = new List<ChunkRef>();
|
||||
//List<ChunkRef> dirty = new List<ChunkRef>();
|
||||
Dictionary<ChunkKey, ChunkRef> dirty = new Dictionary<ChunkKey, ChunkRef>();
|
||||
|
||||
IEnumerator<ChunkRef> en = _cache.GetDirtyEnumerator();
|
||||
while (en.MoveNext()) {
|
||||
dirty.Add(en.Current);
|
||||
ChunkKey key = new ChunkKey(en.Current.X, en.Current.Z);
|
||||
dirty[key] = en.Current;
|
||||
}
|
||||
|
||||
foreach (ChunkRef chunk in dirty) {
|
||||
foreach (ChunkRef chunk in dirty.Values) {
|
||||
chunk.ResetBlockLight();
|
||||
chunk.ResetSkyLight();
|
||||
}
|
||||
|
||||
foreach (ChunkRef chunk in dirty) {
|
||||
foreach (ChunkRef chunk in dirty.Values) {
|
||||
chunk.RebuildBlockLight();
|
||||
chunk.RebuildSkyLight();
|
||||
}
|
||||
|
||||
foreach (ChunkRef chunk in dirty) {
|
||||
ChunkRef east = chunk.GetEastNeighbor();
|
||||
if (!east.IsDirty) {
|
||||
foreach (ChunkRef chunk in dirty.Values) {
|
||||
|
||||
if (!dirty.ContainsKey(new ChunkKey(chunk.X, chunk.Z - 1))) {
|
||||
ChunkRef east = chunk.GetEastNeighbor();
|
||||
chunk.UpdateEdgeBlockLight(east);
|
||||
chunk.UpdateEdgeSkyLight(east);
|
||||
}
|
||||
|
||||
ChunkRef west = chunk.GetWestNeighbor();
|
||||
if (!west.IsDirty) {
|
||||
if (!dirty.ContainsKey(new ChunkKey(chunk.X, chunk.Z + 1))) {
|
||||
ChunkRef west = chunk.GetWestNeighbor();
|
||||
chunk.UpdateEdgeBlockLight(west);
|
||||
chunk.UpdateEdgeSkyLight(west);
|
||||
}
|
||||
|
||||
ChunkRef north = chunk.GetNorthNeighbor();
|
||||
if (!north.IsDirty) {
|
||||
if (!dirty.ContainsKey(new ChunkKey(chunk.X - 1, chunk.Z))) {
|
||||
ChunkRef north = chunk.GetNorthNeighbor();
|
||||
chunk.UpdateEdgeBlockLight(north);
|
||||
chunk.UpdateEdgeSkyLight(north);
|
||||
}
|
||||
|
||||
ChunkRef south = chunk.GetSouthNeighbor();
|
||||
if (!south.IsDirty) {
|
||||
if (!dirty.ContainsKey(new ChunkKey(chunk.X + 1, chunk.Z))) {
|
||||
ChunkRef south = chunk.GetSouthNeighbor();
|
||||
chunk.UpdateEdgeBlockLight(south);
|
||||
chunk.UpdateEdgeSkyLight(south);
|
||||
}
|
||||
|
|
|
@ -52,16 +52,21 @@ namespace Substrate
|
|||
get { return _dirty; }
|
||||
}
|
||||
|
||||
public ChunkRef (IChunkContainer container, IChunkCache cache, int cx, int cz)
|
||||
private ChunkRef (IChunkContainer container, IChunkCache cache, int cx, int cz)
|
||||
{
|
||||
_container = container;
|
||||
_cache = cache;
|
||||
_cx = cx;
|
||||
_cz = cz;
|
||||
}
|
||||
|
||||
if (!_container.ChunkExists(cx, cz)) {
|
||||
throw new MissingChunkException();
|
||||
public static ChunkRef Create (IChunkContainer container, IChunkCache cache, int cx, int cz)
|
||||
{
|
||||
if (!container.ChunkExists(cx, cz)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ChunkRef(container, cache, cx, cz);
|
||||
}
|
||||
|
||||
public int BlockGlobalX (int x)
|
||||
|
|
|
@ -237,14 +237,12 @@ namespace Substrate
|
|||
return c;
|
||||
}
|
||||
|
||||
try {
|
||||
c = new ChunkRef(this, _cache, lcx, lcz);
|
||||
c = ChunkRef.Create(this, _cache, lcx, lcz);
|
||||
if (c != null) {
|
||||
_cache.Insert(c);
|
||||
return c;
|
||||
}
|
||||
catch (MissingChunkException) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public ChunkRef CreateChunk (int lcx, int lcz)
|
||||
|
@ -262,7 +260,7 @@ namespace Substrate
|
|||
Chunk c = new Chunk(cx, cz);
|
||||
c.Save(GetChunkOutStream(lcx, lcz));
|
||||
|
||||
ChunkRef cr = new ChunkRef(this, _cache, lcx, lcz);
|
||||
ChunkRef cr = ChunkRef.Create(this, _cache, lcx, lcz);
|
||||
_cache.Insert(cr);
|
||||
|
||||
return cr;
|
||||
|
|
|
@ -59,9 +59,14 @@
|
|||
<HintPath>Assemblies\Ionic.Zlib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Source\ChunkCache.cs" />
|
||||
<None Include="Source\Experimental\BlockInterface.cs" />
|
||||
<Compile Include="Source\Level.cs" />
|
||||
<Compile Include="Source\PlayerManager.cs" />
|
||||
<Compile Include="Source\PlayerFile.cs" />
|
||||
|
|
Loading…
Reference in a new issue