Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 23, 2009, 6:02:25 PM (15 years ago)
Author:
scheusso
Message:

merged netp5 back to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/Client.cc

    r3198 r3214  
    3939//
    4040
     41#include "Client.h"
     42
    4143#include <cassert>
    42 #include <enet/enet.h>
    4344
    44 #include "Client.h"
    45 #include "Host.h"
     45#include "util/Debug.h"
     46#include "core/Clock.h"
    4647#include "synchronisable/Synchronisable.h"
    47 #include "core/Clock.h"
    48 #include "core/CoreIncludes.h"
    49 #include "packet/Packet.h"
     48#include "packet/Chat.h"
     49#include "packet/Gamestate.h"
    5050#include "FunctionCallManager.h"
    51 
    52 // #include "packet/Acknowledgement.h"
    5351
    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  {
     75      setPort( port );
     76      setServerAddress( address );
    9077  }
    9178
    9279  Client::~Client(){
    93     if(isConnected)
     80    if ( ClientConnection::isConnected() )
    9481      closeConnection();
    9582  }
     
    10188  bool Client::establishConnection(){
    10289    Synchronisable::setClient(true);
    103     isConnected=client_connection.createConnection();
    104     if(!isConnected)
    105       COUT(1) << "could not create connection laber" << std::endl;
    106     return isConnected;
     90    return ClientConnection::establishConnection();
    10791  }
    10892
     
    11296  */
    11397  bool Client::closeConnection(){
    114     isConnected=false;
    115     return client_connection.closeConnection();
     98    return ClientConnection::closeConnection();
    11699  }
    117100
    118101  bool Client::queuePacket(ENetPacket *packet, int clientID){
    119     return client_connection.addPacket(packet);
     102    bool b = ClientConnection::addPacket(packet);
     103    assert(b);
     104    return b;
    120105  }
    121106
     
    143128    //this steers our network frequency
    144129    timeSinceLastUpdate_+=time.getDeltaTime();
    145     if(timeSinceLastUpdate_>=NETWORK_PERIOD){
     130    if(timeSinceLastUpdate_>=NETWORK_PERIOD)
     131    {
    146132      timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
    147133      //     COUT(3) << ".";
    148       if(client_connection.isConnected() && isSynched_){
     134      if ( isConnected() && isSynched_ )
     135      {
    149136        COUT(4) << "popping partial gamestate: " << std::endl;
    150137        packet::Gamestate *gs = gamestate.getGamestate();
     
    159146      }
    160147    }
     148    sendPackets(); // flush the enet queue
    161149   
    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     }
     150    Connection::processQueue();
    173151    if(gamestate.processGamestates())
    174152    {
Note: See TracChangeset for help on using the changeset viewer.