]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mapblock.h
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / mapblock.h
index e331c4840c5b351985cc1337d16f89f912ef8e4b..7b82301e9812492e204c0c341b712a0c3686dc94 100644 (file)
@@ -17,11 +17,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#ifndef MAPBLOCK_HEADER
-#define MAPBLOCK_HEADER
+#pragma once
 
 #include <set>
-#include "debug.h"
 #include "irr_v3d.h"
 #include "mapnode.h"
 #include "exceptions.h"
@@ -32,7 +30,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"
+#include "mapgen/mapgen.h"
 
 class Map;
 class NodeMetadataList;
@@ -65,7 +63,8 @@ class VoxelManipulator;
 #define MOD_REASON_STATIC_DATA_REMOVED       (1 << 16)
 #define MOD_REASON_STATIC_DATA_CHANGED       (1 << 17)
 #define MOD_REASON_EXPIRE_DAYNIGHTDIFF       (1 << 18)
-#define MOD_REASON_UNKNOWN                   (1 << 19)
+#define MOD_REASON_VMANIP                    (1 << 19)
+#define MOD_REASON_UNKNOWN                   (1 << 20)
 
 ////
 //// MapBlock itself
@@ -115,6 +114,8 @@ class MapBlock
                } else if (mod == m_modified) {
                        m_modified_reason |= reason;
                }
+               if (mod == MOD_STATE_WRITE_NEEDED)
+                       contents_cached = false;
        }
 
        inline u32 getModified()
@@ -257,7 +258,7 @@ class MapBlock
                *valid_position = isValidPosition(x, y, z);
 
                if (!*valid_position)
-                       return MapNode(CONTENT_IGNORE);
+                       return {CONTENT_IGNORE};
 
                return data[z * zstride + y * ystride + x];
        }
@@ -294,8 +295,8 @@ class MapBlock
        inline MapNode getNodeNoCheck(s16 x, s16 y, s16 z, bool *valid_position)
        {
                *valid_position = data != nullptr;
-               if (!valid_position)
-                       return MapNode(CONTENT_IGNORE);
+               if (!*valid_position)
+                       return {CONTENT_IGNORE};
 
                return data[z * zstride + y * ystride + x];
        }
@@ -339,19 +340,6 @@ class MapBlock
        // is not valid on this MapBlock.
        bool isValidPositionParent(v3s16 p);
        MapNode getNodeParent(v3s16 p, bool *is_valid_position = NULL);
-       void setNodeParent(v3s16 p, MapNode & n);
-
-       inline void drawbox(s16 x0, s16 y0, s16 z0, s16 w, s16 h, s16 d, MapNode node)
-       {
-               for (u16 z = 0; z < d; z++)
-               for (u16 y = 0; y < h; y++)
-               for (u16 x = 0; x < w; x++)
-                       setNode(x0 + x, y0 + y, z0 + z, node);
-       }
-
-       // See comments in mapblock.cpp
-       bool propagateSunlight(std::set<v3s16> &light_sources,
-               bool remove_light=false, bool *black_air_left=NULL);
 
        // Copies data to VoxelManipulator to getPosRelative()
        void copyTo(VoxelManipulator &dst);
@@ -458,12 +446,12 @@ class MapBlock
        //// Node Timers
        ////
 
-       inline NodeTimer getNodeTimer(v3s16 p)
+       inline NodeTimer getNodeTimer(const v3s16 &p)
        {
                return m_node_timers.get(p);
        }
 
-       inline void removeNodeTimer(v3s16 p)
+       inline void removeNodeTimer(const v3s16 &p)
        {
                m_node_timers.remove(p);
        }
@@ -485,7 +473,7 @@ class MapBlock
        // These don't write or read version by itself
        // Set disk to true for on-disk format, false for over-the-network format
        // Precondition: version >= SER_FMT_VER_LOWEST_WRITE
-       void serialize(std::ostream &os, u8 version, bool disk);
+       void serialize(std::ostream &os, u8 version, bool disk, int compression_level);
        // If disk == true: In addition to doing other things, will add
        // unknown blocks from id-name mapping to wndef
        void deSerialize(std::istream &is, u8 version, bool disk);
@@ -534,6 +522,14 @@ class MapBlock
 
        static const u32 nodecount = MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE;
 
+       //// ABM optimizations ////
+       // Cache of content types
+       std::unordered_set<content_t> contents;
+       // True if content types are cached
+       bool contents_cached = false;
+       // True if we never want to cache content types for this block
+       bool do_not_cache_contents = false;
+
 private:
        /*
                Private member variables
@@ -642,34 +638,17 @@ inline bool blockpos_over_max_limit(v3s16 p)
 /*
        Returns the position of the block where the node is located
 */
-inline v3s16 getNodeBlockPos(v3s16 p)
-{
-       return getContainerPos(p, MAP_BLOCKSIZE);
-}
-
-inline v2s16 getNodeSectorPos(v2s16 p)
+inline v3s16 getNodeBlockPos(const v3s16 &p)
 {
        return getContainerPos(p, MAP_BLOCKSIZE);
 }
 
-inline s16 getNodeBlockY(s16 y)
-{
-       return getContainerPos(y, MAP_BLOCKSIZE);
-}
-
 inline void getNodeBlockPosWithOffset(const v3s16 &p, v3s16 &block, v3s16 &offset)
 {
        getContainerPosWithOffset(p, MAP_BLOCKSIZE, block, offset);
 }
 
-inline void getNodeSectorPosWithOffset(const v2s16 &p, v2s16 &block, v2s16 &offset)
-{
-       getContainerPosWithOffset(p, MAP_BLOCKSIZE, block, offset);
-}
-
 /*
        Get a quick string to describe what a block actually contains
 */
 std::string analyze_block(MapBlock *block);
-
-#endif