X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmesh_generator_thread.cpp;h=be4bcc1f406d262ae9b0e3c5d6f215ba29bab51c;hb=b1e58c9c35ae3eb6167a0745086cdb0ddb1dd9d7;hp=f06bddb573bd03a33aa156d6606e9691ac2e6dd6;hpb=4faaadc8d50d6ab7a19d22bd5a760c4b8321a51f;p=dragonfireclient.git diff --git a/src/mesh_generator_thread.cpp b/src/mesh_generator_thread.cpp index f06bddb57..be4bcc1f4 100644 --- a/src/mesh_generator_thread.cpp +++ b/src/mesh_generator_thread.cpp @@ -63,22 +63,17 @@ MeshUpdateQueue::~MeshUpdateQueue() { MutexAutoLock lock(m_mutex); - for (std::map::iterator i = m_cache.begin(); - i != m_cache.end(); ++i) { - delete i->second; + for (auto &i : m_cache) { + delete i.second; } - for (std::vector::iterator i = m_queue.begin(); - i != m_queue.end(); ++i) { - QueuedMeshUpdate *q = *i; + for (QueuedMeshUpdate *q : m_queue) { delete q; } } void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent) { - DSTACK(FUNCTION_NAME); - MutexAutoLock lock(m_mutex); cleanupCache(); @@ -116,9 +111,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::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 +134,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; irefcount_from_queue++; + for (CachedMapBlockData *cached_block : cached_blocks) { + cached_block->refcount_from_queue++; } } @@ -191,19 +184,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) @@ -223,7 +216,7 @@ void MeshUpdateQueue::fillDataFromMapBlockCache(QueuedMeshUpdate *q) data->fillBlockDataBegin(q->p); - int t_now = time(0); + std::time_t t_now = std::time(0); // Collect data for 3*3*3 blocks from cache v3s16 dp;