1
0

Add new "ForEach" function: ForEachLoadedChunk.

This commit is contained in:
tycho
2015-09-24 15:43:31 +01:00
parent 87489dc308
commit 6e86d20f73
6 changed files with 99 additions and 1 deletions

View File

@@ -2576,6 +2576,34 @@ bool cChunkMap::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinCh
bool cChunkMap::ForEachLoadedChunk(std::function<bool(int, int)> a_Callback)
{
cCSLock Lock(m_CSLayers);
for (cChunkLayerList::const_iterator itr = m_Layers.begin(); itr != m_Layers.end(); ++itr) // iterate over ALL loaded layers
{
cChunkLayer * layer = *itr;
for (int x = 0; x < LAYER_SIZE; x++)
{
for (int z = 0; z < LAYER_SIZE; z++)
{
cChunkPtr p = layer->FindChunk(layer->GetX() * LAYER_SIZE + x, layer->GetZ() * LAYER_SIZE + z);
if ((p != nullptr) && p->IsValid()) // if chunk is loaded
{
if (a_Callback(p->GetPosX(), p->GetPosZ()))
{
return false;
}
}
}
}
}
return true;
}
bool cChunkMap::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes)
{
// Convert block coords to chunks coords: