fix(perf): don't compute chunk connectivity when the BFS occluder is disabled

This commit is contained in:
Tropical 2026-04-07 16:56:20 -05:00
parent b88a89ae01
commit 56caa4f2dc
4 changed files with 23 additions and 0 deletions

View file

@ -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<Entity> 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;

View file

@ -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<std::shared_ptr<TileEntity> > renderableTileEntities;

View file

@ -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,

View file

@ -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<ClipChunk*> m_bfsGrid;
std::vector<uint8_t> m_bfsVisitedFaces[4];
#endif
std::unordered_map<int, BlockDestructionProgress*> 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);