From 6e86d20f730aa46e0fa6b13b26a3b2586d21e513 Mon Sep 17 00:00:00 2001 From: tycho Date: Thu, 24 Sep 2015 15:43:31 +0100 Subject: Add new "ForEach" function: ForEachLoadedChunk. --- src/ChunkMap.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/ChunkMap.cpp') diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index aeae8f350..a11ceb060 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2576,6 +2576,34 @@ bool cChunkMap::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinCh +bool cChunkMap::ForEachLoadedChunk(std::function 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: -- cgit v1.2.3