Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 7, 2008, 4:39:42 PM (17 years ago)
Author:
scheusso
Message:

different enhancements in input/network handling and synchronisation

Location:
code/branches/network3/src/network
Files:
13 edited

Legend:

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

    r1233 r1245  
    8484    // set server address to localhost
    8585    isConnected=false;
     86    test_once=false;
    8687  }
    8788
     
    9394  Client::Client(std::string address, int port) : client_connection(port, address){
    9495    isConnected=false;
     96    test_once=false;
    9597  }
    9698
     
    102104  Client::Client(const char *address, int port) : client_connection(port, address){
    103105    isConnected=false;
     106    test_once=false;
    104107  }
    105108
     
    226229  */
    227230  void Client::tick(float time){
     231    if(client_connection.isConnected()){
     232      COUT(4) << "popping partial gamestate: " << std::endl;
     233      GameStateCompressed *gs = gamestate.popPartialGameState();
     234      if(gs){
     235        COUT(4) << "client tick: sending gs " << gs << std::endl;
     236        if(client_connection.addPacket(pck_gen.gstate(gs)))
     237          if(!client_connection.sendPackets())
     238            COUT(3) << "Problem sending partial gamestate" << std::endl;
     239        // now delete it to save memory
     240        delete [] gs->data;
     241        delete gs;
     242      }
     243    }
    228244    ENetPacket *packet;
    229245    // stop if the packet queue is empty
     
    231247      packet = client_connection.getPacket();
    232248      COUT(5) << "tick packet size " << packet->dataLength << std::endl;
    233       elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
     249      if(!test_once){
     250        elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
     251      }
    234252    }
    235253    return;
    236254  }
    237255
    238   void Client::processGamestate( GameStateCompressed *data){
    239     int id = data->id;
    240     COUT(5) << "received gamestate id: " << data->id << std::endl;
    241     if(gamestate.pushGameState(data)){
    242       client_connection.addPacket(pck_gen.acknowledgement(id));
    243       if(!client_connection.sendPackets())
    244         COUT(2) << "Could not send acknowledgment" << std::endl;
     256  void Client::processGamestate( GameStateCompressed *data, int clientID){
     257    if(!test_once){
     258      int id = data->id;
     259      COUT(5) << "received gamestate id: " << data->id << std::endl;
     260      if(gamestate.pushGameState(data)){
     261        client_connection.addPacket(pck_gen.acknowledgement(id));
     262        if(!client_connection.sendPackets())
     263          COUT(2) << "Could not send acknowledgment" << std::endl;
     264      }
     265//       test_once=true;
    245266    }
    246267  }
     
    263284    clientID_ = w->clientID;
    264285    shipID_ = w->shipID;
    265    
     286    return true;
    266287  }
    267288
  • code/branches/network3/src/network/Client.h

    r1232 r1245  
    103103
    104104    // implement data processing functions of PacketDecoder
    105     void processGamestate( GameStateCompressed *data);
     105    void processGamestate( GameStateCompressed *data, int clientID);
    106106    void processClassid(classid *clid);
    107107    void processChat( chat *data);
     
    109109    int clientID_;     // this is the id the server gave to us
    110110    int shipID_;
     111    bool test_once;
    111112  };
    112113
  • code/branches/network3/src/network/ClientConnection.h

    r1168 r1245  
    7676    bool sendPackets(ENetEvent *event);
    7777    bool waitEstablished(int milisec);
     78    bool isConnected(){return established;}
    7879  private:
    7980    bool processData(ENetEvent *event);
  • code/branches/network3/src/network/ConnectionManager.cc

    r1234 r1245  
    165165    enet_initialize();
    166166    atexit(enet_deinitialize);
    167     ENetEvent event;
     167    ENetEvent *event = new ENetEvent;
    168168    server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
    169169    if(server==NULL){
     
    174174
    175175    while(!quit){
    176       if(enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT)<0){
     176      if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
    177177        // we should never reach this point
    178178        quit=true;
    179179        // add some error handling here ========================
    180180      }
    181       switch(event.type){
     181      switch(event->type){
    182182        // log handling ================
    183183        case ENET_EVENT_TYPE_CONNECT:
    184           addClient(&event);
     184          addClient(event);
    185185          //this is a workaround to ensure thread safety
    186186          /*if(!addFakeConnectRequest(&event))
     
    191191          //std::cout << "received data" << std::endl;
    192192          COUT(5) << "Con.Man: receive event has occured" << std::endl;
    193           processData(&event);
     193          processData(event);
    194194          break;
    195195        case ENET_EVENT_TYPE_DISCONNECT:
    196           // add some error/log handling here
    197           clientDisconnect(event.peer);
     196          clientDisconnect(event->peer);
    198197          break;
    199198        case ENET_EVENT_TYPE_NONE:
    200199          break;
    201200      }
     201//       usleep(1000);
     202      //yield(); //TODO: find apropriate
    202203    }
    203204    disconnectClients();
     
    246247  bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
    247248    COUT(4) << "removing client from list" << std::endl;
    248     return head_->removeClient(peer);
     249    return removeClient(head_->findClient(&(peer->address))->getID());
    249250  }
    250251/**
     
    311312    sendWelcome(temp->getID(), temp->getShipID(), true);
    312313    return true;
     314  }
     315 
     316  bool ConnectionManager::removeClient(int clientID){
     317    orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
     318    while(it){
     319      if(it->objectID!=head_->findClient(clientID)->getShipID()){
     320        ++it;
     321        continue;
     322      }
     323      orxonox::Iterator<orxonox::SpaceShip> temp=it;
     324      ++it;
     325      delete  *temp;
     326      return head_->removeClient(clientID);
     327    }
     328    return false;
    313329  }
    314330 
     
    335351   
    336352    client->setShipID(no->objectID);
    337     no->getFocus();
    338353    return true;
    339354  }
     
    342357    addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID);
    343358    sendPackets();
     359    return true;
    344360  }
    345361 
  • code/branches/network3/src/network/ConnectionManager.h

    r1232 r1245  
    8989  private:
    9090    bool clientDisconnect(ENetPeer *peer);
     91    bool removeClient(int clientID);
    9192    bool processData(ENetEvent *event);
    9293    bool addClient(ENetEvent *event);
  • code/branches/network3/src/network/GameStateClient.cc

    r1232 r1245  
    166166
    167167  GameState *GameStateClient::getPartialSnapshot(){
     168   
     169    GameState *reference;
     170//     std::map<int, GameState*>::iterator it = --gameStateMap.end();
     171//     reference=(--gameStateMap.end())->second;
     172   
    168173    //std::cout << "begin getSnapshot" << std::endl;
    169174    //the size of the gamestate
     
    178183
    179184    GameState *retval=new GameState; //return value
    180     retval->id=reference->id;
     185//     retval->id=reference->id;
     186    if(gameStateMap.size()!=0)
     187      retval->id=(--gameStateMap.end())->second->id;
    181188    retval->diffed=false;
    182189    retval->complete=false;
     
    190197      size+=it->getSize(); // size of the actual data of the synchronisable
    191198      size+=3*sizeof(int); // size of datasize, classID and objectID
     199      COUT(4) << "getpartialsnapshot: size: " << size << std::endl;
    192200    }
    193201    //retval->data = (unsigned char*)malloc(size);
  • code/branches/network3/src/network/GameStateClient.h

    r1232 r1245  
    7070    void printGameStateMap();
    7171
    72     GameState     *reference;
    7372    int           last_diff_;
    7473    std::map<int, GameState *> gameStateMap;
  • code/branches/network3/src/network/GameStateManager.cc

    r1233 r1245  
    106106    if(gID != GAMESTATEID_INITIAL){
    107107      // TODO something with the gamestatemap is wrong
    108       GameState *client = gameStateMap.find(gID)->second;
     108      GameState *client=NULL;
     109      std::map<int, GameState*>::iterator it = gameStateMap.find(gID);
     110      if(it!=gameStateMap.end())
     111        client = it->second;
    109112      GameState *server = reference;
    110113      //head_->findClient(clientID)->setGamestateID(id);
     
    203206
    204207  bool GameStateManager::loadPartialSnapshot(GameState *state, int clientID){
     208    if(!state)
     209      return false;
    205210    unsigned char *data=state->data;
    206211    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
     
    219224      sync.data = data;
    220225      data+=sync.length;
    221 
     226      COUT(4) << "objectID: " << sync.objectID << " classID: " << sync.classID << std::endl;
    222227      while(it && it->objectID!=sync.objectID)
    223228        ++it;
     
    226231      if(!it){
    227232        // the object does not exist yet
     233        COUT(4) << "loadsnapshot: creating new object " << std::endl;
    228234        //COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
    229235        orxonox::Identifier* id = ID((unsigned int)sync.classID);
     
    244250      }else{
    245251        // we have our object
     252        COUT(4) << "loadpartialsnapshot: we found the appropriate object" << std::endl;
    246253        if(checkAccess(clientID, sync.objectID)){
    247254          if(! it->updateData(sync))
     
    396403    //std::cout << "length " << length << std::endl;
    397404    switch ( retval ) {
    398       case Z_OK: COUT(4) << "successfully decompressed" << std::endl; break;
     405      case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break;
    399406      case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL;
    400407      case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL;
     
    444451  bool GameStateManager::checkAccess(int clientID, int objectID){
    445452    // currently we only check, wheter the object is the clients spaceship
    446     return head_->findClient(objectID)->getShipID()==objectID;
     453//     return head_->findClient(objectID)->getShipID()==objectID;
     454    return true; // TODO: change this
    447455  }
    448456
  • code/branches/network3/src/network/PacketDecoder.cc

    r1233 r1245  
    7878      return true;
    7979    case GAMESTATE:
    80       gstate( packet );
     80      gstate( packet, clientId );
    8181      return true;
    8282    case CLASSID:
     
    155155  }
    156156
    157   void PacketDecoder::gstate( ENetPacket* packet )
     157  void PacketDecoder::gstate( ENetPacket* packet, int clientID )
    158158  {
    159159    GameStateCompressed* currentState = NULL;
     
    190190    //clean memory
    191191    enet_packet_destroy( packet );
    192     processGamestate(currentState);
     192    processGamestate(currentState, clientID);
    193193  }
    194194
     
    234234  }
    235235
    236   void PacketDecoder::processGamestate( GameStateCompressed *state )
     236  void PacketDecoder::processGamestate( GameStateCompressed *state, int clientID )
    237237  {
    238238    COUT(5) << "PacketDecoder: processing Gamestate" << std::endl;
  • code/branches/network3/src/network/PacketManager.h

    r1232 r1245  
    9191    void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
    9292    void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
    93     void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT);
    94     void gstate( ENetPacket* packet );
     93    void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
     94    void gstate( ENetPacket* packet, int clientID = CLIENTID_CLIENT );
    9595    void clid( ENetPacket *packet);
    9696    bool decodeWelcome( ENetPacket* packet, int clientID = CLIENTID_CLIENT );
     
    9999    //process data
    100100    //two functions are note yet implemented!
    101     virtual void processGamestate(GameStateCompressed *state);
     101    virtual void processGamestate(GameStateCompressed *state, int clientID);
    102102    virtual void processAck( ack *data, int clientID);
    103103    virtual void processClassid( classid *cid);
  • code/branches/network3/src/network/Server.cc

    r1232 r1245  
    143143    updateGamestate();
    144144
    145     usleep(200000); // TODO remove
     145//     usleep(500000); // TODO remove
    146146    return;
    147147  }
     
    228228    //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
    229229    connection->createClient(clientID);
     230    return true;
     231  }
     232 
     233  void Server::processGamestate( GameStateCompressed *data, int clientID){
     234    COUT(4) << "processing partial gamestate from client " << clientID << std::endl;
     235    if(!gamestates->pushGameState(data, clientID))
     236        COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
     237//     delete[] data->data;
     238//     delete data;
    230239  }
    231240
  • code/branches/network3/src/network/Server.h

    r1232 r1245  
    7474    void processAck( ack *data, int clientID);
    7575    bool processConnectRequest( connectRequest *con, int clientID );
     76    void processGamestate( GameStateCompressed *data, int clientID);
    7677    ConnectionManager *connection;
    7778    GameStateManager *gamestates;
  • code/branches/network3/src/network/Synchronisable.cc

    r1232 r1245  
    5050 
    5151 
    52   int Synchronisable::state_=1; // detemines wheter we are server (default) or client
     52  int Synchronisable::state_=0x1; // detemines wheter we are server (default) or client
    5353 
    5454  /**
     
    165165    for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){
    166166      //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
    167       if( ((*i)->mode & state_) == 0 )
     167      if( ((*i)->mode & state_) == 0 ){
     168        COUT(4) << "not getting data: " << std::endl;
    168169        continue;  // this variable should only be received
     170      }
    169171      switch((*i)->type){
    170172      case DATA:
     
    199201    COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl;
    200202    for(i=syncList->begin(); i!=syncList->end(); i++){
    201       if( ((*i)->mode ^ state_) == 0 )
    202         continue;  // this variable should only be sent
     203      if( ((*i)->mode ^ state_) == 0 ){
     204        COUT(5) << "synchronisable: not updating variable " << std::endl;
     205        continue;  // this variable should only be updated
     206      }
    203207      COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
    204208      switch((*i)->type){
Note: See TracChangeset for help on using the changeset viewer.