Fix a memleak pointed by @Zeno- in MeshUpdateQueue
[oweals/minetest.git] / src / voxel.h
index 53b6edbc7b9ab649fa2ef64044c60622d1c28bc8..58ad39be4a890d7f1fe6fe4ab1db6519dd4a024f 100644 (file)
@@ -82,7 +82,7 @@ public:
 
        void addArea(const VoxelArea &a)
        {
-               if(getExtent() == v3s16(0,0,0))
+               if (hasEmptyExtent())
                {
                        *this = a;
                        return;
@@ -96,7 +96,7 @@ public:
        }
        void addPoint(const v3s16 &p)
        {
-               if(getExtent() == v3s16(0,0,0))
+               if(hasEmptyExtent())
                {
                        MinEdge = p;
                        MaxEdge = p;
@@ -137,6 +137,15 @@ public:
        {
                return MaxEdge - MinEdge + v3s16(1,1,1);
        }
+
+       /* Because MaxEdge and MinEdge are included in the voxel area an empty extent
+        * is not represented by (0, 0, 0), but instead (-1, -1, -1)
+        */
+       bool hasEmptyExtent() const
+       {
+               return MaxEdge - MinEdge == v3s16(-1, -1, -1);
+       }
+
        s32 getVolume() const
        {
                v3s16 e = getExtent();
@@ -146,7 +155,7 @@ public:
        {
                // No area contains an empty area
                // NOTE: Algorithms depend on this, so do not change.
-               if(a.getExtent() == v3s16(0,0,0))
+               if(a.hasEmptyExtent())
                        return false;
 
                return(
@@ -204,7 +213,7 @@ public:
                        return;
                }
 
-               assert(contains(a));
+               assert(contains(a));    // pre-condition
 
                // Take back area, XY inclusive
                {
@@ -404,10 +413,21 @@ public:
        }
        // Stuff explodes if non-emerged area is touched with this.
        // Emerge first, and check VOXELFLAG_NO_DATA if appropriate.
-       MapNode & getNodeRefUnsafe(v3s16 p)
+       MapNode & getNodeRefUnsafe(const v3s16 &p)
        {
                return m_data[m_area.index(p)];
        }
+
+       const MapNode & getNodeRefUnsafeCheckFlags(const v3s16 &p)
+       {
+               s32 index = m_area.index(p);
+
+               if (m_flags[index] & VOXELFLAG_NO_DATA)
+                       return ContentIgnoreNode;
+
+               return m_data[index];
+       }
+
        u8 & getFlagsRefUnsafe(v3s16 p)
        {
                return m_flags[m_area.index(p)];
@@ -560,6 +580,8 @@ public:
        */
        u8 *m_flags;
 
+       static const MapNode ContentIgnoreNode;
+
        //TODO: Use these or remove them
        //TODO: Would these make any speed improvement?
        //bool m_pressure_route_valid;