Modernize client code (#6250)
[oweals/minetest.git] / src / mesh_generator_thread.cpp
index 126bf6327e896f2f6d1ee08624e074e2b9a4361f..b69d7f484bfd3eb1c3078b1364dc0b1c4263be44 100644 (file)
@@ -28,40 +28,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        CachedMapBlockData
 */
 
-CachedMapBlockData::CachedMapBlockData():
-       p(-1337,-1337,-1337),
-       data(NULL),
-       refcount_from_queue(0),
-       last_used_timestamp(time(0))
-{
-}
-
 CachedMapBlockData::~CachedMapBlockData()
 {
        assert(refcount_from_queue == 0);
 
-       if (data)
-               delete[] data;
+       delete[] data;
 }
 
 /*
        QueuedMeshUpdate
 */
 
-QueuedMeshUpdate::QueuedMeshUpdate():
-       p(-1337,-1337,-1337),
-       ack_block_to_server(false),
-       urgent(false),
-       crack_level(-1),
-       crack_pos(0,0,0),
-       data(NULL)
-{
-}
-
 QueuedMeshUpdate::~QueuedMeshUpdate()
 {
-       if (data)
-               delete data;
+       delete data;
 }
 
 /*
@@ -83,6 +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 (std::vector<QueuedMeshUpdate*>::iterator i = m_queue.begin();
                        i != m_queue.end(); ++i) {
                QueuedMeshUpdate *q = *i;
@@ -238,7 +223,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;
@@ -281,6 +266,7 @@ void MeshUpdateQueue::cleanupCache()
                if (cached_block->refcount_from_queue == 0 &&
                                cached_block->last_used_timestamp < t_now - cache_seconds) {
                        m_cache.erase(it++);
+                       delete cached_block;
                } else {
                        ++it;
                }