diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-05-05 16:48:18 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-05-05 16:48:18 +0200 |
commit | 1e350218ccb73a5609db9dd844dc25ed9b1a8286 (patch) | |
tree | 3a6f066a5db8620e5dcc5b6fc39c293b475964d9 /source/LightingThread.cpp | |
parent | ChunkDesc: Added heightmap verification (DEBUG-only), not used yet (diff) | |
download | cuberite-1e350218ccb73a5609db9dd844dc25ed9b1a8286.tar cuberite-1e350218ccb73a5609db9dd844dc25ed9b1a8286.tar.gz cuberite-1e350218ccb73a5609db9dd844dc25ed9b1a8286.tar.bz2 cuberite-1e350218ccb73a5609db9dd844dc25ed9b1a8286.tar.lz cuberite-1e350218ccb73a5609db9dd844dc25ed9b1a8286.tar.xz cuberite-1e350218ccb73a5609db9dd844dc25ed9b1a8286.tar.zst cuberite-1e350218ccb73a5609db9dd844dc25ed9b1a8286.zip |
Diffstat (limited to 'source/LightingThread.cpp')
-rw-r--r-- | source/LightingThread.cpp | 97 |
1 files changed, 60 insertions, 37 deletions
diff --git a/source/LightingThread.cpp b/source/LightingThread.cpp index d50cc28e2..5c39f731b 100644 --- a/source/LightingThread.cpp +++ b/source/LightingThread.cpp @@ -279,39 +279,65 @@ void cLightingThread::LightChunk(cLightingThread::sItem & a_Item) CalcLight(m_BlockLight); PrepareSkyLight(); - CalcLight(m_SkyLight); - - CompressLight(m_BlockLight, BlockLight); - CompressLight(m_SkyLight, SkyLight); /* - // DEBUG: + // DEBUG: Save chunk data with highlighted seeds for visual inspection: + cFile f4; + if ( + f4.Open(Printf("Chunk_%d_%d_seeds.grab", a_Item.x, a_Item.z), cFile::fmWrite) + ) { - cFile f("chunk_BlockTypes.dat", cFile::fmWrite); - if (f.IsOpen()) + for (int z = 0; z < cChunkDef::Width * 3; z++) { - f.Write(m_BlockTypes, sizeof(m_BlockTypes)); + for (int y = cChunkDef::Height / 2; y >= 0; y--) + { + unsigned char Seeds [cChunkDef::Width * 3]; + memcpy(Seeds, m_BlockTypes + y * BlocksPerYLayer + z * cChunkDef::Width * 3, cChunkDef::Width * 3); + for (int x = 0; x < cChunkDef::Width * 3; x++) + { + if (m_IsSeed1[y * BlocksPerYLayer + z * cChunkDef::Width * 3 + x]) + { + Seeds[x] = E_BLOCK_DIAMOND_BLOCK; + } + } + f4.Write(Seeds, cChunkDef::Width * 3); + } } } + //*/ - // DEBUG: - { - cFile f("Chunk_SkyLight.dat", cFile::fmWrite); - if (f.IsOpen()) - { - f.Write(m_SkyLight, sizeof(m_SkyLight)); - } - } + CalcLight(m_SkyLight); - // DEBUG: + /* + // DEBUG: Save XY slices of the chunk data and lighting for visual inspection: + cFile f1, f2, f3; + if ( + f1.Open(Printf("Chunk_%d_%d_data.grab", a_Item.x, a_Item.z), cFile::fmWrite) && + f2.Open(Printf("Chunk_%d_%d_sky.grab", a_Item.x, a_Item.z), cFile::fmWrite) && + f3.Open(Printf("Chunk_%d_%d_glow.grab", a_Item.x, a_Item.z), cFile::fmWrite) + ) { - cFile f("Chunk_BlockLight.dat", cFile::fmWrite); - if (f.IsOpen()) + for (int z = 0; z < cChunkDef::Width * 3; z++) { - f.Write(m_BlockLight, sizeof(m_BlockLight)); + for (int y = cChunkDef::Height / 2; y >= 0; y--) + { + f1.Write(m_BlockTypes + y * BlocksPerYLayer + z * cChunkDef::Width * 3, cChunkDef::Width * 3); + unsigned char SkyLight [cChunkDef::Width * 3]; + unsigned char BlockLight[cChunkDef::Width * 3]; + for (int x = 0; x < cChunkDef::Width * 3; x++) + { + SkyLight[x] = m_SkyLight [y * BlocksPerYLayer + z * cChunkDef::Width * 3 + x] << 4; + BlockLight[x] = m_BlockLight[y * BlocksPerYLayer + z * cChunkDef::Width * 3 + x] << 4; + } + f2.Write(SkyLight, cChunkDef::Width * 3); + f3.Write(BlockLight, cChunkDef::Width * 3); + } } } - */ + //*/ + + CompressLight(m_BlockLight, BlockLight); + CompressLight(m_SkyLight, SkyLight); m_World->ChunkLighted(a_Item.x, a_Item.z, BlockLight, SkyLight); @@ -374,25 +400,22 @@ void cLightingThread::PrepareSkyLight(void) int Neighbor4 = m_HeightMap[idx - cChunkDef::Width * 3] + 1; // Z - 1 int MaxNeighbor = MAX(MAX(Neighbor1, Neighbor2), MAX(Neighbor3, Neighbor4)); // Maximum of the four neighbors - // TODO: The following cycle can be transofrmed into two separate cycles with no condition inside them, one lighting and the other seeding - for (int y = Current, Index = idx + y * BlocksPerYLayer; y < cChunkDef::Height; y++, Index += BlocksPerYLayer) + // Fill the column from the top down to Current with all-light: + for (int y = cChunkDef::Height - 1, Index = idx + y * BlocksPerYLayer; y >= Current; y--, Index -= BlocksPerYLayer) + { + m_SkyLight[Index] = 15; + } + + // Add Current as a seed: + int CurrentIdx = idx + Current * BlocksPerYLayer; + m_IsSeed1[CurrentIdx] = true; + m_SeedIdx1[m_NumSeeds++] = CurrentIdx; + + // Add seed from Current up to the highest neighbor: + for (int y = Current + 1, Index = idx + y * BlocksPerYLayer; y < MaxNeighbor; y++, Index += BlocksPerYLayer) { - // If all the XZ neighbors are lower than y, abort for the current column (but light up the rest of it): - if (y >= MaxNeighbor) - { - for (int y2 = y; y2 < cChunkDef::Height; y2++, Index += BlocksPerYLayer) - { - m_SkyLight[Index] = 15; - } // for y2 - break; // for y - } - - // Add current block as a seed: m_IsSeed1[Index] = true; m_SeedIdx1[m_NumSeeds++] = Index; - - // Light it up to full skylight: - m_SkyLight[Index] = 15; } } } |