Fixed cache bug that would lose dirty chunks.

This commit is contained in:
Justin Aquadro 2011-08-14 19:32:46 +00:00
parent fa1052ab16
commit 7c4ef996d2

View file

@ -22,6 +22,8 @@ namespace Substrate.Core
{ {
ChunkKey key = new ChunkKey(chunk.X, chunk.Z); ChunkKey key = new ChunkKey(chunk.X, chunk.Z);
_dirty.Remove(key);
ChunkRef c; ChunkRef c;
if (!_cache.TryGetValue(key, out c)) { if (!_cache.TryGetValue(key, out c)) {
_cache[key] = chunk; _cache[key] = chunk;
@ -40,13 +42,17 @@ namespace Substrate.Core
public ChunkRef Fetch (ChunkKey key) public ChunkRef Fetch (ChunkKey key)
{ {
ChunkRef c; ChunkRef c;
if (!_cache.TryGetValue(key, out c)) { if (_dirty.TryGetValue(key, out c)) {
return null; return c;
} }
if (_cache.TryGetValue(key, out c)) {
return c; return c;
} }
return null;
}
public IEnumerator<ChunkRef> GetDirtyEnumerator () public IEnumerator<ChunkRef> GetDirtyEnumerator ()
{ {
return _dirty.Values.GetEnumerator(); return _dirty.Values.GetEnumerator();
@ -74,32 +80,6 @@ namespace Substrate.Core
} }
} }
/*public bool MarkChunkDirty (ChunkRef chunk)
{
int cx = chunk.X;
int cz = chunk.Z;
ChunkKey k = new ChunkKey(cx, cz);
if (!_dirty.ContainsKey(k)) {
_dirty.Add(k, chunk);
return true;
}
return false;
}
public bool MarkChunkClean (ChunkRef chunk)
{
int cx = chunk.X;
int cz = chunk.Z;
ChunkKey k = new ChunkKey(cx, cz);
if (_dirty.ContainsKey(k)) {
_dirty.Remove(k);
return true;
}
return false;
}*/
#endregion #endregion
} }
} }