mirror of
https://github.com/minetest/minetest.git
synced 2024-08-19 13:04:09 +02:00
Allow access into MapSector::m_blocks (#14232)
* New API to allow access into MapSector::m_blocks * Use this API on ClientMap::touchMapBlocks(), ClientMap::updateDrawList(), and ClientMap::updateDrawListShadow() to speed them up
This commit is contained in:
parent
2766c70ad3
commit
4bf95703a0
@ -329,7 +329,7 @@ void ClientMap::updateDrawList()
|
|||||||
MapBlockVect sectorblocks;
|
MapBlockVect sectorblocks;
|
||||||
|
|
||||||
for (auto §or_it : m_sectors) {
|
for (auto §or_it : m_sectors) {
|
||||||
MapSector *sector = sector_it.second;
|
const MapSector *sector = sector_it.second;
|
||||||
v2s16 sp = sector->getPos();
|
v2s16 sp = sector->getPos();
|
||||||
|
|
||||||
blocks_loaded += sector->size();
|
blocks_loaded += sector->size();
|
||||||
@ -339,11 +339,9 @@ void ClientMap::updateDrawList()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sectorblocks.clear();
|
|
||||||
sector->getBlocks(sectorblocks);
|
|
||||||
|
|
||||||
// Loop through blocks in sector
|
// Loop through blocks in sector
|
||||||
for (MapBlock *block : sectorblocks) {
|
for (const auto &entry : sector->getBlocks()) {
|
||||||
|
MapBlock *block = entry.second.get();
|
||||||
MapBlockMesh *mesh = block->mesh;
|
MapBlockMesh *mesh = block->mesh;
|
||||||
|
|
||||||
// Calculate the coordinates for range and frustum culling
|
// Calculate the coordinates for range and frustum culling
|
||||||
@ -649,7 +647,7 @@ void ClientMap::touchMapBlocks()
|
|||||||
u32 blocks_in_range_with_mesh = 0;
|
u32 blocks_in_range_with_mesh = 0;
|
||||||
|
|
||||||
for (const auto §or_it : m_sectors) {
|
for (const auto §or_it : m_sectors) {
|
||||||
MapSector *sector = sector_it.second;
|
const MapSector *sector = sector_it.second;
|
||||||
v2s16 sp = sector->getPos();
|
v2s16 sp = sector->getPos();
|
||||||
|
|
||||||
blocks_loaded += sector->size();
|
blocks_loaded += sector->size();
|
||||||
@ -659,14 +657,12 @@ void ClientMap::touchMapBlocks()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
MapBlockVect sectorblocks;
|
|
||||||
sector->getBlocks(sectorblocks);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Loop through blocks in sector
|
Loop through blocks in sector
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (MapBlock *block : sectorblocks) {
|
for (const auto &entry : sector->getBlocks()) {
|
||||||
|
MapBlock *block = entry.second.get();
|
||||||
MapBlockMesh *mesh = block->mesh;
|
MapBlockMesh *mesh = block->mesh;
|
||||||
|
|
||||||
// Calculate the coordinates for range and frustum culling
|
// Calculate the coordinates for range and frustum culling
|
||||||
@ -1266,18 +1262,16 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir,
|
|||||||
u32 blocks_in_range_with_mesh = 0;
|
u32 blocks_in_range_with_mesh = 0;
|
||||||
|
|
||||||
for (auto §or_it : m_sectors) {
|
for (auto §or_it : m_sectors) {
|
||||||
MapSector *sector = sector_it.second;
|
const MapSector *sector = sector_it.second;
|
||||||
if (!sector)
|
if (!sector)
|
||||||
continue;
|
continue;
|
||||||
blocks_loaded += sector->size();
|
blocks_loaded += sector->size();
|
||||||
|
|
||||||
MapBlockVect sectorblocks;
|
|
||||||
sector->getBlocks(sectorblocks);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Loop through blocks in sector
|
Loop through blocks in sector
|
||||||
*/
|
*/
|
||||||
for (MapBlock *block : sectorblocks) {
|
for (const auto &entry : sector->getBlocks()) {
|
||||||
|
MapBlock *block = entry.second.get();
|
||||||
MapBlockMesh *mesh = block->mesh;
|
MapBlockMesh *mesh = block->mesh;
|
||||||
if (!mesh) {
|
if (!mesh) {
|
||||||
// Ignore if mesh doesn't exist
|
// Ignore if mesh doesn't exist
|
||||||
|
@ -45,7 +45,7 @@ public:
|
|||||||
|
|
||||||
void deleteBlocks();
|
void deleteBlocks();
|
||||||
|
|
||||||
v2s16 getPos()
|
v2s16 getPos() const
|
||||||
{
|
{
|
||||||
return m_pos;
|
return m_pos;
|
||||||
}
|
}
|
||||||
@ -62,8 +62,16 @@ public:
|
|||||||
// Returns an owning ptr to block.
|
// Returns an owning ptr to block.
|
||||||
std::unique_ptr<MapBlock> detachBlock(MapBlock *block);
|
std::unique_ptr<MapBlock> detachBlock(MapBlock *block);
|
||||||
|
|
||||||
|
// This makes a copy of the internal collection.
|
||||||
|
// Prefer getBlocks() if possible.
|
||||||
void getBlocks(MapBlockVect &dest);
|
void getBlocks(MapBlockVect &dest);
|
||||||
|
|
||||||
|
// Get access to the internal collection
|
||||||
|
// This is explicitly only allowed on a const object since modifying anything while iterating is unsafe.
|
||||||
|
// The caller needs to make sure that this does not happen.
|
||||||
|
const auto &getBlocks() const { return m_blocks; }
|
||||||
|
const auto &getBlocks() = delete;
|
||||||
|
|
||||||
bool empty() const { return m_blocks.empty(); }
|
bool empty() const { return m_blocks.empty(); }
|
||||||
|
|
||||||
int size() const { return m_blocks.size(); }
|
int size() const { return m_blocks.size(); }
|
||||||
|
Loading…
Reference in New Issue
Block a user