1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-30 19:22:14 +00:00

Simplify HUD handling in Player class

This commit is contained in:
sfan5 2025-08-14 17:10:07 +02:00
parent bb74b9d488
commit 36b5374715
6 changed files with 35 additions and 65 deletions

View file

@ -110,8 +110,6 @@ ItemStack &Player::getWieldedItem(ItemStack *selected, ItemStack *hand) const
u32 Player::addHud(HudElement *toadd)
{
MutexAutoLock lock(m_mutex);
u32 id = getFreeHudID();
if (id < hud.size())
@ -124,37 +122,27 @@ u32 Player::addHud(HudElement *toadd)
HudElement* Player::getHud(u32 id)
{
MutexAutoLock lock(m_mutex);
if (id < hud.size())
return hud[id];
return NULL;
}
void Player::hudApply(std::function<void(const std::vector<HudElement*>&)> f)
{
MutexAutoLock lock(m_mutex);
f(hud);
return nullptr;
}
HudElement* Player::removeHud(u32 id)
{
MutexAutoLock lock(m_mutex);
HudElement* retval = NULL;
HudElement* retval = nullptr;
if (id < hud.size()) {
retval = hud[id];
hud[id] = NULL;
hud[id] = nullptr;
}
// shrink list if possible
while (!hud.empty() && hud.back() == nullptr)
hud.pop_back();
return retval;
}
void Player::clearHud()
{
MutexAutoLock lock(m_mutex);
while(!hud.empty()) {
while (!hud.empty()) {
delete hud.back();
hud.pop_back();
}