From c7a5d61ece270fc2f6e8b4cc7b551dd676602935 Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Fri, 17 Jul 2020 22:00:33 +0200 Subject: [PATCH] [ChunkBuilder] Water is now affected by smooth lighting. --- source/client/world/ChunkBuilder.cpp | 5 ++--- source/server/world/ServerWorld.cpp | 10 +++++----- source/server/world/ServerWorld.hpp | 2 +- source/server/world/save/WorldSaveBasicBackend.cpp | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/source/client/world/ChunkBuilder.cpp b/source/client/world/ChunkBuilder.cpp index 6aabef520..e6d1c8fdb 100644 --- a/source/client/world/ChunkBuilder.cpp +++ b/source/client/world/ChunkBuilder.cpp @@ -245,13 +245,12 @@ inline void ChunkBuilder::addFace(s8f x, s8f y, s8f z, s8f f, const ClientChunk vertices[v].texCoord[0] = gk::qlerp(blockTexCoords.x, blockTexCoords.x + blockTexCoords.sizeX, U); vertices[v].texCoord[1] = gk::qlerp(blockTexCoords.y, blockTexCoords.y + blockTexCoords.sizeY, V); - if (Config::isSmoothLightingEnabled && blockState.drawType() != BlockDrawType::Liquid) + if (Config::isSmoothLightingEnabled) vertices[v].lightValue[0] = getLightForVertex(Light::Sun, x, y, z, *neighbourOfs[v], normal, chunk); else vertices[v].lightValue[0] = chunk.lightmap().getSunlight(x + normal.x, y + normal.y, z + normal.z); - int torchlight = chunk.lightmap().getTorchlight(x, y, z); - if (Config::isSmoothLightingEnabled && torchlight == 0 && blockState.drawType() != BlockDrawType::Liquid) + if (Config::isSmoothLightingEnabled && !blockState.isLightSource()) vertices[v].lightValue[1] = getLightForVertex(Light::Torch, x, y, z, *neighbourOfs[v], normal, chunk); else vertices[v].lightValue[1] = chunk.lightmap().getTorchlight(x + normal.x, y + normal.y, z + normal.z); diff --git a/source/server/world/ServerWorld.cpp b/source/server/world/ServerWorld.cpp index f3253170f..d352d18c8 100644 --- a/source/server/world/ServerWorld.cpp +++ b/source/server/world/ServerWorld.cpp @@ -134,10 +134,7 @@ void ServerWorld::sendChunkData(const ClientInfo &client, ServerChunk &chunk) { } void ServerWorld::sendRequestedData(ClientInfo &client, int cx, int cy, int cz) { - ServerChunk &chunk = createChunk(cx, cy, cz); - - // Create our neighbours so that we can generate and process lights correctly - createChunkNeighbours(chunk); + ServerChunk &chunk = getOrCreateChunk(cx, cy, cz); // Generate our chunk if (!chunk.isInitialized()) { @@ -151,11 +148,14 @@ void ServerWorld::sendRequestedData(ClientInfo &client, int cx, int cy, int cz) sendChunkData(client, chunk); } -ServerChunk &ServerWorld::createChunk(s32 cx, s32 cy, s32 cz) { +ServerChunk &ServerWorld::getOrCreateChunk(s32 cx, s32 cy, s32 cz) { ServerChunk *chunk = (ServerChunk *)getChunk(cx, cy, cz); if (!chunk) { auto it = m_chunks.emplace(gk::Vector3i{cx, cy, cz}, new ServerChunk(cx, cy, cz, *this)); chunk = it.first->second.get(); + + // Create our neighbours so that we can generate and process lights correctly + createChunkNeighbours(*chunk); } return *chunk; diff --git a/source/server/world/ServerWorld.hpp b/source/server/world/ServerWorld.hpp index 0191963d5..4bef39e05 100644 --- a/source/server/world/ServerWorld.hpp +++ b/source/server/world/ServerWorld.hpp @@ -57,7 +57,7 @@ class ServerWorld : public World { void sendChunkData(const ClientInfo &client, ServerChunk &chunk); void sendRequestedData(ClientInfo &client, s32 cx, s32 cy, s32 cz); - ServerChunk &createChunk(s32 cx, s32 cy, s32 cz); + ServerChunk &getOrCreateChunk(s32 cx, s32 cy, s32 cz); Chunk *getChunk(int cx, int cy, int cz) const override; diff --git a/source/server/world/save/WorldSaveBasicBackend.cpp b/source/server/world/save/WorldSaveBasicBackend.cpp index 878b8cce6..6b120ad53 100644 --- a/source/server/world/save/WorldSaveBasicBackend.cpp +++ b/source/server/world/save/WorldSaveBasicBackend.cpp @@ -69,7 +69,7 @@ void WorldSaveBasicBackend::load(const std::string &name) { int cx, cy, cz; save >> cx >> cy >> cz; - ServerChunk &chunk = world.createChunk(cx, cy, cz); + ServerChunk &chunk = world.getOrCreateChunk(cx, cy, cz); for (u8 z = 0 ; z < Chunk::height ; ++z) { for (u8 y = 0 ; y < Chunk::depth ; ++y) { for (u8 x = 0 ; x < Chunk::width ; ++x) {