From 56caa4f2dc62121daf8890de567a4e993c71fb45 Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Tue, 7 Apr 2026 16:56:20 -0500 Subject: [PATCH] fix(perf): don't compute chunk connectivity when the BFS occluder is disabled --- targets/minecraft/client/renderer/Chunk.cpp | 9 +++++++++ targets/minecraft/client/renderer/Chunk.h | 2 ++ targets/minecraft/client/renderer/LevelRenderer.cpp | 6 ++++++ targets/minecraft/client/renderer/LevelRenderer.h | 6 ++++++ 4 files changed, 23 insertions(+) diff --git a/targets/minecraft/client/renderer/Chunk.cpp b/targets/minecraft/client/renderer/Chunk.cpp index 989476468..ed6f1b7bd 100644 --- a/targets/minecraft/client/renderer/Chunk.cpp +++ b/targets/minecraft/client/renderer/Chunk.cpp @@ -142,7 +142,9 @@ void Chunk::setPos(int x, int y, int z) { clipChunk->globalIdx = LevelRenderer::getGlobalIndexForChunk(x, y, z, level); +#ifdef OCCLUSION_MODE_BFS levelRenderer->setGlobalChunkConnectivity(clipChunk->globalIdx, ~0ULL); +#endif // 4J - we're not using offsetted renderlists anymore, so just set the full // position of this chunk into x/y/zRenderOffs where it will be used @@ -415,11 +417,13 @@ void Chunk::rebuild() { RenderManager.CBuffClear(lists + currentLayer); } +#ifdef OCCLUSION_MODE_BFS int globalIdx = levelRenderer->getGlobalIndexForChunk(this->x, this->y, this->z, level); levelRenderer->setGlobalChunkConnectivity(globalIdx, ~0ULL); levelRenderer->setGlobalChunkFlag(this->x, this->y, this->z, level, LevelRenderer::CHUNK_FLAG_COMPILED); +#endif delete region; delete tileRenderer; @@ -538,10 +542,12 @@ void Chunk::rebuild() { bb = {bounds.boundingBox[0], bounds.boundingBox[1], bounds.boundingBox[2], bounds.boundingBox[3], bounds.boundingBox[4], bounds.boundingBox[5]}; +#ifdef OCCLUSION_MODE_BFS uint64_t conn = computeConnectivity(tileIds); // pass tileIds int globalIdx = levelRenderer->getGlobalIndexForChunk(this->x, this->y, this->z, level); levelRenderer->setGlobalChunkConnectivity(globalIdx, conn); +#endif delete tileRenderer; delete region; @@ -586,6 +592,7 @@ float Chunk::squishedDistanceToSqr(std::shared_ptr player) { return xd * xd + yd * yd + zd * zd; } +#ifdef OCCLUSION_MODE_BFS uint64_t Chunk::computeConnectivity(const uint8_t* tileIds) { const int W = 16; const int H = 16; @@ -722,6 +729,8 @@ uint64_t Chunk::computeConnectivity(const uint8_t* tileIds) { return result; } +#endif + void Chunk::reset() { if (assigned) { int oldKey = -1; diff --git a/targets/minecraft/client/renderer/Chunk.h b/targets/minecraft/client/renderer/Chunk.h index d54b21ad2..8c9589442 100644 --- a/targets/minecraft/client/renderer/Chunk.h +++ b/targets/minecraft/client/renderer/Chunk.h @@ -57,7 +57,9 @@ public: int xm, ym, zm; AABB bb; ClipChunk* clipChunk; +#ifdef OCCLUSION_MODE_BFS uint64_t computeConnectivity(const uint8_t* tileIds); +#endif int id; // public: // std::vector > renderableTileEntities; diff --git a/targets/minecraft/client/renderer/LevelRenderer.cpp b/targets/minecraft/client/renderer/LevelRenderer.cpp index 03173d8b2..d6feeb144 100644 --- a/targets/minecraft/client/renderer/LevelRenderer.cpp +++ b/targets/minecraft/client/renderer/LevelRenderer.cpp @@ -127,8 +127,10 @@ ResourceLocation LevelRenderer::END_SKY_LOCATION = const unsigned int HALO_RING_RADIUS = 100; +#ifdef OCCLUSION_MODE_BFS uint64_t* LevelRenderer::globalChunkConnectivity = nullptr; // bad placement do bettr juicey +#endif #if defined(_LARGE_WORLDS) Chunk LevelRenderer::permaChunk[MAX_CONCURRENT_CHUNK_REBUILDS]; @@ -225,9 +227,11 @@ LevelRenderer::LevelRenderer(Minecraft* mc, Textures* textures) { globalChunkFlags = new unsigned char[getGlobalChunkCount()]; memset(globalChunkFlags, 0, getGlobalChunkCount()); +#ifdef OCCLUSION_MODE_BFS globalChunkConnectivity = new uint64_t[getGlobalChunkCount()]; memset(globalChunkConnectivity, 0xFF, getGlobalChunkCount() * sizeof(uint64_t)); // 0xFF >> Fully open +#endif starList = MemoryTracker::genLists(4); @@ -3732,6 +3736,7 @@ void LevelRenderer::setGlobalChunkFlag(int x, int y, int z, Level* level, } } +#ifdef OCCLUSION_MODE_BFS void LevelRenderer::setGlobalChunkConnectivity(int index, uint64_t conn) { if (index >= 0 && index < getGlobalChunkCount()) { globalChunkConnectivity[index] = conn; @@ -3744,6 +3749,7 @@ uint64_t LevelRenderer::getGlobalChunkConnectivity(int index) { } return ~(uint64_t)0; // out of bounds } +#endif void LevelRenderer::clearGlobalChunkFlag(int x, int y, int z, Level* level, unsigned char flag, diff --git a/targets/minecraft/client/renderer/LevelRenderer.h b/targets/minecraft/client/renderer/LevelRenderer.h index 12e02de73..e07bd4732 100644 --- a/targets/minecraft/client/renderer/LevelRenderer.h +++ b/targets/minecraft/client/renderer/LevelRenderer.h @@ -220,10 +220,14 @@ private: emptyChunks; static const int RENDERLISTS_LENGTH = 4; // 4J - added OffsettedRenderList renderLists[RENDERLISTS_LENGTH]; + +#ifdef OCCLUSION_MODE_BFS void setGlobalChunkConnectivity(int index, uint64_t conn); uint64_t getGlobalChunkConnectivity(int index); std::vector m_bfsGrid; std::vector m_bfsVisitedFaces[4]; +#endif + std::unordered_map destroyingBlocks; Icon** breakingTextures; @@ -319,7 +323,9 @@ public: void clearGlobalChunkFlag(int x, int y, int z, Level* level, unsigned char flag, unsigned char shift = 0); +#ifdef OCCLUSION_MODE_BFS static uint64_t* globalChunkConnectivity; +#endif // Get/set whole byte of flags unsigned char getGlobalChunkFlags(int x, int y, int z, Level* level);