Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform server occlusion check before a block is loaded or generated. #14148

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/clientiface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,21 @@ void RemoteClient::GetNextBlocks (
if (!block->getIsUnderground() && !block->getDayNightDiff())
continue;
}
}

/*
Check occlusion cache first.
*/
if (m_blocks_occ.find(p) != m_blocks_occ.end())
continue;

if (m_occ_cull && !block_not_found &&
env->getMap().isBlockOccluded(block, cam_pos_nodes, d >= d_cull_opt)) {
m_blocks_occ.insert(p);
continue;
}
/*
Check occlusion cache first.
*/
if (m_blocks_occ.find(p) != m_blocks_occ.end())
continue;

/*
Note that we do this even before the block is loaded as this does not depend on its contents.
*/
if (m_occ_cull &&
lhofhansl marked this conversation as resolved.
Show resolved Hide resolved
env->getMap().isBlockOccluded(p * MAP_BLOCKSIZE, cam_pos_nodes, d >= d_cull_opt)) {
m_blocks_occ.insert(p);
continue;
}

/*
Expand Down
6 changes: 3 additions & 3 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ bool Map::isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target,
return false;
}

bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes, bool simple_check)
bool Map::isBlockOccluded(v3s16 pos_relative, v3s16 cam_pos_nodes, bool simple_check)
{
// Check occlusion for center and all 8 corners of the mapblock
// Overshoot a little for less flickering
Expand All @@ -1172,7 +1172,7 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes, bool simple_chec
v3s16(-1, -1, -1) * bs2,
};

v3s16 pos_blockcenter = block->getPosRelative() + (MAP_BLOCKSIZE / 2);
v3s16 pos_blockcenter = pos_relative + (MAP_BLOCKSIZE / 2);

// Starting step size, value between 1m and sqrt(3)m
float step = BS * 1.2f;
Expand Down Expand Up @@ -1203,7 +1203,7 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes, bool simple_chec

// Additional occlusion check, see comments in that function
v3s16 check;
if (determineAdditionalOcclusionCheck(cam_pos_nodes, block->getBox(), check)) {
if (determineAdditionalOcclusionCheck(cam_pos_nodes, MapBlock::getBox(pos_relative), check)) {
// node is always on a side facing the camera, end_offset can be lower
if (!isOccluded(cam_pos_nodes, check, step, stepfac, start_offset,
-1.0f, needed_count))
Expand Down
7 changes: 6 additions & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,12 @@ class Map /*: public NodeContainer*/
}
}

bool isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes, bool simple_check = false);
bool isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes, bool simple_check = false)
{
return isBlockOccluded(block->getPosRelative(), cam_pos_nodes, simple_check);
}
bool isBlockOccluded(v3s16 pos_relative, v3s16 cam_pos_nodes, bool simple_check = false);

protected:
IGameDef *m_gamedef;

Expand Down
10 changes: 7 additions & 3 deletions src/mapblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,14 @@ class MapBlock
return m_pos_relative;
}

inline core::aabbox3d<s16> getBox()
inline core::aabbox3d<s16> getBox() {
return getBox(getPosRelative());
}

static inline core::aabbox3d<s16> getBox(const v3s16 &pos_relative)
{
return core::aabbox3d<s16>(getPosRelative(),
getPosRelative()
return core::aabbox3d<s16>(pos_relative,
pos_relative
+ v3s16(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE)
- v3s16(1,1,1));
}
Expand Down