Changeset 5c7f28d in network-game for client/Client/main.cpp


Ignore:
Timestamp:
Jan 26, 2014, 9:45:30 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
c51da03
Parents:
9ee50ce
Message:

The global projectile map and related code is gone from main.cpp, the client processes LOGOUT messages about other players from STATE_GAME, and the map drawing code in GameRender uses switches instead of ifs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r9ee50ce r5c7f28d  
    5757void initWinSock();
    5858void shutdownWinSock();
    59 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers,
    60                     map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId);
     59void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId);
    6160int getRefreshRate(int width, int height);
    6261void drawMessageStatus(ALLEGRO_FONT* font);
     
    136135   bool key[4] = { false, false, false, false };
    137136   map<unsigned int, Player*> mapPlayers;
    138    map<unsigned int, Projectile> mapProjectiles;
    139137   unsigned int curPlayerId = -1;
    140138   ofstream outputLog;
     
    371369            case ALLEGRO_KEY_D:  // drop the current item
    372370               if (state == STATE_GAME) {
    373                   Player* p = NULL;
    374371                  try {
    375                      p = mapPlayers.at(curPlayerId);
    376                   } catch (const out_of_range& ex) {}
    377 
    378                   if (p != NULL) {
     372                     Player* p = mapPlayers.at(curPlayerId);
    379373                     int flagType = OBJECT_NONE;
    380374
     
    389383                        msgProcessor.sendMessage(&msgTo, &server);
    390384                     }
    391                   }
     385                  } catch (const out_of_range& ex) {}
    392386               }
    393387               break;
     
    428422               for(it = playersInGame.begin(); it != playersInGame.end(); it++)
    429423               {
    430                   // need to check if the right-click was actually on this player
    431                   // right now, this code will target all players other than the current one
    432424                  target = it->second;
    433425                  cout << "set target" << endl;
     
    459451
    460452      if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0)
    461          processMessage(msgFrom, state, chatConsole, mapPlayers, mapProjectiles, curPlayerId);
     453         processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId);
    462454
    463455      if (redraw)
     
    631623}
    632624
    633 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers,
    634                     map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId)
     625void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId)
    635626{
    636627   // this is outdated since most messages now don't contain just a text string
     
    790781               break;
    791782            }
    792             case MSG_TYPE_PROJECTILE:
    793             {
    794                cout << "Received a PROJECTILE message" << endl;
    795 
    796                unsigned int id, x, y, targetId;
    797 
    798                memcpy(&id, msg.buffer, 4);
    799                memcpy(&x, msg.buffer+4, 4);
    800                memcpy(&y, msg.buffer+8, 4);
    801                memcpy(&targetId, msg.buffer+12, 4);
    802 
    803                cout << "id: " << id << endl;
    804                cout << "x: " << x << endl;
    805                cout << "y: " << y << endl;
    806                cout << "Target: " << targetId << endl;
    807 
    808                Projectile proj(x, y, targetId, 0);
    809                proj.setId(id);
    810 
    811                mapProjectiles[id] = proj;
    812 
    813                break;
    814             }
    815             case MSG_TYPE_REMOVE_PROJECTILE:
    816             {
    817                 cout << "Received a REMOVE_PROJECTILE message" << endl;
    818 
    819                int id;
    820                memcpy(&id, msg.buffer, 4);
    821                
    822                mapProjectiles.erase(id);
    823 
    824                break;
    825             }
    826783            case MSG_TYPE_GAME_INFO:
    827784            {
     
    971928               else
    972929                  mapPlayers[p.getId()] = new Player(p);
     930
     931               break;
     932            }
     933             case MSG_TYPE_LOGOUT:
     934            {
     935               cout << "Got a logout message" << endl;
     936
     937               int playerId;
     938
     939               // Check if it's about you or another player
     940               memcpy(&playerId, msg.buffer, 4);
     941               response = string(msg.buffer+4);
     942
     943               if (playerId == curPlayerId)
     944                  cout << "Received MSG_TYPE_LOGOUT for self in STATE_GAME. This shouldn't happen." << endl;
     945               else
     946                  delete mapPlayers[playerId];
    973947
    974948               break;
Note: See TracChangeset for help on using the changeset viewer.