Fix issues with earlier CSM HUD commit (#6940)
authorred-001 <red-001@outlook.ie>
Fri, 26 Jan 2018 15:05:47 +0000 (15:05 +0000)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Fri, 26 Jan 2018 15:05:47 +0000 (16:05 +0100)
The CSM HUD PR caused some strange behavior including aborts due to parts of it using some slightly hacky code, the event refactor changing how events are processed and a minor oversight.

src/client.h
src/client/clientevent.h
src/game.cpp
src/network/clientpackethandler.cpp

index f438416aa301b7f9e08262488076def5af0a97e6..00ae4c7c332b16a5c42c67906d1bfa1b9708d0de 100644 (file)
@@ -422,6 +422,11 @@ public:
                return m_csm_noderange_limit;
        }
 
+       inline std::unordered_map<u32, u32> &getHUDTranslationMap()
+       {
+               return m_hud_server_to_client;
+       }
+
        bool joinModChannel(const std::string &channel);
        bool leaveModChannel(const std::string &channel);
        bool sendModChannelMessage(const std::string &channel, const std::string &message);
index e70937a9e96dc0e02778e02185d58c46f5fd8030..f0f1dc9e0b7fd61f8ee7a2190d2449106a58bc6f 100644 (file)
@@ -116,7 +116,7 @@ struct ClientEvent
                } delete_particlespawner;
                struct
                {
-                       u32 id;
+                       u32 server_id;
                        u8 type;
                        v2f *pos;
                        std::string *name;
index 55b2f5204f40d2eff08004848e8b3bc3c93ea1c6..b8d86be474ce8c74d42733c5ce324e0e65784e82 100644 (file)
@@ -2562,12 +2562,12 @@ 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 id = event->hudadd.id;
-
-       HudElement *e = player->getHud(id);
-
-       if (e != NULL) {
+       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()) {
                delete event->hudadd.pos;
                delete event->hudadd.name;
                delete event->hudadd.scale;
@@ -2579,7 +2579,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
                return;
        }
 
-       e = new HudElement;
+       HudElement *e = new HudElement;
        e->type   = (HudElementType)event->hudadd.type;
        e->pos    = *event->hudadd.pos;
        e->name   = *event->hudadd.name;
@@ -2592,10 +2592,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
        e->offset = *event->hudadd.offset;
        e->world_pos = *event->hudadd.world_pos;
        e->size = *event->hudadd.size;
-
-       u32 new_id = player->addHud(e);
-       //if this isn't true our huds aren't consistent
-       sanity_check(new_id == id);
+       hud_server_to_client[server_id] = player->addHud(e);
 
        delete event->hudadd.pos;
        delete event->hudadd.name;
index db3655875ffcaab457d90c6a4c3e98a7b4effe0d..aa4d8c244960dd69ede7653452f08a95721c4040 100644 (file)
@@ -1062,12 +1062,10 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt)
        try {
                *pkt >> size;
        } catch(SerializationError &e) {};
-       u32 client_id = getEnv().getLocalPlayer()->getFreeHudID();
-       m_hud_server_to_client[server_id] = client_id;
 
        ClientEvent *event = new ClientEvent();
        event->type             = CE_HUDADD;
-       event->hudadd.id        = client_id;
+       event->hudadd.server_id = server_id;
        event->hudadd.type      = type;
        event->hudadd.pos       = new v2f(pos);
        event->hudadd.name      = new std::string(name);
@@ -1089,7 +1087,7 @@ void Client::handleCommand_HudRemove(NetworkPacket* pkt)
 
        *pkt >> server_id;
 
-       std::unordered_map<u32, u32>::const_iterator i = m_hud_server_to_client.find(server_id);
+       auto i = m_hud_server_to_client.find(server_id);
        if (i != m_hud_server_to_client.end()) {
                int client_id = i->second;
                m_hud_server_to_client.erase(i);