Skip to content

Commit

Permalink
[ChunkBuilder] Water is now affected by smooth lighting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Jul 17, 2020
1 parent a0c0491 commit c7a5d61
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
5 changes: 2 additions & 3 deletions source/client/world/ChunkBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions source/server/world/ServerWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion source/server/world/ServerWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion source/server/world/save/WorldSaveBasicBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c7a5d61

Please sign in to comment.