diff options
Diffstat (limited to 'src/mesh_generator_thread.cpp')
-rw-r--r-- | src/mesh_generator_thread.cpp | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/src/mesh_generator_thread.cpp b/src/mesh_generator_thread.cpp index b69d7f484..01f4fbd7e 100644 --- a/src/mesh_generator_thread.cpp +++ b/src/mesh_generator_thread.cpp @@ -63,14 +63,11 @@ MeshUpdateQueue::~MeshUpdateQueue() { MutexAutoLock lock(m_mutex); - for (std::map<v3s16, CachedMapBlockData *>::iterator i = m_cache.begin(); - i != m_cache.end(); ++i) { - delete i->second; + for (auto &i : m_cache) { + delete i.second; } - for (std::vector<QueuedMeshUpdate*>::iterator i = m_queue.begin(); - i != m_queue.end(); ++i) { - QueuedMeshUpdate *q = *i; + for (QueuedMeshUpdate *q : m_queue) { delete q; } } @@ -116,9 +113,7 @@ void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool Find if block is already in queue. If it is, update the data and quit. */ - for (std::vector<QueuedMeshUpdate*>::iterator i = m_queue.begin(); - i != m_queue.end(); ++i) { - QueuedMeshUpdate *q = *i; + for (QueuedMeshUpdate *q : m_queue) { if (q->p == p) { // NOTE: We are not adding a new position to the queue, thus // refcount_from_queue stays the same. @@ -141,8 +136,8 @@ void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool m_queue.push_back(q); // This queue entry is a new reference to the cached blocks - for (size_t i=0; i<cached_blocks.size(); i++) { - cached_blocks[i]->refcount_from_queue++; + for (CachedMapBlockData *cached_block : cached_blocks) { + cached_block->refcount_from_queue++; } } @@ -191,19 +186,19 @@ CachedMapBlockData* MeshUpdateQueue::cacheBlock(Map *map, v3s16 p, UpdateMode mo cached_block->data = NULL; } return cached_block; - } else { - // Not yet in cache - CachedMapBlockData *cached_block = new CachedMapBlockData(); - m_cache[p] = cached_block; - MapBlock *b = map->getBlockNoCreateNoEx(p); - if (b) { - cached_block->data = - new MapNode[MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE]; - memcpy(cached_block->data, b->getData(), - MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE * sizeof(MapNode)); - } - return cached_block; } + + // Not yet in cache + CachedMapBlockData *cached_block = new CachedMapBlockData(); + m_cache[p] = cached_block; + MapBlock *b = map->getBlockNoCreateNoEx(p); + if (b) { + cached_block->data = + new MapNode[MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE]; + memcpy(cached_block->data, b->getData(), + MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE * sizeof(MapNode)); + } + return cached_block; } CachedMapBlockData* MeshUpdateQueue::getCachedBlock(const v3s16 &p) |