11 changes: 9 additions & 2 deletions src/client/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/numeric.h"

class IGameDef;
struct TileSpec;
struct TileDef;

/*
tile.{h,cpp}: Texture handling stuff.
Expand Down Expand Up @@ -111,6 +113,7 @@ class ITextureSource : public ISimpleTextureSource
const TextureFromMeshParams &params)=0;
virtual video::ITexture* getNormalTexture(const std::string &name)=0;
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
virtual video::ITexture *getShaderFlagsTexture(TileDef *tiledef, TileSpec *tile)=0;
};

class IWritableTextureSource : public ITextureSource
Expand All @@ -133,6 +136,7 @@ class IWritableTextureSource : public ITextureSource
virtual void rebuildImagesAndTextures()=0;
virtual video::ITexture* getNormalTexture(const std::string &name)=0;
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
virtual video::ITexture *getShaderFlagsTexture(TileDef *tiledef, TileSpec *tile)=0;
};

IWritableTextureSource* createTextureSource(IrrlichtDevice *device);
Expand Down Expand Up @@ -172,12 +176,14 @@ struct FrameSpec
FrameSpec():
texture_id(0),
texture(NULL),
normal_texture(NULL)
normal_texture(NULL),
flags_texture(NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it still compiles when you add a , here, add it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't compile, no comma needed then.

{
}
u32 texture_id;
video::ITexture *texture;
video::ITexture *normal_texture;
video::ITexture *flags_texture;
};

struct TileSpec
Expand All @@ -186,6 +192,7 @@ struct TileSpec
texture_id(0),
texture(NULL),
normal_texture(NULL),
flags_texture(NULL),
alpha(255),
material_type(TILE_MATERIAL_BASIC),
material_flags(
Expand Down Expand Up @@ -252,6 +259,7 @@ struct TileSpec
u32 texture_id;
video::ITexture *texture;
video::ITexture *normal_texture;
video::ITexture *flags_texture;

// Vertex alpha (when MATERIAL_ALPHA_VERTEX is used)
u8 alpha;
Expand All @@ -266,5 +274,4 @@ struct TileSpec

u8 rotation;
};

#endif
4 changes: 2 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,11 +878,11 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
services->setPixelShaderConstant("baseTexture" , (irr::f32 *)&layer0, 1);
services->setPixelShaderConstant("normalTexture" , (irr::f32 *)&layer1, 1);
services->setPixelShaderConstant("useNormalmap" , (irr::f32 *)&layer2, 1);
services->setPixelShaderConstant("textureFlags" , (irr::f32 *)&layer2, 1);
#else
services->setPixelShaderConstant("baseTexture" , (irr::s32 *)&layer0, 1);
services->setPixelShaderConstant("normalTexture" , (irr::s32 *)&layer1, 1);
services->setPixelShaderConstant("useNormalmap" , (irr::s32 *)&layer2, 1);
services->setPixelShaderConstant("textureFlags" , (irr::s32 *)&layer2, 1);
#endif
}
};
Expand Down
8 changes: 2 additions & 6 deletions src/mapblock_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,10 +1213,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
p.tile.applyMaterialOptionsWithShaders(material);
if (p.tile.normal_texture) {
material.setTexture(1, p.tile.normal_texture);
material.setTexture(2, m_tsrc->getTextureForMesh("enable_img.png"));
} else {
material.setTexture(2, m_tsrc->getTextureForMesh("disable_img.png"));
}
material.setTexture(2, p.tile.flags_texture);
} else {
p.tile.applyMaterialOptions(material);
}
Expand Down Expand Up @@ -1349,10 +1347,8 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
if (m_enable_shaders) {
if (animation_frame.normal_texture) {
buf->getMaterial().setTexture(1, animation_frame.normal_texture);
buf->getMaterial().setTexture(2, m_tsrc->getTextureForMesh("enable_img.png"));
} else {
buf->getMaterial().setTexture(2, m_tsrc->getTextureForMesh("disable_img.png"));
}
buf->getMaterial().setTexture(2, animation_frame.flags_texture);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/network/networkprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
presentation
Add TOCLIENT_AUTH_ACCEPT to accept connection from client
Rename GENERIC_CMD_SET_ATTACHMENT to GENERIC_CMD_ATTACH_TO
PROTOCOL_VERSION 26:
Add TileDef tileable_horizontal, tileable_vertical flags
*/

#define LATEST_PROTOCOL_VERSION 25
#define LATEST_PROTOCOL_VERSION 26

// Server's supported network protocol range
#define SERVER_PROTOCOL_VERSION_MIN 13
Expand Down
25 changes: 20 additions & 5 deletions src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ void NodeBox::deSerialize(std::istream &is)

void TileDef::serialize(std::ostream &os, u16 protocol_version) const
{
if(protocol_version >= 17)
if (protocol_version >= 26)
writeU8(os, 2);
else if (protocol_version >= 17)
writeU8(os, 1);
else
writeU8(os, 0);
Expand All @@ -129,8 +131,12 @@ void TileDef::serialize(std::ostream &os, u16 protocol_version) const
writeU16(os, animation.aspect_w);
writeU16(os, animation.aspect_h);
writeF1000(os, animation.length);
if(protocol_version >= 17)
if (protocol_version >= 17)
writeU8(os, backface_culling);
if (protocol_version >= 26) {
writeU8(os, tileable_horizontal);
writeU8(os, tileable_vertical);
}
}

void TileDef::deSerialize(std::istream &is)
Expand All @@ -141,10 +147,15 @@ void TileDef::deSerialize(std::istream &is)
animation.aspect_w = readU16(is);
animation.aspect_h = readU16(is);
animation.length = readF1000(is);
if(version >= 1)
if (version >= 1)
backface_culling = readU8(is);
if (version >= 2) {
tileable_horizontal = readU8(is);
tileable_vertical = readU8(is);
}
}


/*
SimpleSoundSpec serialization
*/
Expand Down Expand Up @@ -183,6 +194,7 @@ void ContentFeatures::reset()
solidness = 2;
visual_solidness = 0;
backface_culling = true;

#endif
has_on_construct = false;
has_on_destruct = false;
Expand Down Expand Up @@ -996,9 +1008,11 @@ void CNodeDefManager::fillTileAttribs(ITextureSource *tsrc, TileSpec *tile,
tile->alpha = alpha;
tile->material_type = material_type;

// Normal texture
if (use_normal_texture)
// Normal texture and shader flags texture
if (use_normal_texture) {
tile->normal_texture = tsrc->getNormalTexture(tiledef->name);
}
tile->flags_texture = tsrc->getShaderFlagsTexture(tiledef, tile);

// Material flags
tile->material_flags = 0;
Expand Down Expand Up @@ -1038,6 +1052,7 @@ void CNodeDefManager::fillTileAttribs(ITextureSource *tsrc, TileSpec *tile,
frame.texture = tsrc->getTextureForMesh(os.str(), &frame.texture_id);
if (tile->normal_texture)
frame.normal_texture = tsrc->getNormalTexture(os.str());
frame.flags_texture = tile->flags_texture;
tile->frames[i] = frame;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/nodedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ struct TileDef
{
std::string name;
bool backface_culling; // Takes effect only in special cases
bool tileable_horizontal;
bool tileable_vertical;
struct{
enum TileAnimationType type;
int aspect_w; // width for aspect ratio
Expand All @@ -124,6 +126,8 @@ struct TileDef
{
name = "";
backface_culling = true;
tileable_horizontal = true;
tileable_vertical = true;
animation.type = TAT_NONE;
animation.aspect_w = 1;
animation.aspect_h = 1;
Expand Down
16 changes: 10 additions & 6 deletions src/script/common/c_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,24 @@ TileDef read_tiledef(lua_State *L, int index)
getstringfield(L, index, "name", tiledef.name);
getstringfield(L, index, "image", tiledef.name); // MaterialSpec compat.
tiledef.backface_culling = getboolfield_default(
L, index, "backface_culling", true);
L, index, "backface_culling", true);
tiledef.tileable_horizontal = getboolfield_default(
L, index, "tileable_horizontal", true);
tiledef.tileable_vertical = getboolfield_default(
L, index, "tileable_vertical", true);
// animation = {}
lua_getfield(L, index, "animation");
if(lua_istable(L, -1)){
// {type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0}
tiledef.animation.type = (TileAnimationType)
getenumfield(L, -1, "type", es_TileAnimationType,
TAT_NONE);
getenumfield(L, -1, "type", es_TileAnimationType,
TAT_NONE);
tiledef.animation.aspect_w =
getintfield_default(L, -1, "aspect_w", 16);
getintfield_default(L, -1, "aspect_w", 16);
tiledef.animation.aspect_h =
getintfield_default(L, -1, "aspect_h", 16);
getintfield_default(L, -1, "aspect_h", 16);
tiledef.animation.length =
getfloatfield_default(L, -1, "length", 1.0);
getfloatfield_default(L, -1, "length", 1.0);
}
lua_pop(L, 1);
}
Expand Down
Binary file removed textures/base/pack/disable_img.png
Binary file not shown.
Binary file removed textures/base/pack/enable_img.png
Binary file not shown.