1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Modernize various files (src/m*) (#6267)

* Modernize various files (src/m*)

* range-based for loops
* code style
* C++ headers instead of C headers
* Default operators
* empty function

Thanks to clang-tidy
This commit is contained in:
Loïc Blot 2017-08-18 18:18:25 +02:00 committed by GitHub
parent fb196be8cf
commit c427533389
34 changed files with 254 additions and 355 deletions

View file

@ -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)