From: Daniel Karbach Date: Thu, 23 Jul 2015 07:21:00 +0000 (+0200) Subject: propagate light into blocking blocks X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;ds=sidebyside;h=695918769a616db82dbebb987ea91f3204dee8a9;p=blank.git propagate light into blocking blocks this way semi-filled blocks like slabs don't blacken surfaces behind them, but they will be bright when part of a 1 thick wall --- diff --git a/TODO b/TODO index 7e52a23..5fc2e9e 100644 --- a/TODO +++ b/TODO @@ -54,6 +54,10 @@ entity ai I kinda mitigated it a little for direct neighbors during linking, but it still can happen in (hopefully) rare corner cases + propagation through semi-filled blocks is wonky. I worked around it by + having the light propagate into solid blocks, but feels like this + could cause some weird behaviours + gravity maybe like light levels? should also store a direction with it in diff --git a/src/world/chunk.cpp b/src/world/chunk.cpp index ef3c5fc..c421be9 100644 --- a/src/world/chunk.cpp +++ b/src/world/chunk.cpp @@ -65,9 +65,13 @@ struct SetNode { int Get() const noexcept { return chunk->GetLight(pos); } void Set(int level) noexcept { chunk->SetLight(pos, level); } + const BlockType &GetType() const noexcept { return chunk->Type(Chunk::ToIndex(pos)); } + bool HasNext(Block::Face face) noexcept { + const BlockType &type = GetType(); + if (type.block_light && !type.luminosity) return false; const BlockLookup next(chunk, pos, face); - return next && !next.GetType().block_light; + return next; } SetNode GetNext(Block::Face face) noexcept { const BlockLookup next(chunk, pos, face); diff --git a/tst/world/ChunkTest.cpp b/tst/world/ChunkTest.cpp index 6db245a..c8dac83 100644 --- a/tst/world/ChunkTest.cpp +++ b/tst/world/ChunkTest.cpp @@ -450,10 +450,6 @@ void ChunkTest::testLightPropagation() { // now block the light to the left chunk->SetBlock(Chunk::Pos(6, 7, 7), Block(1)); - CPPUNIT_ASSERT_EQUAL_MESSAGE( - "non-zero light level in solid block", - 0, chunk->GetLight(Chunk::Pos(6, 7, 7)) - ); CPPUNIT_ASSERT_EQUAL_MESSAGE( "adding obstacle affected unrelated index", 5, chunk->GetLight(Chunk::Pos(7, 7, 7))