mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-08-20 09:57:10 +00:00
slight optimizations
This commit is contained in:
parent
19e7386d12
commit
f25b105bee
|
|
@ -2948,15 +2948,20 @@ void LevelRenderer::cull(Culler* culler, float a) {
|
||||||
int sizeX = maxCx - minCx + 1;
|
int sizeX = maxCx - minCx + 1;
|
||||||
int sizeY = maxCy - minCy + 1;
|
int sizeY = maxCy - minCy + 1;
|
||||||
int sizeZ = maxCz - minCz + 1;
|
int sizeZ = maxCz - minCz + 1;
|
||||||
|
int gridSize = sizeX * sizeY * sizeZ;
|
||||||
|
|
||||||
std::vector<ClipChunk*> grid(sizeX * sizeY * sizeZ, nullptr);
|
if (m_bfsGrid.size() < gridSize) {
|
||||||
|
m_bfsGrid.resize(gridSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(m_bfsGrid.data(), 0, gridSize * sizeof(ClipChunk*));
|
||||||
for (unsigned int i = 0; i < chunks[playerIndex].length; i++) {
|
for (unsigned int i = 0; i < chunks[playerIndex].length; i++) {
|
||||||
ClipChunk* cc = &chunks[playerIndex][i];
|
ClipChunk* cc = &chunks[playerIndex][i];
|
||||||
if (cc->globalIdx < 0) continue;
|
if (cc->globalIdx < 0) continue;
|
||||||
int lx = intFloorDiv(cc->chunk->x, CHUNK_XZSIZE) - minCx;
|
int lx = intFloorDiv(cc->chunk->x, CHUNK_XZSIZE) - minCx;
|
||||||
int ly = intFloorDiv(cc->chunk->y, CHUNK_SIZE) - minCy;
|
int ly = intFloorDiv(cc->chunk->y, CHUNK_SIZE) - minCy;
|
||||||
int lz = intFloorDiv(cc->chunk->z, CHUNK_XZSIZE) - minCz;
|
int lz = intFloorDiv(cc->chunk->z, CHUNK_XZSIZE) - minCz;
|
||||||
grid[(lx * sizeY + ly) * sizeZ + lz] = cc;
|
m_bfsGrid[(lx * sizeY + ly) * sizeZ + lz] = cc;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto getChunkAt = [&](int cx, int cy, int cz) -> ClipChunk* {
|
auto getChunkAt = [&](int cx, int cy, int cz) -> ClipChunk* {
|
||||||
|
|
@ -2965,7 +2970,7 @@ void LevelRenderer::cull(Culler* culler, float a) {
|
||||||
int lz = cz - minCz;
|
int lz = cz - minCz;
|
||||||
if (lx >= 0 && lx < sizeX && ly >= 0 && ly < sizeY && lz >= 0 &&
|
if (lx >= 0 && lx < sizeX && ly >= 0 && ly < sizeY && lz >= 0 &&
|
||||||
lz < sizeZ) {
|
lz < sizeZ) {
|
||||||
return grid[(lx * sizeY + ly) * sizeZ + lz];
|
return m_bfsGrid[(lx * sizeY + ly) * sizeZ + lz];
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
|
|
@ -3014,14 +3019,20 @@ void LevelRenderer::cull(Culler* culler, float a) {
|
||||||
int incomingFace;
|
int incomingFace;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<BFSNode> q;
|
static thread_local std::vector<BFSNode> q;
|
||||||
q.reserve(chunks[playerIndex].length * 2);
|
q.clear();
|
||||||
|
q.reserve(chunks[playerIndex].length);
|
||||||
int qHead = 0;
|
int qHead = 0;
|
||||||
|
|
||||||
std::vector<uint8_t> visitedFaces(chunks[playerIndex].length, 0);
|
int visitedSize = chunks[playerIndex].length;
|
||||||
|
if (m_bfsVisitedFaces[playerIndex].size() < visitedSize) {
|
||||||
|
m_bfsVisitedFaces[playerIndex].resize(visitedSize, 0);
|
||||||
|
}
|
||||||
|
memset(m_bfsVisitedFaces[playerIndex].data(), 0, visitedSize);
|
||||||
|
|
||||||
q.push_back({startChunk, -1});
|
q.push_back({startChunk, -1});
|
||||||
visitedFaces[startChunk - chunks[playerIndex].data] = 0x3F;
|
m_bfsVisitedFaces[playerIndex][startChunk - chunks[playerIndex].data] =
|
||||||
|
0x3F;
|
||||||
|
|
||||||
static const int OFFSETS[6][3] = {
|
static const int OFFSETS[6][3] = {
|
||||||
{0, -1, 0}, // 0: -Y
|
{0, -1, 0}, // 0: -Y
|
||||||
|
|
@ -3096,7 +3107,9 @@ void LevelRenderer::cull(Culler* culler, float a) {
|
||||||
int nIdx = neighbor - chunks[playerIndex].data;
|
int nIdx = neighbor - chunks[playerIndex].data;
|
||||||
int nextIncFace = outFace ^ 1;
|
int nextIncFace = outFace ^ 1;
|
||||||
|
|
||||||
if ((visitedFaces[nIdx] & (1 << nextIncFace)) != 0) continue;
|
if ((m_bfsVisitedFaces[playerIndex][nIdx] & (1 << nextIncFace)) !=
|
||||||
|
0)
|
||||||
|
continue;
|
||||||
|
|
||||||
float cellBounds[6] = {
|
float cellBounds[6] = {
|
||||||
(float)neighbor->chunk->x - 0.1f,
|
(float)neighbor->chunk->x - 0.1f,
|
||||||
|
|
@ -3108,7 +3121,7 @@ void LevelRenderer::cull(Culler* culler, float a) {
|
||||||
|
|
||||||
if (!clip(cellBounds, fdraw)) continue;
|
if (!clip(cellBounds, fdraw)) continue;
|
||||||
|
|
||||||
visitedFaces[nIdx] |= (1 << nextIncFace);
|
m_bfsVisitedFaces[playerIndex][nIdx] |= (1 << nextIncFace);
|
||||||
q.push_back({neighbor, nextIncFace});
|
q.push_back({neighbor, nextIncFace});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -221,13 +221,15 @@ private:
|
||||||
OffsettedRenderList renderLists[RENDERLISTS_LENGTH];
|
OffsettedRenderList renderLists[RENDERLISTS_LENGTH];
|
||||||
void setGlobalChunkConnectivity(int index, uint64_t conn);
|
void setGlobalChunkConnectivity(int index, uint64_t conn);
|
||||||
uint64_t getGlobalChunkConnectivity(int index);
|
uint64_t getGlobalChunkConnectivity(int index);
|
||||||
|
std::vector<ClipChunk*> m_bfsGrid;
|
||||||
|
std::vector<uint8_t> m_bfsVisitedFaces[4];
|
||||||
std::unordered_map<int, BlockDestructionProgress*> destroyingBlocks;
|
std::unordered_map<int, BlockDestructionProgress*> destroyingBlocks;
|
||||||
Icon** breakingTextures;
|
Icon** breakingTextures;
|
||||||
|
|
||||||
void addRenderableTileEntity_Locked(
|
void addRenderableTileEntity_Locked(
|
||||||
int key, const std::shared_ptr<TileEntity>& tileEntity);
|
int key, const std::shared_ptr<TileEntity>& tileEntity);
|
||||||
void eraseRenderableTileEntity_Locked(
|
void eraseRenderableTileEntity_Locked(RenderableTileEntityBucket& bucket,
|
||||||
RenderableTileEntityBucket& bucket, TileEntity* tileEntity);
|
TileEntity* tileEntity);
|
||||||
void queueRenderableTileEntityForRemoval_Locked(int key,
|
void queueRenderableTileEntityForRemoval_Locked(int key,
|
||||||
TileEntity* tileEntity);
|
TileEntity* tileEntity);
|
||||||
void retireRenderableTileEntitiesForChunkKey(int key);
|
void retireRenderableTileEntitiesForChunkKey(int key);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue