Improve LBMManager::applyLBMs() code

Fixes a possible bug for lbms on content ID zero and removes unsafe casts.
This commit is contained in:
sfan5 2022-06-05 16:58:48 +02:00
parent 03d86ea0b4
commit a69b7abe00

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