Modernize client code (#6250)
[oweals/minetest.git] / src / mesh_generator_thread.h
index e74861862447b6b72d0b6742613101b01c8d01a4..051a0dc8808d5d47361a0a2e4b801417d0bca360 100644 (file)
@@ -20,31 +20,33 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef MESH_GENERATOR_THREAD_HEADER
 #define MESH_GENERATOR_THREAD_HEADER
 
+#include <ctime>
+#include <mutex>
 #include "mapblock_mesh.h"
 #include "threading/mutex_auto_lock.h"
 #include "util/thread.h"
 
 struct CachedMapBlockData
 {
-       v3s16 p;
-       MapNode *data; // A copy of the MapBlock's data member
-       int refcount_from_queue;
-       int last_used_timestamp;
+       v3s16 p = v3s16(-1337, -1337, -1337);
+       MapNode *data = nullptr; // A copy of the MapBlock's data member
+       int refcount_from_queue = 0;
+       std::time_t last_used_timestamp = std::time(0);
 
-       CachedMapBlockData();
+       CachedMapBlockData() {}
        ~CachedMapBlockData();
 };
 
 struct QueuedMeshUpdate
 {
-       v3s16 p;
-       bool ack_block_to_server;
-       bool urgent;
-       int crack_level;
+       v3s16 p = v3s16(-1337, -1337, -1337);
+       bool ack_block_to_server = false;
+       bool urgent = false;
+       int crack_level = -1;
        v3s16 crack_pos;
-       MeshMakeData *data; // This is generated in MeshUpdateQueue::pop()
+       MeshMakeData *data = nullptr; // This is generated in MeshUpdateQueue::pop()
 
-       QueuedMeshUpdate();
+       QueuedMeshUpdate(){};
        ~QueuedMeshUpdate();
 };
 
@@ -53,10 +55,12 @@ struct QueuedMeshUpdate
 */
 class MeshUpdateQueue
 {
-       enum UpdateMode {
+       enum UpdateMode
+       {
                FORCE_UPDATE,
                SKIP_UPDATE_IF_ALREADY_CACHED,
        };
+
 public:
        MeshUpdateQueue(Client *client);
 
@@ -68,7 +72,7 @@ public:
 
        // Returned pointer must be deleted
        // Returns NULL if queue is empty
-       QueuedMeshUpdate * pop();
+       QueuedMeshUpdate *pop();
 
        u32 size()
        {
@@ -78,10 +82,10 @@ public:
 
 private:
        Client *m_client;
-       std::vector<QueuedMeshUpdate*> m_queue;
+       std::vector<QueuedMeshUpdate *> m_queue;
        std::set<v3s16> m_urgents;
-       std::map<v3s16, CachedMapBlockData*> m_cache;
-       Mutex m_mutex;
+       std::map<v3s16, CachedMapBlockData *> m_cache;
+       std::mutex m_mutex;
 
        // TODO: Add callback to update these when g_settings changes
        bool m_cache_enable_shaders;
@@ -89,25 +93,20 @@ private:
        bool m_cache_smooth_lighting;
        int m_meshgen_block_cache_size;
 
-       CachedMapBlockDatacacheBlock(Map *map, v3s16 p, UpdateMode mode,
-                       size_t *cache_hit_counter=NULL);
-       CachedMapBlockDatagetCachedBlock(const v3s16 &p);
+       CachedMapBlockData *cacheBlock(Map *map, v3s16 p, UpdateMode mode,
+                       size_t *cache_hit_counter = NULL);
+       CachedMapBlockData *getCachedBlock(const v3s16 &p);
        void fillDataFromMapBlockCache(QueuedMeshUpdate *q);
        void cleanupCache();
 };
 
 struct MeshUpdateResult
 {
-       v3s16 p;
-       MapBlockMesh *mesh;
-       bool ack_block_to_server;
-
-       MeshUpdateResult():
-               p(-1338,-1338,-1338),
-               mesh(NULL),
-               ack_block_to_server(false)
-       {
-       }
+       v3s16 p = v3s16(-1338, -1338, -1338);
+       MapBlockMesh *mesh = nullptr;
+       bool ack_block_to_server = false;
+
+       MeshUpdateResult() {}
 };
 
 class MeshUpdateThread : public UpdateThread