Cache consistency bug in Region fixed. Ready for 0.3.

This commit is contained in:
Justin Aquadro 2011-04-12 04:28:38 +00:00
parent d72e7881a5
commit 245e792541
3 changed files with 20 additions and 11 deletions

View file

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number // Build Number
// Revision // Revision
// //
[assembly: AssemblyVersion("0.2.0.0")] [assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")] [assembly: AssemblyFileVersion("0.3.0.0")]

View file

@ -245,7 +245,10 @@ namespace Substrate
_region = _enum.Current; _region = _enum.Current;
} }
if (MoveNextInRegion()) { if (MoveNextInRegion()) {
_chunk = _cm.GetChunkRefInRegion(_region, _x, _z); _chunk = _region.GetChunkRef(_x, _z, _cm);
if (_chunk == null) {
throw new Exception();
}
return true; return true;
} }
} }

View file

@ -264,7 +264,7 @@ namespace Substrate
DeleteChunk(lcx, lcz); DeleteChunk(lcx, lcz);
Chunk c = new Chunk(ChunkGlobalX(lcx), ChunkGlobalZ(lcz)); Chunk c = new Chunk(lcx, lcz);
c.Save(GetChunkOutStream(lcx, lcz)); c.Save(GetChunkOutStream(lcx, lcz));
ChunkRef cr = new ChunkRef(this, cache, lcx, lcz); ChunkRef cr = new ChunkRef(this, cache, lcx, lcz);
@ -356,8 +356,10 @@ namespace Substrate
{ {
int saved = 0; int saved = 0;
foreach (ChunkRef c in _dirty.Values) { foreach (ChunkRef c in _dirty.Values) {
int lcx = c.LocalX; int cx = c.X;
int lcz = c.LocalZ; int cz = c.Z;
int lcx = cx - _rx * ChunkManager.REGION_XLEN;
int lcz = cz - _rz * ChunkManager.REGION_ZLEN;
if (!ChunkExists(lcx, lcz)) { if (!ChunkExists(lcx, lcz)) {
throw new MissingChunkException(); throw new MissingChunkException();
@ -384,8 +386,10 @@ namespace Substrate
public bool MarkChunkDirty (ChunkRef chunk) public bool MarkChunkDirty (ChunkRef chunk)
{ {
int lcx = chunk.LocalX; int cx = chunk.X;
int lcz = chunk.LocalZ; int cz = chunk.Z;
int lcx = cx - _rx * ChunkManager.REGION_XLEN;
int lcz = cz - _rz * ChunkManager.REGION_ZLEN;
ChunkKey k = new ChunkKey(lcx, lcz); ChunkKey k = new ChunkKey(lcx, lcz);
if (!_dirty.ContainsKey(k)) { if (!_dirty.ContainsKey(k)) {
@ -397,10 +401,12 @@ namespace Substrate
public bool MarkChunkClean (ChunkRef chunk) public bool MarkChunkClean (ChunkRef chunk)
{ {
int lcx = chunk.LocalX; int cx = chunk.X;
int lcz = chunk.LocalZ; int cz = chunk.Z;
int lcx = cx - _rx * ChunkManager.REGION_XLEN;
int lcz = cz - _rz * ChunkManager.REGION_ZLEN;
ChunkKey k = new ChunkKey(lcx, lcz); ChunkKey k = new ChunkKey(lcx, lcx);
if (_dirty.ContainsKey(k)) { if (_dirty.ContainsKey(k)) {
_dirty.Remove(k); _dirty.Remove(k);
return true; return true;