[ServerChunk] Incomplete tree issue fixed (see #41).

This commit is contained in:
Quentin Bazin 2020-02-15 17:36:24 +09:00
parent 71587c0da8
commit b2fd4e6b51
5 changed files with 18 additions and 11 deletions

View File

@ -26,8 +26,9 @@
#include "TextureAtlas.hpp"
void ClientChunk::update() {
if (m_lightmap.updateLights() || m_hasChanged) {
if (m_lightmap.updateLights() || m_hasChanged || m_hasLightChanged) {
m_hasChanged = false;
m_hasLightChanged = false;
m_verticesCount = m_builder.buildChunk(*this, m_vbo);
}

View File

@ -79,6 +79,9 @@ class Chunk : public gk::NonCopyable {
bool hasChanged() const { return m_hasChanged; }
void setChanged(bool hasChanged) { m_hasChanged = hasChanged; }
bool hasLightChanged() const { return m_hasLightChanged; }
void setLightChanged(bool hasLightChanged) { m_hasLightChanged = hasLightChanged; }
bool isInitialized() const { return m_isInitialized; }
void setInitialized(bool isInitialized) { m_isInitialized = isInitialized; }
@ -106,6 +109,7 @@ class Chunk : public gk::NonCopyable {
Chunk *m_surroundingChunks[6]{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
bool m_hasChanged = false;
bool m_hasLightChanged = false;
bool m_isInitialized = false;
std::unordered_map<std::size_t, const Block&> m_tickingBlocks;

View File

@ -278,7 +278,7 @@ u8 ChunkLightmap::getTorchlight(int x, int y, int z) const {
void ChunkLightmap::setLightData(int x, int y, int z, u8 val) {
m_lightMap[x][y][z] = val;
m_chunk->setChanged(true);
m_chunk->setLightChanged(true);
updateSurroundingChunks(x, y, z);
}
@ -293,7 +293,7 @@ void ChunkLightmap::setSunlight(int x, int y, int z, u8 val) {
m_lightMap[x][y][z] = (m_lightMap[x][y][z] & 0xf) | (val << 4);
m_chunk->setChanged(true);
m_chunk->setLightChanged(true);
updateSurroundingChunks(x, y, z);
};
@ -308,17 +308,17 @@ void ChunkLightmap::setTorchlight(int x, int y, int z, u8 val) {
m_lightMap[x][y][z] = (m_lightMap[x][y][z] & 0xf0) | val;
m_chunk->setChanged(true);
m_chunk->setLightChanged(true);
updateSurroundingChunks(x, y, z);
}
void ChunkLightmap::updateSurroundingChunks(int x, int y, int z) {
if(x == 0 && m_chunk->getSurroundingChunk(Chunk::Left)) { m_chunk->getSurroundingChunk(Chunk::Left)->setChanged(true); }
if(x == CHUNK_WIDTH - 1 && m_chunk->getSurroundingChunk(Chunk::Right)) { m_chunk->getSurroundingChunk(Chunk::Right)->setChanged(true); }
if(y == 0 && m_chunk->getSurroundingChunk(Chunk::Bottom)) { m_chunk->getSurroundingChunk(Chunk::Bottom)->setChanged(true); }
if(y == CHUNK_HEIGHT - 1 && m_chunk->getSurroundingChunk(Chunk::Top)) { m_chunk->getSurroundingChunk(Chunk::Top)->setChanged(true); }
if(z == 0 && m_chunk->getSurroundingChunk(Chunk::Front)) { m_chunk->getSurroundingChunk(Chunk::Front)->setChanged(true); }
if(z == CHUNK_DEPTH - 1 && m_chunk->getSurroundingChunk(Chunk::Back)) { m_chunk->getSurroundingChunk(Chunk::Back)->setChanged(true); }
if(x == 0 && m_chunk->getSurroundingChunk(Chunk::Left)) { m_chunk->getSurroundingChunk(Chunk::Left)->setLightChanged(true); }
if(x == CHUNK_WIDTH - 1 && m_chunk->getSurroundingChunk(Chunk::Right)) { m_chunk->getSurroundingChunk(Chunk::Right)->setLightChanged(true); }
if(y == 0 && m_chunk->getSurroundingChunk(Chunk::Bottom)) { m_chunk->getSurroundingChunk(Chunk::Bottom)->setLightChanged(true); }
if(y == CHUNK_HEIGHT - 1 && m_chunk->getSurroundingChunk(Chunk::Top)) { m_chunk->getSurroundingChunk(Chunk::Top)->setLightChanged(true); }
if(z == 0 && m_chunk->getSurroundingChunk(Chunk::Front)) { m_chunk->getSurroundingChunk(Chunk::Front)->setLightChanged(true); }
if(z == CHUNK_DEPTH - 1 && m_chunk->getSurroundingChunk(Chunk::Back)) { m_chunk->getSurroundingChunk(Chunk::Back)->setLightChanged(true); }
}

View File

@ -27,8 +27,9 @@
#include "World.hpp"
void ServerChunk::updateLights() {
if (m_lightmap.updateLights()) {
if (m_lightmap.updateLights() || m_hasChanged) {
m_isSent = false;
m_hasChanged = false;
}
}

View File

@ -119,6 +119,7 @@ void ServerWorld::sendChunkData(const Client &client, ServerChunk *chunk) {
client.tcpSocket->send(packet);
chunk->setSent(true);
chunk->setChanged(false);
// std::cout << "Chunk at (" << chunk->x() << ", " << chunk->y() << ", " << chunk->z() << ") sent to client" << std::endl;
}