diff --git a/src/graphics/ChunksRenderer.cpp b/src/graphics/ChunksRenderer.cpp index b87ad1ee..3b39e235 100644 --- a/src/graphics/ChunksRenderer.cpp +++ b/src/graphics/ChunksRenderer.cpp @@ -9,7 +9,6 @@ #include using glm::ivec2; -using std::shared_ptr; ChunksRenderer::ChunksRenderer(Level* level, const ContentGfxCache* cache, const EngineSettings& settings) : level(level) { const int MAX_FULL_CUBES = 3000; @@ -20,10 +19,10 @@ ChunksRenderer::~ChunksRenderer() { delete renderer; } -shared_ptr ChunksRenderer::render(Chunk* chunk) { +std::shared_ptr ChunksRenderer::render(Chunk* chunk) { chunk->setModified(false); Mesh* mesh = renderer->render(chunk, level->chunksStorage); - auto sptr = shared_ptr(mesh); + auto sptr = std::shared_ptr(mesh); meshes[ivec2(chunk->x, chunk->z)] = sptr; return sptr; } @@ -35,7 +34,7 @@ void ChunksRenderer::unload(Chunk* chunk) { } } -shared_ptr ChunksRenderer::getOrRender(Chunk* chunk) { +std::shared_ptr ChunksRenderer::getOrRender(Chunk* chunk) { auto found = meshes.find(ivec2(chunk->x, chunk->z)); if (found != meshes.end() && !chunk->isModified()){ return found->second; @@ -43,7 +42,7 @@ shared_ptr ChunksRenderer::getOrRender(Chunk* chunk) { return render(chunk); } -shared_ptr ChunksRenderer::get(Chunk* chunk) { +std::shared_ptr ChunksRenderer::get(Chunk* chunk) { auto found = meshes.find(ivec2(chunk->x, chunk->z)); if (found != meshes.end()) { return found->second; diff --git a/src/lighting/Lighting.cpp b/src/lighting/Lighting.cpp index d4e4322e..f3343d9e 100644 --- a/src/lighting/Lighting.cpp +++ b/src/lighting/Lighting.cpp @@ -40,18 +40,17 @@ void Lighting::clear(){ } } -void Lighting::prebuildSkyLight(int cx, int cz){ - const Block* const* blockDefs = content->getIndices()->getBlockDefs(); +void Lighting::prebuildSkyLight(Chunk* chunk, const ContentIndices* indices){ + auto* blockDefs = indices->getBlockDefs(); - Chunk* chunk = chunks->getChunk(cx, cz); int highestPoint = 0; for (int z = 0; z < CHUNK_D; z++){ for (int x = 0; x < CHUNK_W; x++){ for (int y = CHUNK_H-1;;y--){ if (y < 0) break; - voxel* vox = &(chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x]); - const Block* block = blockDefs[vox->id]; + voxel& vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x]; + const Block* block = blockDefs[vox.id]; if (!block->skyLightPassing) { if (highestPoint < y) highestPoint = y; diff --git a/src/lighting/Lighting.h b/src/lighting/Lighting.h index 47fc962b..7ceb86ac 100644 --- a/src/lighting/Lighting.h +++ b/src/lighting/Lighting.h @@ -2,6 +2,8 @@ #define LIGHTING_LIGHTING_H_ class Content; +class ContentIndices; +class Chunk; class Chunks; class LightSolver; @@ -17,10 +19,11 @@ public: ~Lighting(); void clear(); - void prebuildSkyLight(int cx, int cz); void buildSkyLight(int cx, int cz); void onChunkLoaded(int cx, int cz, bool expand); void onBlockSet(int x, int y, int z, int id); + + static void prebuildSkyLight(Chunk* chunk, const ContentIndices* indices); }; #endif /* LIGHTING_LIGHTING_H_ */ diff --git a/src/logic/ChunksController.cpp b/src/logic/ChunksController.cpp index 0d2aabb3..3f6f006b 100644 --- a/src/logic/ChunksController.cpp +++ b/src/logic/ChunksController.cpp @@ -4,6 +4,7 @@ #include #include +#include "../content/Content.h" #include "../voxels/Block.h" #include "../voxels/Chunk.h" #include "../voxels/Chunks.h" @@ -63,7 +64,7 @@ bool ChunksController::loadVisible(){ int index = z * w + x; auto chunk = chunks->chunks[index]; if (chunk != nullptr){ - if (!chunk->isLighted()) { + if (chunk->isLoaded() && !chunk->isLighted()) { int surrounding = 0; for (int oz = -1; oz <= 1; oz++){ for (int ox = -1; ox <= 1; ox++){ @@ -112,11 +113,11 @@ bool ChunksController::loadVisible(){ ); chunk->setUnsaved(true); } - chunk->updateHeights(); if (!chunk->isLoadedLights()) { - lighting->prebuildSkyLight(chunk->x, chunk->z); + Lighting::prebuildSkyLight(chunk.get(), level->content->getIndices()); } + chunk->setLoaded(true); return true; } diff --git a/src/settings.h b/src/settings.h index dc21070f..cf106395 100644 --- a/src/settings.h +++ b/src/settings.h @@ -25,7 +25,7 @@ struct DisplaySettings { struct ChunksSettings { /* Max milliseconds that engine uses for chunks loading only */ - uint loadSpeed = 10; + uint loadSpeed = 4; /* Radius of chunks loading zone (chunk is unit) */ uint loadDistance = 22; /* Buffer zone where chunks are not unloading (chunk is unit)*/