Huge LBM lookup performance improvement on mapblock loading (#7195)

* Huge LBM lookup performance improvement on mapblock loading
This commit is contained in:
Loïc Blot 2018-04-04 10:56:46 +02:00 committed by GitHub
parent 5070ca2111
commit 392e80e3f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 11 deletions

View File

@ -254,23 +254,32 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp)
MapNode n; MapNode n;
content_t c; content_t c;
lbm_lookup_map::const_iterator it = getLBMsIntroducedAfter(stamp); lbm_lookup_map::const_iterator it = getLBMsIntroducedAfter(stamp);
for (pos.X = 0; pos.X < MAP_BLOCKSIZE; pos.X++) for (; it != m_lbm_lookup.end(); ++it) {
for (pos.Y = 0; pos.Y < MAP_BLOCKSIZE; pos.Y++) // Cache previous version to speedup lookup which has a very high performance
for (pos.Z = 0; pos.Z < MAP_BLOCKSIZE; pos.Z++) // penalty on each call
{ content_t previous_c{};
n = block->getNodeNoEx(pos); std::vector<LoadingBlockModifierDef *> *lbm_list = nullptr;
c = n.getContent();
for (LBMManager::lbm_lookup_map::const_iterator iit = it; for (pos.X = 0; pos.X < MAP_BLOCKSIZE; pos.X++)
iit != m_lbm_lookup.end(); ++iit) { for (pos.Y = 0; pos.Y < MAP_BLOCKSIZE; pos.Y++)
const std::vector<LoadingBlockModifierDef *> *lbm_list = for (pos.Z = 0; pos.Z < MAP_BLOCKSIZE; pos.Z++) {
iit->second.lookup(c); n = block->getNodeNoEx(pos);
c = n.getContent();
// If content_t are not matching perform an LBM lookup
if (previous_c != c) {
lbm_list = (std::vector<LoadingBlockModifierDef *> *)
it->second.lookup(c);
previous_c = c;
}
if (!lbm_list) if (!lbm_list)
continue; continue;
for (auto lbmdef : *lbm_list) { for (auto lbmdef : *lbm_list) {
lbmdef->trigger(env, pos + pos_of_block, n); lbmdef->trigger(env, pos + pos_of_block, n);
} }
} }
} }
} }
/* /*