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

Allow unsafe access into MapSector::m_blocks #14232

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 6 additions & 12 deletions src/client/clientmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,9 @@ void ClientMap::updateDrawList()
continue;
}

sectorblocks.clear();
sector->getBlocks(sectorblocks);

// Loop through blocks in sector
for (MapBlock *block : sectorblocks) {
for (const auto &entry : sector->getBlocksUnsafe()) {
MapBlock *block = entry.second.get();
MapBlockMesh *mesh = block->mesh;

// Calculate the coordinates for range and frustum culling
Expand Down Expand Up @@ -659,14 +657,12 @@ void ClientMap::touchMapBlocks()
continue;
}

MapBlockVect sectorblocks;
sector->getBlocks(sectorblocks);

/*
Loop through blocks in sector
*/

for (MapBlock *block : sectorblocks) {
for (const auto &entry : sector->getBlocksUnsafe()) {
MapBlock *block = entry.second.get();
MapBlockMesh *mesh = block->mesh;

// Calculate the coordinates for range and frustum culling
Expand Down Expand Up @@ -1271,13 +1267,11 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir,
continue;
lhofhansl marked this conversation as resolved.
Show resolved Hide resolved
blocks_loaded += sector->size();

MapBlockVect sectorblocks;
sector->getBlocks(sectorblocks);

/*
Loop through blocks in sector
*/
for (MapBlock *block : sectorblocks) {
for (const auto &entry : sector->getBlocksUnsafe()) {
MapBlock *block = entry.second.get();
MapBlockMesh *mesh = block->mesh;
if (!mesh) {
// Ignore if mesh doesn't exist
Expand Down
4 changes: 4 additions & 0 deletions src/mapsector.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class MapSector

void getBlocks(MapBlockVect &dest);

// Get access to the internal map.
// When iterating over this map, do NOT call any MapSector methods that modify this map
const auto & getBlocksUnsafe() const { return m_blocks; }

bool empty() const { return m_blocks.empty(); }

int size() const { return m_blocks.size(); }
Expand Down