Skip to content

Instantly share code, notes, and snippets.

@Brian1KB
Created May 6, 2016 19:08
Show Gist options
  • Save Brian1KB/ca4ca14c6cdee92881c20358ae1dd12b to your computer and use it in GitHub Desktop.
Save Brian1KB/ca4ca14c6cdee92881c20358ae1dd12b to your computer and use it in GitHub Desktop.
Creates framing chunks
int createdChunks = 0;
Stopwatch sw = new Stopwatch();
sw.Start();
foreach (KeyValuePair<ChunkCoordinates, ChunkColumn> valuePair in _chunkCache)
{
ChunkCoordinates chunkCoordinates = valuePair.Key;
ChunkColumn chunkColumn = valuePair.Value;
if (chunkColumn != null && !chunkColumn.isAllAir)
{
for (int startX = chunkCoordinates.X - 1; startX <= chunkCoordinates.X + 1; startX++)
{
for (int startZ = chunkCoordinates.Z - 1; startZ <= chunkCoordinates.Z + 1; startZ++)
{
ChunkCoordinates surroundingChunkCoordinates = new ChunkCoordinates(startX, startZ);
if (!surroundingChunkCoordinates.Equals(chunkCoordinates))
{
ChunkColumn surroundingChunkColumn;
_chunkCache.TryGetValue(surroundingChunkCoordinates, out surroundingChunkColumn);
if (surroundingChunkColumn == null)
{
ChunkColumn airColumn = new ChunkColumn
{
x = startX,
z = startZ,
isAllAir = true
};
airColumn.GetBatch();
_chunkCache[chunkCoordinates] = airColumn;
createdChunks++;
}
}
}
}
}
}
sw.Stop();
Log.Info("Created " + createdChunks + " air chunks in " + sw.ElapsedMilliseconds + "ms");
return createdChunks;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment