1
0
mirror of https://github.com/minetest/minetest.git synced 2025-07-06 01:40:21 +02:00

Reserve vectors before pushing and other code quality changes (#11161)

This commit is contained in:
sfan5
2021-04-05 13:38:31 +02:00
committed by GitHub
parent 3e1904fa8c
commit f0bad0e2ba
20 changed files with 106 additions and 108 deletions

View File

@ -336,22 +336,22 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
irr::gui::IGUIFont* font = g_fontengine->getFont();
// Reorder elements by z_index
std::vector<size_t> ids;
std::vector<HudElement*> elems;
elems.reserve(player->maxHudId());
for (size_t i = 0; i != player->maxHudId(); i++) {
HudElement *e = player->getHud(i);
if (!e)
continue;
auto it = ids.begin();
while (it != ids.end() && player->getHud(*it)->z_index <= e->z_index)
auto it = elems.begin();
while (it != elems.end() && (*it)->z_index <= e->z_index)
++it;
ids.insert(it, i);
elems.insert(it, e);
}
for (size_t i : ids) {
HudElement *e = player->getHud(i);
for (HudElement *e : elems) {
v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5),
floor(e->pos.Y * (float) m_screensize.Y + 0.5));
@ -522,8 +522,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
client->getMinimap()->drawMinimap(rect);
break; }
default:
infostream << "Hud::drawLuaElements: ignoring drawform " << e->type <<
" of hud element ID " << i << " due to unrecognized type" << std::endl;
infostream << "Hud::drawLuaElements: ignoring drawform " << e->type
<< " due to unrecognized type" << std::endl;
}
}
}