[Block] Draw type 'Liquid' added. [ChunkBuilder] No longer dependent on 'BlockType'.

This commit is contained in:
Quentin Bazin 2020-02-03 15:29:00 +09:00
parent 03bbc53cd4
commit 70e80d1e31
5 changed files with 22 additions and 15 deletions

View File

@ -38,7 +38,7 @@ class ChunkBuilder {
enum Layer {
Solid,
Liquid,
Other,
Flora,
};
private:

View File

@ -87,7 +87,9 @@ std::array<std::size_t, ChunkBuilder::layers> ChunkBuilder::buildChunk(const Cli
{x, y, z + 1},
};
if (block.drawType() == BlockDrawType::Solid || block.drawType() == BlockDrawType::AllFaces) {
if (block.drawType() == BlockDrawType::Solid
|| block.drawType() == BlockDrawType::AllFaces
|| block.drawType() == BlockDrawType::Liquid) {
for(u8 i = 0 ; i < 6 ; i++) {
addFace(x, y, z, i, chunk, &block, surroundingBlocksPos[i]);
}
@ -121,8 +123,9 @@ inline void ChunkBuilder::addFace(u8 x, u8 y, u8 z, u8 i, const ClientChunk &chu
const Block *surroundingBlock = &Registry::getInstance().getBlock(surroundingBlockID);
// Skip hidden faces
if(surroundingBlock && surroundingBlock->id() && surroundingBlock->drawType() == BlockDrawType::Solid
&& (surroundingBlock->isOpaque() || block->drawType() != BlockDrawType::AllFaces))
if (surroundingBlock && surroundingBlock->id()
&& ((block->drawType() == BlockDrawType::Solid && surroundingBlock->drawType() == BlockDrawType::Solid && surroundingBlock->isOpaque())
|| (block->id() == surroundingBlock->id() && block->drawType() == BlockDrawType::Liquid)))
return;
static glm::vec3 a, b, c, v1, v2, normal;
@ -200,10 +203,8 @@ inline void ChunkBuilder::addFace(u8 x, u8 y, u8 z, u8 i, const ClientChunk &chu
if (!Config::isAmbientOcclusionEnabled)
vertices[j].ambientOcclusion = 5;
if (block->id() == BlockType::Water)
if (block->drawType() == BlockDrawType::Liquid)
m_vertices[Layer::Liquid].emplace_back(vertices[j]);
else if (block->id() == BlockType::Leaves)
m_vertices[Layer::Other].emplace_back(vertices[j]);
else
m_vertices[Layer::Solid].emplace_back(vertices[j]);
};
@ -266,12 +267,12 @@ inline void ChunkBuilder::addCross(u8 x, u8 y, u8 z, const ClientChunk &chunk, c
vertices[j].blockType = block->id();
}
m_vertices[Layer::Other].emplace_back(vertices[0]);
m_vertices[Layer::Other].emplace_back(vertices[1]);
m_vertices[Layer::Other].emplace_back(vertices[3]);
m_vertices[Layer::Other].emplace_back(vertices[3]);
m_vertices[Layer::Other].emplace_back(vertices[1]);
m_vertices[Layer::Other].emplace_back(vertices[2]);
m_vertices[Layer::Flora].emplace_back(vertices[0]);
m_vertices[Layer::Flora].emplace_back(vertices[1]);
m_vertices[Layer::Flora].emplace_back(vertices[3]);
m_vertices[Layer::Flora].emplace_back(vertices[3]);
m_vertices[Layer::Flora].emplace_back(vertices[1]);
m_vertices[Layer::Flora].emplace_back(vertices[2]);
}
}

View File

@ -29,7 +29,11 @@ void ClientChunk::drawLayer(gk::RenderTarget &target, gk::RenderStates states, u
states.texture = &m_textureAtlas.texture();
glCheck(glEnable(GL_CULL_FACE));
if (layer == ChunkBuilder::Layer::Flora)
glCheck(glDisable(GL_CULL_FACE));
else
glCheck(glEnable(GL_CULL_FACE));
glCheck(glEnable(GL_DEPTH_TEST));
if(Config::isWireframeModeEnabled) glCheck(glPolygonMode(GL_FRONT_AND_BACK, GL_LINE));

View File

@ -34,6 +34,7 @@ enum class BlockDrawType {
Solid = 0,
XShape = 1,
AllFaces = 2,
Liquid = 3,
};
class Block : public ISerializable {

View File

@ -58,7 +58,8 @@ mod:block {
mod:block {
id = "water",
name = "Water",
tiles = "water.png"
tiles = "water.png",
draw_type = 3 -- FIXME: Use string instead
}
mod:block {