Changeset b35b2b2 in network-game


Ignore:
Timestamp:
Jul 29, 2013, 10:32:59 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
d05086b
Parents:
297682c
Message:

Added a basic ingame debug console

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r297682c rb35b2b2  
    2828
    2929#include "../../common/Common.h"
     30#include "../../common/MessageContainer.h"
    3031#include "../../common/MessageProcessor.h"
    3132#include "../../common/WorldMap.h"
     
    6364void quit();
    6465void sendChatMessage();
     66void toggleDebugging();
     67void drawMessageStatus(ALLEGRO_FONT* font);
    6568
    6669void error(const char *);
     
    8285Window* wndRegister;
    8386Window* wndMain;
     87Window* wndMainDebug;
    8488Window* wndCurrent;
    8589
     
    103107NETWORK_MSG msgTo, msgFrom;
    104108string username;
    105 chat chatConsole;
     109chat chatConsole, debugConsole;
     110bool debugging;
    106111
    107112MessageProcessor msgProcessor;
     
    120125   int scoreBlue, scoreRed;
    121126   bool fullscreen = false;
     127   debugging = false;
    122128
    123129   scoreBlue = 0;
     
    183189
    184190   cout << "Loaded map" << endl;
     191
     192   debugConsole.addLine("Debug console:");
     193   debugConsole.addLine("");
    185194
    186195   wndLogin = new Window(0, 0, SCREEN_W, SCREEN_H);
     
    193202   wndLogin->addComponent(new Button(SCREEN_W/2+10, 130, 90, 20, font, "Login", login));
    194203   wndLogin->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit));
     204   wndLogin->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging));
    195205
    196206   txtUsername = (Textbox*)wndLogin->getComponent(0);
     
    210220   wndRegister->addComponent(new Button(SCREEN_W/2+10, 220, 90, 20, font, "Submit", registerAccount));
    211221   wndRegister->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit));
     222   wndRegister->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging));
    212223
    213224   txtUsernameRegister = (Textbox*)wndRegister->getComponent(0);
     
    225236   wndMain->addComponent(new Textbox(95, 40, 300, 20, font));
    226237   wndMain->addComponent(new Button(95, 70, 60, 20, font, "Send", sendChatMessage));
     238   wndMain->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging));
    227239   wndMain->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout));
    228240
    229241   txtChat = (Textbox*)wndMain->getComponent(0);
     242
     243   wndMainDebug = new Window(0, 0, SCREEN_W, SCREEN_H);
     244   wndMainDebug->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging));
     245   wndMainDebug->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout));
    230246
    231247   cout << "Created main screen" << endl;
     
    391407
    392408         msgProcessor.resendUnackedMessages(sock);
    393          msgProcessor.cleanAckedMessages();
    394 
    395          wndCurrent->draw(display);
     409         //msgProcessor.cleanAckedMessages();
     410
     411         if (debugging && wndCurrent == wndMain)
     412            wndMainDebug->draw(display);
     413         else
     414            wndCurrent->draw(display);
    396415
    397416         if(wndCurrent == wndMain) {
    398             chatConsole.draw(font, al_map_rgb(255,255,255));
     417            if (!debugging)
     418               chatConsole.draw(font, al_map_rgb(255,255,255));
    399419
    400420            al_draw_text(font, al_map_rgb(0, 255, 0), 4, 43, ALLEGRO_ALIGN_LEFT, "Message:");
     
    449469               al_draw_line(start.x, start.y, end.x, end.y, al_map_rgb(0, 0, 0), 4);
    450470            }
     471         }
     472
     473         if (debugging) {
     474            //debugConsole.draw(font, al_map_rgb(255,255,255));
     475            drawMessageStatus(font);
    451476         }
    452477
     
    9771002}
    9781003
    979 int getRefreshRate(int width, int height) {
     1004void toggleDebugging()
     1005{
     1006   debugging = !debugging;
     1007}
     1008
     1009int getRefreshRate(int width, int height)
     1010{
    9801011   int numRefreshRates = al_get_num_display_modes();
    9811012   ALLEGRO_DISPLAY_MODE displayMode;
     
    9901021   return 0;
    9911022}
     1023
     1024void drawMessageStatus(ALLEGRO_FONT* font)
     1025{
     1026   int clientMsgOffset = 0;
     1027   int serverMsgOffset = 650;
     1028
     1029   al_draw_text(font, al_map_rgb(0, 255, 255), 5, 43, ALLEGRO_ALIGN_LEFT, "ID");
     1030   al_draw_text(font, al_map_rgb(0, 255, 255), 25, 43, ALLEGRO_ALIGN_LEFT, "Type");
     1031   al_draw_text(font, al_map_rgb(0, 255, 255), 245, 43, ALLEGRO_ALIGN_LEFT, "Acked?");
     1032
     1033   al_draw_text(font, al_map_rgb(0, 255, 255), 5+serverMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "ID");
     1034   al_draw_text(font, al_map_rgb(0, 255, 255), 25+serverMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "Type");
     1035
     1036   map<unsigned int, map<unsigned long, MessageContainer> >& sentMessages = msgProcessor.getSentMessages();
     1037   int id, type;
     1038   bool acked;
     1039   ostringstream ossId, ossAcked;
     1040
     1041   map<unsigned int, map<unsigned long, MessageContainer> >::iterator it;
     1042
     1043   int msgCount = 0;
     1044   for (it = sentMessages.begin(); it != sentMessages.end(); it++) {
     1045      map<unsigned long, MessageContainer> playerMessage = it->second;
     1046      map<unsigned long, MessageContainer>::iterator it2;
     1047      for (it2 = playerMessage.begin(); it2 !=  playerMessage.end(); it2++) {
     1048
     1049         id = it->first;
     1050         ossId.str("");;
     1051         ossId << id;
     1052
     1053         type = it2->second.getMessage()->type;
     1054         string typeStr = MessageContainer::getMsgTypeString(type);
     1055
     1056         acked = it2->second.getAcked();
     1057         ossAcked.str("");;
     1058         ossAcked << boolalpha << acked;
     1059
     1060         al_draw_text(font, al_map_rgb(0, 255, 0), 5, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossId.str().c_str());
     1061         al_draw_text(font, al_map_rgb(0, 255, 0), 25, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, typeStr.c_str());
     1062         al_draw_text(font, al_map_rgb(0, 255, 0), 245, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossAcked.str().c_str());
     1063
     1064         msgCount++;
     1065      }
     1066   }
     1067
     1068   map<unsigned int, MessageContainer>& ackedMessages = msgProcessor.getAckedMessages();
     1069   map<unsigned int, MessageContainer>::iterator it3;
     1070
     1071   msgCount = 0;
     1072   for (it3 = ackedMessages.begin(); it3 != ackedMessages.end(); it3++) {
     1073      ossId.str("");;
     1074      ossId << it3->first;
     1075
     1076      string typeStr = MessageContainer::getMsgTypeString(it3->second.getMessage()->type);
     1077
     1078      al_draw_text(font, al_map_rgb(255, 0, 0), 5+serverMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossId.str().c_str());
     1079      al_draw_text(font, al_map_rgb(255, 0, 0), 25+serverMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, typeStr.c_str());
     1080
     1081      msgCount++;
     1082   }
     1083}
  • common/MessageContainer.cpp

    r297682c rb35b2b2  
    4848   this->timeAcked = time;
    4949}
     50
     51/*
     52string getMsgTypeString(int msgType) {
     53   switch(msgType) {
     54      case MSG_TYPE_ACK: return "MSG_TYPE_ACK";
     55      case MSG_TYPE_REGISTER: return "MSG_TYPE_REGISTER";
     56      case MSG_TYPE_LOGIN: return "MSG_TYPE_LOGIN";
     57      case MSG_TYPE_LOGOUT: return "MSG_TYPE_LOGOUT";
     58      case MSG_TYPE_CHAT: return "MSG_TYPE_CHAT";
     59      case MSG_TYPE_PLAYER: return "MSG_TYPE_PLAYER";
     60      case MSG_TYPE_PLAYER_MOVE: return "MSG_TYPE_PLAYER_MOVE";
     61      case MSG_TYPE_OBJECT: return "MSG_TYPE_OBJECT";
     62      case MSG_TYPE_REMOVE_OBJECT: return "MSG_TYPE_REMOVE_OBJECT";
     63      case MSG_TYPE_PICKUP_FLAG: return "MSG_TYPE_PICKUP_FLAG";
     64      caseMSG_TYPE_DROP_FLAG: return "MSG_TYPE_DROP_FLAG";
     65      case MSG_TYPE_SCORE: return "MSG_TYPE_SCORE";
     66      case MSG_TYPE_START_ATTACK: return "MSG_TYPE_START_ATACK";
     67      case MSG_TYPE_ATTACK: return "MSG_TYPE_ATTACK";
     68      case MSG_TYPE_PROJECTILE: return "MSG_TYPE_PROJECTILE";
     69      case MSG_TYPE_REMOVE_PROJECTILE: return "MSG_TYPE_REMOVE_PROJECTILE";
     70      default: return "Unknown";
     71   }
     72}
     73*/
  • common/MessageContainer.h

    r297682c rb35b2b2  
    33
    44#include "Compiler.h"
     5
     6#include <string>
    57
    68#if defined WINDOWS
     
    1012   #include <netinet/in.h>
    1113#endif
     14
     15using namespace std;
    1216
    1317#define MSG_TYPE_ACK               1
     
    5458   void setAcked(bool acked);
    5559   void setTimeAcked(unsigned long long time);
     60
     61   static string getMsgTypeString(int msgType) {
     62      switch(msgType) {
     63         case MSG_TYPE_ACK: return "MSG_TYPE_ACK";
     64         case MSG_TYPE_REGISTER: return "MSG_TYPE_REGISTER";
     65         case MSG_TYPE_LOGIN: return "MSG_TYPE_LOGIN";
     66         case MSG_TYPE_LOGOUT: return "MSG_TYPE_LOGOUT";
     67         case MSG_TYPE_CHAT: return "MSG_TYPE_CHAT";
     68         case MSG_TYPE_PLAYER: return "MSG_TYPE_PLAYER";
     69         case MSG_TYPE_PLAYER_MOVE: return "MSG_TYPE_PLAYER_MOVE";
     70         case MSG_TYPE_OBJECT: return "MSG_TYPE_OBJECT";
     71         case MSG_TYPE_REMOVE_OBJECT: return "MSG_TYPE_REMOVE_OBJECT";
     72         case MSG_TYPE_PICKUP_FLAG: return "MSG_TYPE_PICKUP_FLAG";
     73         case MSG_TYPE_DROP_FLAG: return "MSG_TYPE_DROP_FLAG";
     74         case MSG_TYPE_SCORE: return "MSG_TYPE_SCORE";
     75         case MSG_TYPE_START_ATTACK: return "MSG_TYPE_START_ATACK";
     76         case MSG_TYPE_ATTACK: return "MSG_TYPE_ATTACK";
     77         case MSG_TYPE_PROJECTILE: return "MSG_TYPE_PROJECTILE";
     78         case MSG_TYPE_REMOVE_PROJECTILE: return "MSG_TYPE_REMOVE_PROJECTILE";
     79         default: return "Unknown";
     80      }
     81   }
    5682};
    5783
  • common/MessageProcessor.cpp

    r297682c rb35b2b2  
    5252         cout << "Got message of type " << msg->type << endl;
    5353
    54       ackedMessages[msg->id] = getCurrentMillis();
     54      ackedMessages[msg->id] = MessageContainer(*msg, *source);
     55      ackedMessages[msg->id].setAcked(true);
     56      ackedMessages[msg->id].setTimeAcked(getCurrentMillis());
    5557
    5658      NETWORK_MSG ack;
     
    6870
    6971void MessageProcessor::resendUnackedMessages(int sock) {
    70    map<int, map<unsigned long, MessageContainer> >::iterator it;
     72   map<unsigned int, map<unsigned long, MessageContainer> >::iterator it;
    7173   map<unsigned long, MessageContainer>::iterator it2;
    7274   map<unsigned long, MessageContainer> sentMsg;
     
    8385
    8486void MessageProcessor::cleanAckedMessages() {
    85    map<int, map<unsigned long, MessageContainer> >::iterator it = sentMessages.begin();
     87   map<unsigned int, map<unsigned long, MessageContainer> >::iterator it = sentMessages.begin();
    8688   map<unsigned long, MessageContainer>::iterator it2;
    8789
     
    104106   }
    105107
     108   /*
    106109   map<unsigned int, unsigned long long>::iterator it3 = ackedMessages.begin();
    107110
     
    112115         it3++;
    113116   }
     117   */
    114118}
     119
     120map<unsigned int, map<unsigned long, MessageContainer> >& MessageProcessor::getSentMessages() {
     121   return this->sentMessages;
     122}
     123
     124map<unsigned int, MessageContainer>& MessageProcessor::getAckedMessages() {
     125   return this->ackedMessages;
     126}
  • common/MessageProcessor.h

    r297682c rb35b2b2  
    1313
    1414   // map from message ids to maps from player addresses to message info
    15    map<int, map<unsigned long, MessageContainer> > sentMessages;
     15   map<unsigned int, map<unsigned long, MessageContainer> > sentMessages;
    1616
    1717   // map from message ids to the time each mesage was acked
    18    map<unsigned int, unsigned long long> ackedMessages;
     18   map<unsigned int, MessageContainer> ackedMessages;
    1919
    2020   unsigned long pid;
     
    2828   void resendUnackedMessages(int sock);
    2929   void cleanAckedMessages();
     30
     31   map<unsigned int, map<unsigned long, MessageContainer> >& getSentMessages();
     32   map<unsigned int, MessageContainer>& getAckedMessages();
    3033};
    3134
Note: See TracChangeset for help on using the changeset viewer.