mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-19 03:05:29 +02:00
Simplify HUD handling in Player class
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user