aboutsummaryrefslogtreecommitdiff
path: root/src/client/game.cpp
diff options
context:
space:
mode:
authorsavilli <78875209+savilli@users.noreply.github.com>2021-02-26 23:21:20 +0300
committerGitHub <noreply@github.com>2021-02-26 21:21:20 +0100
commit3edb1ddb8127aa7e8de867be50c695271091cb94 (patch)
tree579a97a09a3b7058e239ead7b3828ea13e2484ed /src/client/game.cpp
parentb5eda416cea3157ae3590fb7d229cd2cd17c3bf9 (diff)
downloadminetest-3edb1ddb8127aa7e8de867be50c695271091cb94.tar.gz
minetest-3edb1ddb8127aa7e8de867be50c695271091cb94.tar.bz2
minetest-3edb1ddb8127aa7e8de867be50c695271091cb94.zip
Fix hud_change and hud_remove after hud_add (#10997)
Diffstat (limited to 'src/client/game.cpp')
-rw-r--r--src/client/game.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/client/game.cpp b/src/client/game.cpp
index d4e2fe7c3..15fa2af23 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -856,6 +856,9 @@ private:
Hud *hud = nullptr;
Minimap *mapper = nullptr;
+ // Map server hud ids to client hud ids
+ std::unordered_map<u32, u32> m_hud_server_to_client;
+
GameRunData runData;
Flags m_flags;
@@ -2602,12 +2605,11 @@ void Game::handleClientEvent_HandleParticleEvent(ClientEvent *event,
void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
{
LocalPlayer *player = client->getEnv().getLocalPlayer();
- auto &hud_server_to_client = client->getHUDTranslationMap();
u32 server_id = event->hudadd.server_id;
// ignore if we already have a HUD with that ID
- auto i = hud_server_to_client.find(server_id);
- if (i != hud_server_to_client.end()) {
+ auto i = m_hud_server_to_client.find(server_id);
+ if (i != m_hud_server_to_client.end()) {
delete event->hudadd.pos;
delete event->hudadd.name;
delete event->hudadd.scale;
@@ -2635,7 +2637,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
e->size = *event->hudadd.size;
e->z_index = event->hudadd.z_index;
e->text2 = *event->hudadd.text2;
- hud_server_to_client[server_id] = player->addHud(e);
+ m_hud_server_to_client[server_id] = player->addHud(e);
delete event->hudadd.pos;
delete event->hudadd.name;
@@ -2651,18 +2653,28 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
void Game::handleClientEvent_HudRemove(ClientEvent *event, CameraOrientation *cam)
{
LocalPlayer *player = client->getEnv().getLocalPlayer();
- HudElement *e = player->removeHud(event->hudrm.id);
- delete e;
+
+ auto i = m_hud_server_to_client.find(event->hudrm.id);
+ if (i != m_hud_server_to_client.end()) {
+ HudElement *e = player->removeHud(i->second);
+ delete e;
+ m_hud_server_to_client.erase(i);
+ }
+
}
void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *cam)
{
LocalPlayer *player = client->getEnv().getLocalPlayer();
- u32 id = event->hudchange.id;
- HudElement *e = player->getHud(id);
+ HudElement *e = nullptr;
+
+ auto i = m_hud_server_to_client.find(event->hudchange.id);
+ if (i != m_hud_server_to_client.end()) {
+ e = player->getHud(i->second);
+ }
- if (e == NULL) {
+ if (e == nullptr) {
delete event->hudchange.v3fdata;
delete event->hudchange.v2fdata;
delete event->hudchange.sdata;