Fix a memleak pointed by @Zeno- in MeshUpdateQueue
[oweals/minetest.git] / src / mapblock.h
index 8a7dfc11db9dc2a6bef0907e015cc67adf56c725..8816dc817f7ef7f7f18b3ca44c4972dc50028a3f 100644 (file)
@@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "modifiedstate.h"
 #include "util/numeric.h" // getContainerPos
 #include "settings.h"
+#include "mapgen.h"
 
 class Map;
 class NodeMetadataList;
@@ -153,6 +154,11 @@ public:
                raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_REALLOCATE);
        }
 
+       MapNode* getData()
+       {
+               return data;
+       }
+
        ////
        //// Modification tracking methods
        ////
@@ -632,9 +638,10 @@ private:
        /*!
         * Each bit indicates if light spreading was finished
         * in a direction. (Because the neighbor could also be unloaded.)
-        * Bits: day X+, day Y+, day Z+, day Z-, day Y-, day X-,
-        * night X+, night Y+, night Z+, night Z-, night Y-, night X-,
-        * nothing, nothing, nothing, nothing.
+        * Bits (most significant first):
+        * nothing,  nothing,  nothing,  nothing,
+        * night X-, night Y-, night Z-, night Z+, night Y+, night X+,
+        * day X-,   day Y-,   day Z-,   day Z+,   day Y+,   day X+.
        */
        u16 m_lighting_complete;
 
@@ -669,41 +676,24 @@ typedef std::vector<MapBlock*> MapBlockVect;
 
 inline bool objectpos_over_limit(v3f p)
 {
-       // MAP_BLOCKSIZE must be subtracted to avoid an object being spawned just
-       // within the map generation limit but in a block and sector that extend
-       // beyond the map generation limit.
-       // This avoids crashes caused by sector over limit in createSector().
-       const float object_limit = (MYMIN(MAX_MAP_GENERATION_LIMIT,
-               g_settings->getU16("map_generation_limit")) - MAP_BLOCKSIZE) * BS;
-       return (p.X < -object_limit
-               || p.X > object_limit
-               || p.Y < -object_limit
-               || p.Y > object_limit
-               || p.Z < -object_limit
-               || p.Z > object_limit);
+       const float max_limit_bs = MAX_MAP_GENERATION_LIMIT * BS;
+       return p.X < -max_limit_bs ||
+               p.X >  max_limit_bs ||
+               p.Y < -max_limit_bs ||
+               p.Y >  max_limit_bs ||
+               p.Z < -max_limit_bs ||
+               p.Z >  max_limit_bs;
 }
 
-/*
-       We are checking for any node of the mapblock being beyond the limit.
-
-       At the negative limit we are checking for
-               block minimum nodepos < -mapgenlimit.
-       At the positive limit we are checking for
-               block maximum nodepos > mapgenlimit.
-
-       Block minimum nodepos = blockpos * mapblocksize.
-       Block maximum nodepos = (blockpos + 1) * mapblocksize - 1.
-*/
-inline bool blockpos_over_limit(v3s16 p)
+inline bool blockpos_over_max_limit(v3s16 p)
 {
-       const u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
-               g_settings->getU16("map_generation_limit"));
-       return (p.X * MAP_BLOCKSIZE < -map_gen_limit
-               || (p.X + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
-               || p.Y * MAP_BLOCKSIZE < -map_gen_limit
-               || (p.Y + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
-               || p.Z * MAP_BLOCKSIZE < -map_gen_limit
-               || (p.Z + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit);
+       const s16 max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
+       return p.X < -max_limit_bp ||
+               p.X >  max_limit_bp ||
+               p.Y < -max_limit_bp ||
+               p.Y >  max_limit_bp ||
+               p.Z < -max_limit_bp ||
+               p.Z >  max_limit_bp;
 }
 
 /*