]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/nodedef.h
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / nodedef.h
index cf03abaae8b493b552d0875973f6de97888cb4f9..3e77624eb3134b7d25eca4b003d398005786d642 100644 (file)
@@ -44,6 +44,9 @@ class ITextureSource;
 class IShaderSource;
 class IGameDef;
 class NodeResolver;
+#if BUILD_UNITTESTS
+class TestSchematic;
+#endif
 
 enum ContentParamType
 {
@@ -158,7 +161,6 @@ class TextureSettings {
        int node_texture_size;
        bool opaque_water;
        bool connected_glass;
-       bool use_normal_texture;
        bool enable_mesh_cache;
        bool enable_minimap;
 
@@ -232,6 +234,14 @@ enum AlignStyle : u8 {
        ALIGN_STYLE_USER_DEFINED,
 };
 
+enum AlphaMode : u8 {
+       ALPHAMODE_BLEND,
+       ALPHAMODE_CLIP,
+       ALPHAMODE_OPAQUE,
+       ALPHAMODE_LEGACY_COMPAT, /* means either opaque or clip */
+};
+
+
 /*
        Stand-alone definition of a TileSpec (basically a server-side TileSpec)
 */
@@ -261,6 +271,11 @@ struct TileDef
                NodeDrawType drawtype);
 };
 
+// Defines the number of special tiles per nodedef
+//
+// NOTE: When changing this value, the enum entries of OverrideTarget and
+//       parser in TextureOverrideSource must be updated so that all special
+//       tiles can be overridden.
 #define CF_SPECIAL_COUNT 6
 
 struct ContentFeatures
@@ -311,9 +326,7 @@ struct ContentFeatures
        // These will be drawn over the base tiles.
        TileDef tiledef_overlay[6];
        TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
-       // If 255, the node is opaque.
-       // Otherwise it uses texture alpha.
-       u8 alpha;
+       AlphaMode alpha;
        // The color of the node.
        video::SColor color;
        std::string palette_name;
@@ -413,18 +426,44 @@ struct ContentFeatures
        void reset();
        void serialize(std::ostream &os, u16 protocol_version) const;
        void deSerialize(std::istream &is);
-       /*!
-        * Since vertex alpha is no longer supported, this method
-        * adds opacity directly to the texture pixels.
-        *
-        * \param tiles array of the tile definitions.
-        * \param length length of tiles
-        */
-       void correctAlpha(TileDef *tiles, int length);
 
        /*
                Some handy methods
        */
+       void setDefaultAlphaMode()
+       {
+               switch (drawtype) {
+               case NDT_NORMAL:
+               case NDT_LIQUID:
+               case NDT_FLOWINGLIQUID:
+                       alpha = ALPHAMODE_OPAQUE;
+                       break;
+               case NDT_NODEBOX:
+               case NDT_MESH:
+                       alpha = ALPHAMODE_LEGACY_COMPAT; // this should eventually be OPAQUE
+                       break;
+               default:
+                       alpha = ALPHAMODE_CLIP;
+                       break;
+               }
+       }
+
+       bool needsBackfaceCulling() const
+       {
+               switch (drawtype) {
+               case NDT_TORCHLIKE:
+               case NDT_SIGNLIKE:
+               case NDT_FIRELIKE:
+               case NDT_RAILLIKE:
+               case NDT_PLANTLIKE:
+               case NDT_PLANTLIKE_ROOTED:
+               case NDT_MESH:
+                       return false;
+               default:
+                       return true;
+               }
+       }
+
        bool isLiquid() const{
                return (liquid_type != LIQUID_NONE);
        }
@@ -442,6 +481,21 @@ struct ContentFeatures
        void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
                scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings);
 #endif
+
+private:
+#ifndef SERVER
+       /*
+        * Checks if any tile texture has any transparent pixels.
+        * Prints a warning and returns true if that is the case, false otherwise.
+        * This is supposed to be used for use_texture_alpha backwards compatibility.
+        */
+       bool textureAlphaCheck(ITextureSource *tsrc, const TileDef *tiles,
+               int length);
+#endif
+
+       void setAlphaFromLegacy(u8 legacy_alpha);
+
+       u8 getAlphaForLegacy() const;
 };
 
 /*!
@@ -738,10 +792,13 @@ class NodeDefManager {
 
 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
@@ -753,12 +810,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;
 };