]> git.lizzy.rs Git - minetest.git/blobdiff - src/client/tile.h
Rewrite rendering engine (#6253)
[minetest.git] / src / client / tile.h
index fb1c87371c55286066958848d363a2742444d937..e69dbe0c7bb3d6d7352dd74f28f907a53662ee13 100644 (file)
@@ -17,15 +17,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#ifndef TILE_HEADER
-#define TILE_HEADER
+#pragma once
 
 #include "irrlichttypes.h"
 #include "irr_v3d.h"
 #include <ITexture.h>
-#include <IrrlichtDevice.h>
 #include <string>
 #include <vector>
+#include <SMaterial.h>
+#include <memory>
 #include "util/numeric.h"
 
 class IGameDef;
@@ -89,8 +89,10 @@ struct TextureFromMeshParams
 class ISimpleTextureSource
 {
 public:
-       ISimpleTextureSource(){}
-       virtual ~ISimpleTextureSource(){}
+       ISimpleTextureSource() = default;
+
+       virtual ~ISimpleTextureSource() = default;
+
        virtual video::ITexture* getTexture(
                        const std::string &name, u32 *id = nullptr) = 0;
 };
@@ -98,8 +100,10 @@ class ISimpleTextureSource
 class ITextureSource : public ISimpleTextureSource
 {
 public:
-       ITextureSource(){}
-       virtual ~ITextureSource(){}
+       ITextureSource() = default;
+
+       virtual ~ITextureSource() = default;
+
        virtual u32 getTextureId(const std::string &name)=0;
        virtual std::string getTextureName(u32 id)=0;
        virtual video::ITexture* getTexture(u32 id)=0;
@@ -125,8 +129,10 @@ class ITextureSource : public ISimpleTextureSource
 class IWritableTextureSource : public ITextureSource
 {
 public:
-       IWritableTextureSource(){}
-       virtual ~IWritableTextureSource(){}
+       IWritableTextureSource() = default;
+
+       virtual ~IWritableTextureSource() = default;
+
        virtual u32 getTextureId(const std::string &name)=0;
        virtual std::string getTextureName(u32 id)=0;
        virtual video::ITexture* getTexture(u32 id)=0;
@@ -169,7 +175,7 @@ enum MaterialType{
 // Ignored if MATERIAL_FLAG_CRACK is not set.
 #define MATERIAL_FLAG_CRACK_OVERLAY 0x04
 #define MATERIAL_FLAG_ANIMATION 0x08
-#define MATERIAL_FLAG_HIGHLIGHTED 0x10
+//#define MATERIAL_FLAG_HIGHLIGHTED 0x10
 #define MATERIAL_FLAG_TILEABLE_HORIZONTAL 0x20
 #define MATERIAL_FLAG_TILEABLE_VERTICAL 0x40
 
@@ -179,7 +185,8 @@ enum MaterialType{
 */
 struct FrameSpec
 {
-       FrameSpec() {}
+       FrameSpec() = default;
+
        u32 texture_id = 0;
        video::ITexture *texture = nullptr;
        video::ITexture *normal_texture = nullptr;
@@ -191,7 +198,7 @@ struct FrameSpec
 //! Defines a layer of a tile.
 struct TileLayer
 {
-       TileLayer() {}
+       TileLayer() = default;
 
        /*!
         * Two layers are equal if they can be merged.
@@ -202,7 +209,8 @@ struct TileLayer
                        texture_id == other.texture_id &&
                        material_type == other.material_type &&
                        material_flags == other.material_flags &&
-                       color == other.color;
+                       color == other.color &&
+                       scale == other.scale;
        }
 
        /*!
@@ -230,9 +238,10 @@ struct TileLayer
                case TILE_MATERIAL_LIQUID_TRANSPARENT:
                        material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
                        break;
+               default:
+                       break;
                }
-               material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING)
-                       ? true : false;
+               material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
                if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
                        material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
                }
@@ -243,8 +252,7 @@ struct TileLayer
 
        void applyMaterialOptionsWithShaders(video::SMaterial &material) const
        {
-               material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING)
-                       ? true : false;
+               material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
                if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
                        material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
                        material.TextureLayer[1].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
@@ -284,13 +292,15 @@ struct TileLayer
        //! If true, the tile has its own color.
        bool has_color = false;
 
-       std::vector<FrameSpec> frames;
+       std::shared_ptr<std::vector<FrameSpec>> frames = nullptr;
 
        /*!
         * The color of the tile, or if the tile does not own
         * a color then the color of the node owning this tile.
         */
        video::SColor color;
+
+       u8 scale;
 };
 
 /*!
@@ -299,8 +309,8 @@ struct TileLayer
 struct TileSpec
 {
        TileSpec() {
-               for (int layer = 0; layer < MAX_TILE_LAYERS; layer++)
-                       layers[layer] = TileLayer();
+               for (auto &layer : layers)
+                       layer = TileLayer();
        }
 
        /*!
@@ -318,10 +328,12 @@ struct TileSpec
                        && emissive_light == other.emissive_light;
        }
 
+       //! If true, the tile rotation is ignored.
+       bool world_aligned = false;
+       //! Tile rotation.
        u8 rotation = 0;
        //! This much light does the tile emit.
        u8 emissive_light = 0;
        //! The first is base texture, the second is overlay.
        TileLayer layers[MAX_TILE_LAYERS];
 };
-#endif