]> git.lizzy.rs Git - minetest.git/blobdiff - src/nodedef.h
Remove old rollback migration code (#13082)
[minetest.git] / src / nodedef.h
index 6fc20518df40acc52f7935fc517e046c0283372b..288d09dd836a4c1238635579d318842938d005d6 100644 (file)
@@ -36,14 +36,14 @@ class Client;
 #include "texture_override.h" // TextureOverride
 #include "tileanimation.h"
 
-// PROTOCOL_VERSION >= 37
-static const u8 CONTENTFEATURES_VERSION = 13;
-
 class IItemDefManager;
 class ITextureSource;
 class IShaderSource;
 class IGameDef;
 class NodeResolver;
+#if BUILD_UNITTESTS
+class TestSchematic;
+#endif
 
 enum ContentParamType
 {
@@ -58,13 +58,13 @@ enum ContentParamType2
        CPT2_FULL,
        // Flowing liquid properties
        CPT2_FLOWINGLIQUID,
-       // Direction for chests and furnaces and such
+       // Direction for chests and furnaces and such (with axis rotation)
        CPT2_FACEDIR,
        // Direction for signs, torches and such
        CPT2_WALLMOUNTED,
        // Block level like FLOWINGLIQUID
        CPT2_LEVELED,
-       // 2D rotation for things like plants
+       // 2D rotation
        CPT2_DEGROTATE,
        // Mesh options for plants
        CPT2_MESHOPTIONS,
@@ -76,6 +76,12 @@ enum ContentParamType2
        CPT2_COLORED_WALLMOUNTED,
        // Glasslike framed drawtype internal liquid level, param2 values 0 to 63
        CPT2_GLASSLIKE_LIQUID_LEVEL,
+       // 3 bits of palette index, then degrotate
+       CPT2_COLORED_DEGROTATE,
+       // Simplified direction for chests and furnaces and such (4 directions)
+       CPT2_4DIR,
+       // 6 bits of palette index, then 4dir
+       CPT2_COLORED_4DIR,
 };
 
 enum LiquidType
@@ -94,17 +100,8 @@ enum NodeBoxType
        NODEBOX_CONNECTED, // optionally draws nodeboxes if a neighbor node attaches
 };
 
-struct NodeBox
+struct NodeBoxConnected
 {
-       enum NodeBoxType type;
-       // NODEBOX_REGULAR (no parameters)
-       // NODEBOX_FIXED
-       std::vector<aabb3f> fixed;
-       // NODEBOX_WALLMOUNTED
-       aabb3f wall_top;
-       aabb3f wall_bottom;
-       aabb3f wall_side; // being at the -X side
-       // NODEBOX_CONNECTED
        std::vector<aabb3f> connect_top;
        std::vector<aabb3f> connect_bottom;
        std::vector<aabb3f> connect_front;
@@ -119,9 +116,35 @@ struct NodeBox
        std::vector<aabb3f> disconnected_right;
        std::vector<aabb3f> disconnected;
        std::vector<aabb3f> disconnected_sides;
+};
+
+struct NodeBox
+{
+       enum NodeBoxType type;
+       // NODEBOX_REGULAR (no parameters)
+       // NODEBOX_FIXED
+       std::vector<aabb3f> fixed;
+       // NODEBOX_WALLMOUNTED
+       aabb3f wall_top;
+       aabb3f wall_bottom;
+       aabb3f wall_side; // being at the -X side
+       // NODEBOX_CONNECTED
+       // (kept externally to not bloat the structure)
+       std::shared_ptr<NodeBoxConnected> connected;
 
        NodeBox()
        { reset(); }
+       ~NodeBox() = default;
+
+       inline NodeBoxConnected &getConnected() {
+               if (!connected)
+                       connected = std::make_shared<NodeBoxConnected>();
+               return *connected;
+       }
+       inline const NodeBoxConnected &getConnected() const {
+               assert(connected);
+               return *connected;
+       }
 
        void reset();
        void serialize(std::ostream &os, u16 protocol_version) const;
@@ -190,10 +213,10 @@ enum NodeDrawType
        // paramtype2 = "meshoptions" allows various forms, sizes and
        // vertical and horizontal random offsets.
        NDT_PLANTLIKE,
-       // Fenceposts that connect to neighbouring fenceposts with horizontal bars
+       // Fenceposts that connect to neighboring fenceposts with horizontal bars
        NDT_FENCELIKE,
        // Selects appropriate junction texture to connect like rails to
-       // neighbouring raillikes.
+       // neighboring raillikes.
        NDT_RAILLIKE,
        // Custom Lua-definable structure of multiple cuboids
        NDT_NODEBOX,
@@ -202,7 +225,7 @@ enum NodeDrawType
        // Uses 3 textures, one for frames, second for faces,
        // optional third is a 'special tile' for the liquid.
        NDT_GLASSLIKE_FRAMED,
-       // Draw faces slightly rotated and only on neighbouring nodes
+       // Draw faces slightly rotated and only on neighboring nodes
        NDT_FIRELIKE,
        // Enabled -> ndt_glasslike_framed, disabled -> ndt_glasslike
        NDT_GLASSLIKE_FRAMED_OPTIONAL,
@@ -264,8 +287,7 @@ struct TileDef
        }
 
        void serialize(std::ostream &os, u16 protocol_version) const;
-       void deSerialize(std::istream &is, u8 contentfeatures_version,
-               NodeDrawType drawtype);
+       void deSerialize(std::istream &is, NodeDrawType drawtype, u16 protocol_version);
 };
 
 // Defines the number of special tiles per nodedef
@@ -277,6 +299,10 @@ struct TileDef
 
 struct ContentFeatures
 {
+       // PROTOCOL_VERSION >= 37. This is legacy and should not be increased anymore, 
+       // write checks that depend directly on the protocol version instead.
+       static const u8 CONTENTFEATURES_VERSION = 13;
+
        /*
                Cached stuff
         */
@@ -285,7 +311,6 @@ struct ContentFeatures
        // up    down  right left  back  front
        TileSpec tiles[6];
        // Special tiles
-       // - Currently used for flowing liquids
        TileSpec special_tiles[CF_SPECIAL_COUNT];
        u8 solidness; // Used when choosing which face is drawn
        u8 visual_solidness; // When solidness=0, this tells how it looks like
@@ -297,6 +322,9 @@ struct ContentFeatures
        bool has_on_destruct;
        bool has_after_destruct;
 
+       // "float" group
+       bool floats;
+
        /*
                Actual data
         */
@@ -371,11 +399,15 @@ struct ContentFeatures
        u32 damage_per_second;
        // client dig prediction
        std::string node_dig_prediction;
+       // how slow players move through
+       u8 move_resistance = 0;
 
        // --- LIQUID PROPERTIES ---
 
        // Whether the node is non-liquid, source liquid or flowing liquid
        enum LiquidType liquid_type;
+       // If true, movement (e.g. of players) inside this node is liquid-like.
+       bool liquid_move_physics;
        // If the content is liquid, this is the flowing version of the liquid.
        std::string liquid_alternative_flowing;
        content_t liquid_alternative_flowing_id;
@@ -422,7 +454,7 @@ struct ContentFeatures
        ~ContentFeatures();
        void reset();
        void serialize(std::ostream &os, u16 protocol_version) const;
-       void deSerialize(std::istream &is);
+       void deSerialize(std::istream &is, u16 protocol_version);
 
        /*
                Some handy methods
@@ -464,9 +496,25 @@ struct ContentFeatures
        bool isLiquid() const{
                return (liquid_type != LIQUID_NONE);
        }
-       bool sameLiquid(const ContentFeatures &f) const{
-               if(!isLiquid() || !f.isLiquid()) return false;
-               return (liquid_alternative_flowing_id == f.liquid_alternative_flowing_id);
+
+       bool isLiquidRender() const {
+               return (drawtype == NDT_LIQUID || drawtype == NDT_FLOWINGLIQUID);
+       }
+
+       bool sameLiquidRender(const ContentFeatures &f) const {
+               if (!isLiquidRender() || !f.isLiquidRender())
+                       return false;
+               return liquid_alternative_flowing_id == f.liquid_alternative_flowing_id &&
+                       liquid_alternative_source_id == f.liquid_alternative_source_id;
+       }
+
+       ContentLightingFlags getLightingFlags() const {
+               ContentLightingFlags flags;
+               flags.has_light = param_type == CPT_LIGHT;
+               flags.light_propagates = light_propagates;
+               flags.sunlight_propagates = sunlight_propagates;
+               flags.light_source = light_source;
+               return flags;
        }
 
        int getGroup(const std::string &group) const
@@ -524,7 +572,7 @@ class NodeDefManager {
         */
        inline const ContentFeatures& get(content_t c) const {
                return
-                       c < m_content_features.size() ?
+                       (c < m_content_features.size() && !m_content_features[c].name.empty()) ?
                                m_content_features[c] : m_content_features[CONTENT_UNKNOWN];
        }
 
@@ -538,6 +586,15 @@ class NodeDefManager {
                return get(n.getContent());
        }
 
+       inline ContentLightingFlags getLightingFlags(content_t c) const {
+               // No bound check is necessary, since the array's length is CONTENT_MAX + 1.
+               return m_content_lighting_flag_cache[c];
+       }
+
+       inline ContentLightingFlags getLightingFlags(const MapNode &n) const {
+               return getLightingFlags(n.getContent());
+       }
+
        /*!
         * Returns the node properties for a node name.
         * @param name name of a node
@@ -655,13 +712,11 @@ class NodeDefManager {
         * total ContentFeatures.
         * @param progress_cbk_args passed to the callback function
         */
-       void updateTextures(IGameDef *gamedef,
-               void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
-               void *progress_cbk_args);
+       void updateTextures(IGameDef *gamedef, void *progress_cbk_args);
 
        /*!
         * Writes the content of this manager to the given output stream.
-        * @param protocol_version serialization version of ContentFeatures
+        * @param protocol_version Active network protocol version
         */
        void serialize(std::ostream &os, u16 protocol_version) const;
 
@@ -669,8 +724,9 @@ class NodeDefManager {
         * Restores the manager from a serialized stream.
         * This clears the previous state.
         * @param is input stream containing a serialized NodeDefManager
+        * @param protocol_version Active network protocol version
         */
-       void deSerialize(std::istream &is);
+       void deSerialize(std::istream &is, u16 protocol_version);
 
        /*!
         * Used to indicate that node registration has finished.
@@ -720,7 +776,7 @@ class NodeDefManager {
         * @param i a content ID
         * @param name a node name
         */
-       void addNameIdMapping(content_t i, std::string name);
+       void addNameIdMapping(content_t i, const std::string &name);
 
        /*!
         * Removes a content ID from all groups.
@@ -785,14 +841,22 @@ class NodeDefManager {
         * Even constant NodeDefManager instances can register listeners.
         */
        mutable std::vector<NodeResolver *> m_pending_resolve_callbacks;
+
+       /*!
+        * Fast cache of content lighting flags.
+        */
+       ContentLightingFlags m_content_lighting_flag_cache[CONTENT_MAX + 1L];
 };
 
 NodeDefManager *createNodeDefManager();
 
+// NodeResolver: Queue for node names which are then translated
+// to content_t after the NodeDefManager was initialized
 class NodeResolver {
 public:
        NodeResolver();
        virtual ~NodeResolver();
+       // Callback which is run as soon NodeDefManager is ready
        virtual void resolveNodeNames() = 0;
 
        // required because this class is used as mixin for ObjDef
@@ -804,12 +868,31 @@ class NodeResolver {
        bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
                bool all_required = false, content_t c_fallback = CONTENT_IGNORE);
 
-       void nodeResolveInternal();
+       inline bool isResolveDone() const { return m_resolve_done; }
+       void reset(bool resolve_done = false);
 
-       u32 m_nodenames_idx = 0;
-       u32 m_nnlistsizes_idx = 0;
+       // Vector containing all node names in the resolve "queue"
        std::vector<std::string> m_nodenames;
+       // Specifies the "set size" of node names which are to be processed
+       // this is used for getIdsFromNrBacklog
+       // TODO: replace or remove
        std::vector<size_t> m_nnlistsizes;
+
+protected:
+       friend class NodeDefManager; // m_ndef
+
        const NodeDefManager *m_ndef = nullptr;
+       // Index of the next "m_nodenames" entry to resolve
+       u32 m_nodenames_idx = 0;
+
+private:
+#if BUILD_UNITTESTS
+       // Unittest requires access to m_resolve_done
+       friend class TestSchematic;
+#endif
+       void nodeResolveInternal();
+
+       // Index of the next "m_nnlistsizes" entry to process
+       u32 m_nnlistsizes_idx = 0;
        bool m_resolve_done = false;
 };