Changeset 31b347a in network-game for client/Client/main.cpp


Ignore:
Timestamp:
Dec 17, 2013, 2:11:14 PM (11 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
master
Children:
453087e
Parents:
e103b51
Message:

When the client receives a PLAYER message, a new PLAYER object is only created if the player doesn't already exist in the player list.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    re103b51 r31b347a  
    743743               cout << "Received MSG_TYPE_PLAYER" << endl;
    744744
    745                Player* p = new Player("", "");
    746                p->deserialize(msg.buffer);
    747                p->timeLastUpdated = getCurrentMillis();
    748                p->isChasing = false;
    749                if (p->health <= 0)
    750                   p->isDead = true;
     745               Player p("", "");
     746               p.deserialize(msg.buffer);
     747               p.timeLastUpdated = getCurrentMillis();
     748               p.isChasing = false;
     749               if (p.health <= 0)
     750                  p.isDead = true;
    751751               else
    752                   p->isDead = false;
    753 
    754                if (mapPlayers.find(p->id) != mapPlayers.end())
    755                     delete mapPlayers[p->id];
    756                mapPlayers[p->id] = p;
     752                  p.isDead = false;
     753
     754               if (mapPlayers.find(p.id) != mapPlayers.end())
     755                  *(mapPlayers[p.id]) = p;
     756               else
     757                  mapPlayers[p.id] = new Player(p);
    757758
    758759               break;
     
    947948               cout << "Received MSG_TYPE_PLAYER" << endl;
    948949
    949                Player* p = new Player("", "");
    950                p->deserialize(msg.buffer);
    951                p->timeLastUpdated = getCurrentMillis();
    952                p->isChasing = false;
    953                if (p->health <= 0)
    954                   p->isDead = true;
     950               Player p("", "");
     951               p.deserialize(msg.buffer);
     952               p.timeLastUpdated = getCurrentMillis();
     953               p.isChasing = false;
     954               if (p.health <= 0)
     955                  p.isDead = true;
    955956               else
    956                   p->isDead = false;
    957 
    958                if (mapPlayers.find(p->id) != mapPlayers.end())
    959                     delete mapPlayers[p->id];
    960                mapPlayers[p->id] = p;
    961 
    962                game->addPlayer(p);
     957                  p.isDead = false;
     958
     959               if (mapPlayers.find(p.id) != mapPlayers.end())
     960                  *(mapPlayers[p.id]) = p;
     961               else
     962                  mapPlayers[p.id] = new Player(p);
     963
     964               break;
     965
     966               // there's a problem here because PLAYER messages will be sent
     967               // for players in this game as well as for new players logging in
     968               // we might need two different message types
     969               game->addPlayer(mapPlayers[p.id]);
    963970
    964971               break;
Note: See TracChangeset for help on using the changeset viewer.