Changeset 753fa8a in network-game


Ignore:
Timestamp:
Aug 3, 2013, 1:13:25 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
f419b09
Parents:
f9cb9fb
Message:

The client now uses the new getAckedMessages method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    rf9cb9fb r753fa8a  
    112112
    113113MessageProcessor msgProcessor;
     114ofstream outputLog;
    114115
    115116int main(int argc, char **argv)
     
    127128   bool fullscreen = false;
    128129   debugging = false;
    129    ofstream outputLog;
    130130
    131131   scoreBlue = 0;
     
    322322                  msgTo.type = MSG_TYPE_PICKUP_FLAG;
    323323                  memcpy(msgTo.buffer, &curPlayerId, 4);
    324                   msgProcessor.sendMessage(&msgTo, sock, &server);
     324                  msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    325325               }
    326326               break;
     
    347347                        msgTo.type = MSG_TYPE_DROP_FLAG;
    348348                        memcpy(msgTo.buffer, &curPlayerId, 4);
    349                         msgProcessor.sendMessage(&msgTo, sock, &server);
     349                        msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    350350                     }
    351351                  }
     
    370370                  memcpy(msgTo.buffer+8, &pos.y, 4);
    371371
    372                   msgProcessor.sendMessage(&msgTo, sock, &server);
     372                  msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    373373               }
    374374               else
     
    397397                        memcpy(msgTo.buffer+4, &target->id, 4);
    398398
    399                         msgProcessor.sendMessage(&msgTo, sock, &server);
     399                        msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    400400                     }
    401401                  }
     
    404404      }
    405405
    406       if (msgProcessor.receiveMessage(&msgFrom, sock, &from) >= 0)
     406      if (msgProcessor.receiveMessage(&msgFrom, sock, &from, &outputLog) >= 0)
    407407         processMessage(msgFrom, state, chatConsole, gameMap, mapPlayers, mapProjectiles, curPlayerId, scoreBlue, scoreRed);
    408408
     
    411411         redraw = false;
    412412
    413          msgProcessor.resendUnackedMessages(sock);
    414          //msgProcessor.cleanAckedMessages();
     413         msgProcessor.resendUnackedMessages(sock, &outputLog);
     414         //msgProcessor.cleanAckedMessages(&outputLog);
    415415
    416416         if (debugging && wndCurrent == wndMain)
     
    958958   memcpy(msgTo.buffer+username.size()+password.size()+2, &playerClass, 4);
    959959
    960    msgProcessor.sendMessage(&msgTo, sock, &server);
     960   msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    961961}
    962962
     
    975975   strcpy(msgTo.buffer+username.size()+1, strPassword.c_str());
    976976
    977    msgProcessor.sendMessage(&msgTo, sock, &server);
     977   msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    978978
    979979   state = STATE_LOGIN;
     
    989989   strcpy(msgTo.buffer, username.c_str());
    990990
    991    msgProcessor.sendMessage(&msgTo, sock, &server);
     991   msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    992992}
    993993
     
    10071007   strcpy(msgTo.buffer, msg.c_str());
    10081008
    1009    msgProcessor.sendMessage(&msgTo, sock, &server);
     1009   msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    10101010}
    10111011
     
    10321032void drawMessageStatus(ALLEGRO_FONT* font)
    10331033{
    1034    int clientMsgOffset = 0;
    1035    int serverMsgOffset = 650;
    1036 
    1037    al_draw_text(font, al_map_rgb(0, 255, 255), 5, 43, ALLEGRO_ALIGN_LEFT, "ID");
    1038    al_draw_text(font, al_map_rgb(0, 255, 255), 25, 43, ALLEGRO_ALIGN_LEFT, "Type");
    1039    al_draw_text(font, al_map_rgb(0, 255, 255), 245, 43, ALLEGRO_ALIGN_LEFT, "Acked?");
    1040 
    1041    al_draw_text(font, al_map_rgb(0, 255, 255), 5+serverMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "ID");
    1042    al_draw_text(font, al_map_rgb(0, 255, 255), 25+serverMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "Type");
     1034   int clientMsgOffset = 5;
     1035   int serverMsgOffset = 950;
     1036
     1037   al_draw_text(font, al_map_rgb(0, 255, 255), 0+clientMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "ID");
     1038   al_draw_text(font, al_map_rgb(0, 255, 255), 20+clientMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "Type");
     1039   al_draw_text(font, al_map_rgb(0, 255, 255), 240+clientMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "Acked?");
     1040
     1041   al_draw_text(font, al_map_rgb(0, 255, 255), serverMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "ID");
    10431042
    10441043   map<unsigned int, map<unsigned long, MessageContainer> >& sentMessages = msgProcessor.getSentMessages();
     
    10661065         ossAcked << boolalpha << acked;
    10671066
    1068          al_draw_text(font, al_map_rgb(0, 255, 0), 5, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossId.str().c_str());
    1069          al_draw_text(font, al_map_rgb(0, 255, 0), 25, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, typeStr.c_str());
    1070          al_draw_text(font, al_map_rgb(0, 255, 0), 245, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossAcked.str().c_str());
     1067         al_draw_text(font, al_map_rgb(0, 255, 0), clientMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossId.str().c_str());
     1068         al_draw_text(font, al_map_rgb(0, 255, 0), 20+clientMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, typeStr.c_str());
     1069         al_draw_text(font, al_map_rgb(0, 255, 0), 240+clientMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossAcked.str().c_str());
    10711070
    10721071         msgCount++;
     
    10741073   }
    10751074
    1076    map<unsigned int, MessageContainer>& ackedMessages = msgProcessor.getAckedMessages();
    1077    map<unsigned int, MessageContainer>::iterator it3;
    1078 
    1079    msgCount = 0;
    1080    for (it3 = ackedMessages.begin(); it3 != ackedMessages.end(); it3++) {
    1081       ossId.str("");;
    1082       ossId << it3->first;
    1083 
    1084       string typeStr = MessageContainer::getMsgTypeString(it3->second.getMessage()->type);
    1085 
    1086       al_draw_text(font, al_map_rgb(255, 0, 0), 5+serverMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossId.str().c_str());
    1087       al_draw_text(font, al_map_rgb(255, 0, 0), 25+serverMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, typeStr.c_str());
    1088 
    1089       msgCount++;
    1090    }
    1091 }
     1075   if (msgProcessor.getAckedMessages().size() > 0) {
     1076      map<unsigned int, unsigned long long> ackedMessages = msgProcessor.getAckedMessages()[0];
     1077      map<unsigned int, unsigned long long>::iterator it3;
     1078
     1079      msgCount = 0;
     1080      for (it3 = ackedMessages.begin(); it3 != ackedMessages.end(); it3++) {
     1081         ossId.str("");;
     1082         ossId << it3->first;
     1083
     1084         al_draw_text(font, al_map_rgb(255, 0, 0), 25+serverMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossId.str().c_str());
     1085
     1086         msgCount++;
     1087      }
     1088   }
     1089}
Note: See TracChangeset for help on using the changeset viewer.