Changeset 95ffe57 in network-game for client/Client/main.cpp


Ignore:
Timestamp:
Oct 4, 2013, 5:06:20 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
90eaad2
Parents:
e6c26b8
Message:

The server now has a map of Player pointers instead of Players and MSG_TYPE_PLAYER is sent to notify a player joining a game about the players already in the game

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    re6c26b8 r95ffe57  
    674674               {
    675675                  wndCurrent = wndLobby;
    676                  
    677                   Player p("", "");
    678                   p.deserialize(msg.buffer);
    679 
    680                   if (mapPlayers.find(p.id) != mapPlayers.end())
    681                      delete mapPlayers[p.id];
    682                   mapPlayers[p.id] = new Player(p);
    683                   curPlayerId = p.id;
     676               
     677                  // this message should only be sent when a player first logs in so they know their id
     678 
     679                  Player* p = new Player("", "");
     680                  p->deserialize(msg.buffer);
     681
     682                  if (mapPlayers.find(p->id) != mapPlayers.end())
     683                     delete mapPlayers[p->id];
     684                  mapPlayers[p->id] = p;
     685                  curPlayerId = p->id;
    684686
    685687                  cout << "Got a valid login response with the player" << endl;
    686688                  cout << "Player id: " << curPlayerId << endl;
    687                   cout << "Player health: " << p.health << endl;
     689                  cout << "Player health: " << p->health << endl;
    688690                  cout << "player map size: " << mapPlayers.size() << endl;
    689691               }
     
    708710               cout << "Received MSG_TYPE_PLAYER" << endl;
    709711
    710                Player p("", "");
    711                p.deserialize(msg.buffer);
    712                p.timeLastUpdated = getCurrentMillis();
    713                p.isChasing = false;
    714                if (p.health <= 0)
    715                   p.isDead = true;
     712               Player* p = new Player("", "");
     713               p->deserialize(msg.buffer);
     714               p->timeLastUpdated = getCurrentMillis();
     715               p->isChasing = false;
     716               if (p->health <= 0)
     717                  p->isDead = true;
    716718               else
    717                   p.isDead = false;
    718 
    719                if (mapPlayers.find(p.id) != mapPlayers.end())
    720                     delete mapPlayers[p.id];
    721                mapPlayers[p.id] = new Player(p);
     719                  p->isDead = false;
     720
     721               if (mapPlayers.find(p->id) != mapPlayers.end())
     722                    delete mapPlayers[p->id];
     723               mapPlayers[p->id] = p;
    722724
    723725               break;
Note: See TracChangeset for help on using the changeset viewer.