Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2965


Ignore:
Timestamp:
May 11, 2009, 1:42:10 PM (15 years ago)
Author:
scheusso
Message:

some fixes (bidirectional variables, …), some changes (client tickrate, connection handling)

Location:
code/branches/netp2/src/network
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp2/src/network/Client.cc

    r2948 r2965  
    140140   */
    141141  void Client::tick(float time){
    142 //     COUT(3) << ".";
    143     if(client_connection.isConnected() && isSynched_){
    144       COUT(4) << "popping partial gamestate: " << std::endl;
    145       packet::Gamestate *gs = gamestate.getGamestate();
    146       if(gs){
    147         COUT(4) << "client tick: sending gs " << gs << std::endl;
    148         if( !gs->send() )
    149           COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
     142    //this steers our network frequency
     143    timeSinceLastUpdate_+=time;
     144    if(timeSinceLastUpdate_>=NETWORK_PERIOD){
     145      timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
     146      //     COUT(3) << ".";
     147      if(client_connection.isConnected() && isSynched_){
     148        COUT(4) << "popping partial gamestate: " << std::endl;
     149        packet::Gamestate *gs = gamestate.getGamestate();
     150        if(gs){
     151          COUT(4) << "client tick: sending gs " << gs << std::endl;
     152          if( !gs->send() )
     153            COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
    150154        // gs gets automatically deleted by enet callback
     155        }
     156        FunctionCallManager::sendCalls();
    151157      }
    152       FunctionCallManager::sendCalls();
     158      ENetEvent *event;
     159    // stop if the packet queue is empty
     160      while(!(client_connection.queueEmpty())){
     161        event = client_connection.getEvent();
     162        COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
     163        packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer);
     164      // note: packet commits suicide here except for the GameState. That is then deleted by a GamestateHandler
     165        bool b = packet->process();
     166        assert(b);
     167      }
     168      if(gamestate.processGamestates())
     169      {
     170        if(!isSynched_)
     171          isSynched_=true;
     172      }
     173      gamestate.cleanup();
    153174    }
    154     ENetEvent *event;
    155     // stop if the packet queue is empty
    156     while(!(client_connection.queueEmpty())){
    157       event = client_connection.getEvent();
    158       COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
    159       packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer);
    160       // note: packet commits suicide here except for the GameState. That is then deleted by a GamestateHandler
    161       bool b = packet->process();
    162       assert(b);
    163     }
    164     if(gamestate.processGamestates())
    165     {
    166       if(!isSynched_)
    167         isSynched_=true;
    168     }
    169     gamestate.cleanup();
     175
    170176    return;
    171177  }
  • code/branches/netp2/src/network/Client.h

    r2773 r2965  
    8888
    8989    bool gameStateFailure_;
     90    float timeSinceLastUpdate_;
    9091  };
    9192
  • code/branches/netp2/src/network/ClientConnection.cc

    r2836 r2965  
    5858
    5959  ClientConnection::ClientConnection(int port, const std::string& address) {
    60     quit=false;
     60    quit_=false;
    6161    server=NULL;
    6262    serverAddress = new ENetAddress();
     
    6767
    6868  ClientConnection::ClientConnection(int port, const char *address) {
    69     quit=false;
     69    quit_=false;
    7070    server=NULL;
    7171    serverAddress = new ENetAddress();
     
    107107
    108108  bool ClientConnection::closeConnection() {
    109     quit=true;
     109    quit_=true;
    110110    //network_threads.join_all();
    111111    receiverThread_->join();
     
    151151      COUT(2) << "ClientConnection: could not create client host" << std::endl;
    152152      // add some error handling here ==========================
    153       quit=true;
     153      quit_=true;
    154154    }
    155155    //connect to the server
    156156    if(!establishConnection()){
    157157      COUT(2) << "clientConn: receiver thread: could not establishConnection" << std::endl;
    158       quit=true;
     158      quit_=true;
    159159      return;
    160160    }
    161161    event = new ENetEvent;
    162162    //main loop
    163     while(!quit){
     163    while(!quit_){
    164164      //std::cout << "connection loop" << std::endl;
    165165      {
     
    167167        if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){
    168168          // we should never reach this point
    169                 assert(0);
    170           quit=true;
    171           continue;
     169//              assert(0);
     170          printf("ClientConnection: ENet returned with an error!\n");
     171          quit_=true;
     172          break;
    172173          // add some error handling here ========================
    173174        }
     
    185186        break;
    186187      case ENET_EVENT_TYPE_DISCONNECT:
    187         quit=true;
     188        quit_=true;
     189        printf("Received disconnect Packet from Server!\n");
    188190        // server closed the connection
    189191        return;
     
    235237    }
    236238    // handshake
    237     while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit){
     239    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit_){
    238240      if( event.type == ENET_EVENT_TYPE_CONNECT ){
    239241        established=true;
  • code/branches/netp2/src/network/ClientConnection.h

    r2836 r2965  
    5454    const int NETWORK_CLIENT_MAX_CONNECTIONS = 5;
    5555    const int NETWORK_CLIENT_WAIT_TIME = 10;
    56     const int NETWORK_CLIENT_CONNECT_TIMEOUT = 10000; // miliseconds
     56    const int NETWORK_CLIENT_CONNECT_TIMEOUT = 3000; // miliseconds
    5757    const int NETWORK_CLIENT_CHANNELS = 2;
    5858
     
    7676    //bool sendPackets(ENetEvent *event);
    7777    bool waitEstablished(int milisec);
    78     bool isConnected(){return established;}
     78    inline bool isConnected(){return established;}
     79    inline bool checkConnection(){ return !quit_ && isConnected(); }
    7980  private:
    8081    ClientConnection(const ClientConnection& copy); // not used
     
    9091    ENetAddress *serverAddress;
    9192    // quit-variable (communication with threads)
    92     bool quit;
     93    bool quit_;
    9394    bool established;
    9495    // clientlist
  • code/branches/netp2/src/network/ConnectionManager.cc

    r2953 r2965  
    7171    assert(instance_==0);
    7272    instance_=this;
    73     quit=false;
     73    quit_=false;
    7474    bindAddress = new ENetAddress();
    7575    bindAddress->host = ENET_HOST_ANY;
     
    8080    assert(instance_==0);
    8181    instance_=this;
    82     quit=false;
     82    quit_=false;
    8383    bindAddress = new ENetAddress();
    8484    bindAddress->host = ENET_HOST_ANY;
     
    8989    assert(instance_==0);
    9090    instance_=this;
    91     quit=false;
     91    quit_=false;
    9292    bindAddress = new ENetAddress();
    9393    enet_address_set_host (bindAddress, address.c_str());
     
    9898    assert(instance_==0);
    9999    instance_=this;
    100     quit=false;
     100    quit_=false;
    101101    bindAddress = new ENetAddress();
    102102    enet_address_set_host (bindAddress, address);
     
    105105
    106106  ConnectionManager::~ConnectionManager(){
    107     if(!quit)
     107    if(!quit_)
    108108      quitListener();
    109109    instance_=0;
     
    129129
    130130  bool ConnectionManager::quitListener() {
    131     quit=true;
     131    quit_=true;
    132132    receiverThread_->join();
    133133    return true;
     
    185185    if(server==NULL){
    186186      // add some error handling here ==========================
    187       quit=true;
     187      quit_=true;
    188188      return;
    189189    }
    190190
    191191    event = new ENetEvent;
    192     while(!quit)
     192    while(!quit_)
    193193    {
    194194      { //mutex scope
     
    196196        if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
    197197          // we should never reach this point
    198           quit=true;
     198          printf("ConnectionManager: ENet returned with an error\n");
     199          quit_=true;
    199200          continue;
    200201          printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh");
  • code/branches/netp2/src/network/ConnectionManager.h

    r2836 r2965  
    8181    void disconnectClient(ClientInformation *client);
    8282    void syncClassid(unsigned int clientID);
     83    bool checkReceiverThread(){ return !quit_; }
    8384
    8485  private:
     
    9596    ENetAddress *bindAddress;
    9697
    97     bool quit; // quit-variable (communication with threads)
     98    bool quit_; // quit-variable (communication with threads)
    9899
    99100    boost::thread *receiverThread_;
  • code/branches/netp2/src/network/Host.h

    r2171 r2965  
    3535
    3636namespace orxonox {
     37
     38  const int CLIENTID_SERVER = 0;
     39  const unsigned int NETWORK_FREQUENCY = 25;
     40  const float NETWORK_PERIOD = 1./NETWORK_FREQUENCY;
    3741
    3842/**
  • code/branches/netp2/src/network/Server.h

    r2662 r2965  
    5151namespace orxonox
    5252{
    53   const int CLIENTID_SERVER = 0;
    54   const unsigned int NETWORK_FREQUENCY = 25;
    55   const float NETWORK_PERIOD = 1./NETWORK_FREQUENCY;
    5653
    5754  /**
Note: See TracChangeset for help on using the changeset viewer.