From 9286d483650f68d3f6779a90178109ad25ab5b2b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 12 Dec 2025 19:36:12 +0300 Subject: [PATCH] feat: blocks renderer optimization --- src/graphics/render/BlocksRenderer.cpp | 3 +-- src/voxels/Chunks.cpp | 5 +++-- src/voxels/Chunks.hpp | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/graphics/render/BlocksRenderer.cpp b/src/graphics/render/BlocksRenderer.cpp index f2788df38..0d508223b 100644 --- a/src/graphics/render/BlocksRenderer.cpp +++ b/src/graphics/render/BlocksRenderer.cpp @@ -692,8 +692,7 @@ void BlocksRenderer::build(const Chunk* chunk, const Chunks* chunks) { voxelsBuffer->setPosition( chunk->x * CHUNK_W - voxelBufferPadding, 0, chunk->z * CHUNK_D - voxelBufferPadding); - chunks->getVoxels(*voxelsBuffer, settings.graphics.backlight.get()); - + chunks->getVoxels(*voxelsBuffer, settings.graphics.backlight.get(), chunk->top + 1); if (voxelsBuffer->pickBlockId( chunk->x * CHUNK_W, 0, chunk->z * CHUNK_D ) == BLOCK_VOID) { diff --git a/src/voxels/Chunks.cpp b/src/voxels/Chunks.cpp index eded34e89..96c709639 100644 --- a/src/voxels/Chunks.cpp +++ b/src/voxels/Chunks.cpp @@ -334,7 +334,8 @@ bool Chunks::putChunk(const std::shared_ptr& chunk) { // reduce nesting on next modification // 25.06.2024: not now // 11.11.2024: not now -void Chunks::getVoxels(VoxelsVolume& volume, bool backlight) const { +// 12.12.2025: not now +void Chunks::getVoxels(VoxelsVolume& volume, bool backlight, int top) const { voxel* voxels = volume.getVoxels(); light_t* lights = volume.getLights(); int x = volume.getX(); @@ -342,7 +343,7 @@ void Chunks::getVoxels(VoxelsVolume& volume, bool backlight) const { int z = volume.getZ(); int w = volume.getW(); - int h = volume.getH(); + int h = std::min(volume.getH(), top); int d = volume.getD(); int scx = floordiv(x); diff --git a/src/voxels/Chunks.hpp b/src/voxels/Chunks.hpp index 214e47c67..2448d8333 100644 --- a/src/voxels/Chunks.hpp +++ b/src/voxels/Chunks.hpp @@ -9,6 +9,7 @@ #include "typedefs.hpp" #include "voxel.hpp" +#include "constants.hpp" #include "util/AreaMap2D.hpp" class VoxelRenderer; @@ -126,7 +127,7 @@ public: bool isReplaceableBlock(int32_t x, int32_t y, int32_t z); bool isObstacleBlock(int32_t x, int32_t y, int32_t z); - void getVoxels(VoxelsVolume& volume, bool backlight = false) const; + void getVoxels(VoxelsVolume& volume, bool backlight = false, int top = CHUNK_H) const; void setCenter(int32_t x, int32_t z); void resize(uint32_t newW, uint32_t newD);