1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Elide MapBlock::contents_cached

This commit is contained in:
sfan5 2023-12-12 16:08:41 +01:00
parent f5b35a074f
commit 777dca7043
3 changed files with 19 additions and 19 deletions

View file

@ -894,7 +894,8 @@ public:
// Check the content type cache first
// to see whether there are any ABMs
// to be run at all for this block.
if (block->contents_cached) {
if (!block->contents.empty()) {
assert(!block->do_not_cache_contents); // invariant
blocks_cached++;
bool run_abms = false;
for (content_t c : block->contents) {
@ -905,9 +906,6 @@ public:
}
if (!run_abms)
return;
} else {
// Clear any caching
block->contents.clear();
}
blocks_scanned++;
@ -917,6 +915,8 @@ public:
u32 active_object_count = this->countObjects(block, map, active_object_count_wider);
m_env->m_added_objects = 0;
bool want_contents_cached = block->contents.empty() && !block->do_not_cache_contents;
v3s16 p0;
for(p0.X=0; p0.X<MAP_BLOCKSIZE; p0.X++)
for(p0.Y=0; p0.Y<MAP_BLOCKSIZE; p0.Y++)
@ -926,14 +926,15 @@ public:
content_t c = n.getContent();
// Cache content types as we go
if (!block->contents_cached && !block->do_not_cache_contents) {
if (!CONTAINS(block->contents, c))
block->contents.push_back(c);
if (block->contents.size() > CONTENT_TYPE_CACHE_MAX) {
if (want_contents_cached && !CONTAINS(block->contents, c)) {
if (block->contents.size() >= CONTENT_TYPE_CACHE_MAX) {
// Too many different nodes... don't try to cache
want_contents_cached = false;
block->do_not_cache_contents = true;
block->contents.clear();
block->contents.shrink_to_fit();
} else {
block->contents.push_back(c);
}
}
@ -997,7 +998,6 @@ public:
break;
}
}
block->contents_cached = !block->do_not_cache_contents;
}
};