Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 21, 2009, 12:27:19 AM (15 years ago)
Author:
scheusso
Message:

rest of the cleanup ( mostly client connection handling)
network is now single-threaded ( only in order to become multithreaded again, but thats another story ;) )

File:
1 edited

Legend:

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

    r3198 r3202  
    5050#include "FunctionCallManager.h"
    5151
    52 // #include "packet/Acknowledgement.h"
    53 
    5452namespace orxonox
    5553{
    56 //   SetConsoleCommandShortcut(Client, chat);
    5754
    5855
     
    6158  * initializes the address and the port to default localhost:NETWORK_PORT
    6259  */
    63   Client::Client(): client_connection(NETWORK_PORT,"127.0.0.1"){
    64     // set server address to localhost
    65     isConnected=false;
    66     isSynched_=false;
    67     gameStateFailure_=false;
     60  Client::Client():
     61      isSynched_(false),
     62      gameStateFailure_(false)
     63  {
    6864  }
    6965
     
    7369  * @param port port of the application on the server
    7470  */
    75   Client::Client(const std::string& address, int port) : client_connection(port, address){
    76     isConnected=false;
    77     isSynched_=false;
    78     gameStateFailure_=false;
    79   }
    80 
    81   /**
    82   * Constructor for the Client class
    83   * @param address the server address
    84   * @param port port of the application on the server
    85   */
    86   Client::Client(const char *address, int port) : client_connection(port, address){
    87     isConnected=false;
    88     isSynched_=false;
    89     gameStateFailure_=false;
     71  Client::Client(const std::string& address, int port):
     72      isSynched_(false),
     73      gameStateFailure_(false)
     74  {
    9075  }
    9176
    9277  Client::~Client(){
    93     if(isConnected)
     78    if ( ClientConnection::isConnected() )
    9479      closeConnection();
    9580  }
     
    10186  bool Client::establishConnection(){
    10287    Synchronisable::setClient(true);
    103     isConnected=client_connection.createConnection();
    104     if(!isConnected)
    105       COUT(1) << "could not create connection laber" << std::endl;
    106     return isConnected;
     88    return ClientConnection::establishConnection();
    10789  }
    10890
     
    11294  */
    11395  bool Client::closeConnection(){
    114     isConnected=false;
    115     return client_connection.closeConnection();
     96    return ClientConnection::closeConnection();
    11697  }
    11798
    11899  bool Client::queuePacket(ENetPacket *packet, int clientID){
    119     return client_connection.addPacket(packet);
     100    bool b = ClientConnection::addPacket(packet);
     101    assert(b);
     102    return b;
    120103  }
    121104
     
    143126    //this steers our network frequency
    144127    timeSinceLastUpdate_+=time.getDeltaTime();
    145     if(timeSinceLastUpdate_>=NETWORK_PERIOD){
     128    if(timeSinceLastUpdate_>=NETWORK_PERIOD)
     129    {
    146130      timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
    147131      //     COUT(3) << ".";
    148       if(client_connection.isConnected() && isSynched_){
     132      if ( isConnected() && isSynched_ )
     133      {
    149134        COUT(4) << "popping partial gamestate: " << std::endl;
    150135        packet::Gamestate *gs = gamestate.getGamestate();
     
    159144      }
    160145    }
     146    sendPackets(); // flush the enet queue
    161147   
    162     ENetEvent *event;
    163     // stop if the packet queue is empty
    164     while(!(client_connection.queueEmpty())){
    165       event = client_connection.getEvent();
    166       COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
    167       packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer);
    168       // note: packet commits suicide here except for the GameState. That is then deleted by a GamestateHandler
    169       bool b = packet->process();
    170       assert(b);
    171       delete event;
    172     }
     148    Connection::processQueue();
    173149    if(gamestate.processGamestates())
    174150    {
Note: See TracChangeset for help on using the changeset viewer.