Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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)

File:
1 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  }
Note: See TracChangeset for help on using the changeset viewer.