public GetChunk ( int x, int z, bool GenerateNewChunkIfNeeded ) : Chunk | ||
x | int | |
z | int | |
GenerateNewChunkIfNeeded | bool | |
Résultat | Chunk |
public Chunk GetChunk(int x, int z, bool GenerateNewChunkIfNeeded)
{
if (mCurrentChunk != null && mCurrentChunkX == x && mCurrentChunkZ == z)
return mCurrentChunk;
mCurrentChunkX = x;
mCurrentChunkZ = z;
Vector2i id = GetChunkHandle(x, z);
Chunk c;
double min, max;
if (!mChunks.TryGetValue(id, out c))
{
if (File.Exists(GetChunkFilename(x, z)))
{
mCurrentChunk = _LoadChunk(x, z);
return mCurrentChunk;
}
if (GenerateNewChunkIfNeeded)
{
Generate(x, z, out min, out max);
mCurrentChunk = GetChunk(x, z);
return mCurrentChunk;
}
return null;
}
mCurrentChunk = c;
return c;
}
public void TEST002_SaveMap() { if (Directory.Exists("002")) Directory.Delete("002", true); Directory.CreateDirectory("002"); // Saves map here. InfdevHandler mh = new InfdevHandler(); mh.Save("002/level.dat"); mh.SetDimension(0); Chunk cnkA = mh.NewChunk(0, 0); cnkA.Blocks[0, 0, 0] = 0x01; cnkA.Blocks[0, 0, 1] = 0x02; cnkA.Blocks[0, 0, 2] = 0x03; cnkA.Blocks[0, 0, 3] = 0x04; cnkA.Save(); FileInfo fA = new FileInfo(cnkA.Filename); Assert.Greater(fA.Length, 0, "System writing zero-length chunks."); Chunk cnkB = mh.GetChunk(0, 0); Assert.AreEqual(cnkB.Blocks[0, 0, 0], 0x01); Assert.AreEqual(cnkB.Blocks[0, 0, 1], 0x02); Assert.AreEqual(cnkB.Blocks[0, 0, 2], 0x03); Assert.AreEqual(cnkB.Blocks[0, 0, 3], 0x04); Directory.Delete("002", true); }