X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fclient%2Ftile.h;h=49c46f749d648da88267c7bd0eb53e7de6cfbd31;hb=946f3030fc0728de15620896e08ed7e10696c11b;hp=c6ebee00621bff812345fff1c9147fb16b66ce2d;hpb=1ffb180868ffcec6812cd3aac8f56ffefb91c8bc;p=dragonfireclient.git diff --git a/src/client/tile.h b/src/client/tile.h index c6ebee006..49c46f749 100644 --- a/src/client/tile.h +++ b/src/client/tile.h @@ -17,17 +17,20 @@ 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 -#include -#include "threads.h" #include #include +#include #include "util/numeric.h" +#include "config.h" + +#if ENABLE_GLES +#include +#endif class IGameDef; struct TileSpec; @@ -60,29 +63,10 @@ std::string getImagePath(std::string path); Utilizes a thread-safe cache. */ -std::string getTexturePath(const std::string &filename); +std::string getTexturePath(const std::string &filename, bool *is_base_pack = nullptr); void clearTextureNameCache(); -/* - ITextureSource::generateTextureFromMesh parameters -*/ -namespace irr {namespace scene {class IMesh;}} -struct TextureFromMeshParams -{ - scene::IMesh *mesh; - core::dimension2d dim; - std::string rtt_texture_name; - bool delete_texture_on_shutdown; - v3f camera_position; - v3f camera_lookat; - core::CMatrix4 camera_projection_matrix; - video::SColorf ambient_light; - v3f light_position; - video::SColorf light_color; - f32 light_radius; -}; - /* TextureSource creates and caches textures. */ @@ -90,24 +74,28 @@ struct TextureFromMeshParams class ISimpleTextureSource { public: - ISimpleTextureSource(){} - virtual ~ISimpleTextureSource(){} + ISimpleTextureSource() = default; + + virtual ~ISimpleTextureSource() = default; + virtual video::ITexture* getTexture( - const std::string &name, u32 *id = NULL) = 0; + const std::string &name, u32 *id = nullptr) = 0; }; 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; virtual video::ITexture* getTexture( - const std::string &name, u32 *id = NULL)=0; + const std::string &name, u32 *id = nullptr)=0; virtual video::ITexture* getTextureForMesh( - const std::string &name, u32 *id = NULL) = 0; + const std::string &name, u32 *id = nullptr) = 0; /*! * Returns a palette from the given texture name. * The pointer is valid until the texture source is @@ -115,10 +103,7 @@ class ITextureSource : public ISimpleTextureSource * Should be called from the main thread. */ virtual Palette* getPalette(const std::string &name) = 0; - virtual IrrlichtDevice* getDevice()=0; virtual bool isKnownSourceImage(const std::string &name)=0; - virtual video::ITexture* generateTextureFromMesh( - const TextureFromMeshParams ¶ms)=0; virtual video::ITexture* getNormalTexture(const std::string &name)=0; virtual video::SColor getTextureAverageColor(const std::string &name)=0; virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0; @@ -127,17 +112,16 @@ 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; virtual video::ITexture* getTexture( - const std::string &name, u32 *id = NULL)=0; - virtual IrrlichtDevice* getDevice()=0; + const std::string &name, u32 *id = nullptr)=0; virtual bool isKnownSourceImage(const std::string &name)=0; - virtual video::ITexture* generateTextureFromMesh( - const TextureFromMeshParams ¶ms)=0; virtual void processQueue()=0; virtual void insertSourceImage(const std::string &name, video::IImage *img)=0; @@ -147,10 +131,11 @@ class IWritableTextureSource : public ITextureSource virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0; }; -IWritableTextureSource* createTextureSource(IrrlichtDevice *device); +IWritableTextureSource *createTextureSource(); -#ifdef __ANDROID__ -video::IImage * Align2Npot2(video::IImage * image, video::IVideoDriver* driver); +#if ENABLE_GLES +bool hasNPotSupport(); +video::IImage * Align2Npot2(video::IImage * image, irr::video::IVideoDriver* driver); #endif enum MaterialType{ @@ -159,7 +144,13 @@ enum MaterialType{ TILE_MATERIAL_LIQUID_TRANSPARENT, TILE_MATERIAL_LIQUID_OPAQUE, TILE_MATERIAL_WAVING_LEAVES, - TILE_MATERIAL_WAVING_PLANTS + TILE_MATERIAL_WAVING_PLANTS, + TILE_MATERIAL_OPAQUE, + TILE_MATERIAL_WAVING_LIQUID_BASIC, + TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT, + TILE_MATERIAL_WAVING_LIQUID_OPAQUE, + TILE_MATERIAL_PLAIN, + TILE_MATERIAL_PLAIN_ALPHA }; // Material flags @@ -171,7 +162,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 @@ -181,17 +172,12 @@ enum MaterialType{ */ struct FrameSpec { - FrameSpec(): - texture_id(0), - texture(NULL), - normal_texture(NULL), - flags_texture(NULL) - { - } - u32 texture_id; - video::ITexture *texture; - video::ITexture *normal_texture; - video::ITexture *flags_texture; + FrameSpec() = default; + + u32 texture_id = 0; + video::ITexture *texture = nullptr; + video::ITexture *normal_texture = nullptr; + video::ITexture *flags_texture = nullptr; }; #define MAX_TILE_LAYERS 2 @@ -199,25 +185,7 @@ struct FrameSpec //! Defines a layer of a tile. struct TileLayer { - TileLayer(): - texture(NULL), - texture_id(0), - color(), - material_type(TILE_MATERIAL_BASIC), - material_flags( - //0 // <- DEBUG, Use the one below - MATERIAL_FLAG_BACKFACE_CULLING | - MATERIAL_FLAG_TILEABLE_HORIZONTAL| - MATERIAL_FLAG_TILEABLE_VERTICAL - ), - shader_id(0), - normal_texture(NULL), - flags_texture(NULL), - animation_frame_length_ms(0), - animation_frame_count(1), - has_color(false) - { - } + TileLayer() = default; /*! * Two layers are equal if they can be merged. @@ -228,7 +196,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; } /*! @@ -243,21 +212,27 @@ struct TileLayer void applyMaterialOptions(video::SMaterial &material) const { switch (material_type) { + case TILE_MATERIAL_OPAQUE: + case TILE_MATERIAL_LIQUID_OPAQUE: + case TILE_MATERIAL_WAVING_LIQUID_OPAQUE: + material.MaterialType = video::EMT_SOLID; + break; case TILE_MATERIAL_BASIC: case TILE_MATERIAL_WAVING_LEAVES: case TILE_MATERIAL_WAVING_PLANTS: + case TILE_MATERIAL_WAVING_LIQUID_BASIC: + material.MaterialTypeParam = 0.5; material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; break; case TILE_MATERIAL_ALPHA: case TILE_MATERIAL_LIQUID_TRANSPARENT: + case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT: material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; break; - case TILE_MATERIAL_LIQUID_OPAQUE: - material.MaterialType = video::EMT_SOLID; + 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; } @@ -268,8 +243,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; @@ -286,27 +260,38 @@ struct TileLayer && (material_flags & MATERIAL_FLAG_TILEABLE_VERTICAL); } - video::ITexture *texture; - u32 texture_id; + // Ordered for size, please do not reorder + + video::ITexture *texture = nullptr; + video::ITexture *normal_texture = nullptr; + video::ITexture *flags_texture = nullptr; + + u32 shader_id = 0; + + u32 texture_id = 0; + + u16 animation_frame_length_ms = 0; + u16 animation_frame_count = 1; + + u8 material_type = TILE_MATERIAL_BASIC; + u8 material_flags = + //0 // <- DEBUG, Use the one below + MATERIAL_FLAG_BACKFACE_CULLING | + MATERIAL_FLAG_TILEABLE_HORIZONTAL| + MATERIAL_FLAG_TILEABLE_VERTICAL; + + //! If true, the tile has its own color. + bool has_color = false; + + std::vector *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; - // Material parameters - u8 material_type; - u8 material_flags; - u32 shader_id; - video::ITexture *normal_texture; - video::ITexture *flags_texture; - - // Animation parameters - u16 animation_frame_length_ms; - u8 animation_frame_count; - //! If true, the tile has its own color. - bool has_color; - std::vector frames; + u8 scale; }; /*! @@ -314,14 +299,8 @@ struct TileLayer */ struct TileSpec { - TileSpec(): - rotation(0), - emissive_light(0) - { - for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) - layers[layer] = TileLayer(); - } - + TileSpec() = default; + /*! * Returns true if this tile can be merged with the other tile. */ @@ -337,10 +316,14 @@ struct TileSpec && emissive_light == other.emissive_light; } - u8 rotation; + //! 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; + u8 emissive_light = 0; //! The first is base texture, the second is overlay. TileLayer layers[MAX_TILE_LAYERS]; }; -#endif + +std::vector getTextureDirs();