Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 9, 2008, 4:35:38 AM (16 years ago)
Author:
landauf
Message:

big change in ObjectList: separated the class into a non-template base and a template wrapper for the base. this also changes the Iterator, there is now a non-template IteratorBase. this brings much more flexibility, like iterating through all objects of a given identifier without knowing the type. however this needs a dynamic_cast, which isn't quite optimal, but I think there are much worser things than that out there. ;)

there isn't much you have to know about this, except there is no more ObjectList<myClass>::start() function but a ObjectList<myClass>::begin() to be more STLish. another thing: ObjectList<myClass>::end() points now to the element _after_ the last element, so it's possible to iterate in a for-loop until (it != ObjectList<myClass>::end()). the reason is the same as above. however, (it) as a boolean still works perfectly fine.

Location:
code/branches/core3/src/network
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/network/ConnectionManager.cc

    r1534 r1574  
    6464{
    6565  //boost::thread_group network_threads;
    66  
     66
    6767  ConnectionManager::ConnectionManager():receiverThread_(0){}
    6868  boost::recursive_mutex ConnectionManager::enet_mutex_;
    69  
     69
    7070  ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) {
    7171    quit=false;
     
    7474    head_ = head;
    7575  }
    76  
     76
    7777  ConnectionManager::ConnectionManager(ClientInformation *head, int port){
    7878    quit=false;
     
    115115    return packet;
    116116  }*/
    117  
     117
    118118  ENetEvent *ConnectionManager::getEvent(){
    119119    if(!buffer.isEmpty())
     
    251251    }
    252252  }
    253  
     253
    254254  //### added some bugfixes here, but we cannot test them because
    255255  //### the server crashes everytime because of some gamestates
     
    333333  }
    334334
    335  
    336  
     335
     336
    337337  bool ConnectionManager::removeShip(ClientInformation *client){
    338338    int id=client->getShipID();
    339339    orxonox::Iterator<orxonox::SpaceShip> it;
    340     for(it = orxonox::ObjectList<orxonox::SpaceShip>::start(); it; ++it){
     340    for(it = orxonox::ObjectList<orxonox::SpaceShip>::begin(); it; ++it){
    341341      if(it->objectID!=id)
    342342        continue;
     
    345345    return true;
    346346  }
    347  
     347
    348348  bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
    349349    if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){
     
    353353      return false;
    354354  }
    355  
     355
    356356  void ConnectionManager::disconnectClient(ClientInformation *client){
    357357    {
     
    362362    removeShip(client);
    363363  }
    364  
     364
    365365  bool ConnectionManager::addFakeConnectRequest(ENetEvent *ev){
    366366    ENetEvent event;
     
    369369    return buffer.push(&event);
    370370  }
    371  
    372  
     371
     372
    373373
    374374}
  • code/branches/core3/src/network/GameStateClient.cc

    r1534 r1574  
    151151    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
    152152    // get the start of the Synchronisable list
    153     orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
     153    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::begin();
    154154    syncData sync;
    155155    // loop as long as we have some data ;)
     
    236236    int offset=0, size=0;
    237237    // get total size of gamestate
    238     for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     238    for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
    239239      if(!it->getBacksync())
    240240        continue;
     
    253253    memsize=size;
    254254    // go through all Synchronisables
    255     for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     255    for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
    256256      if(!it->getBacksync())
    257257        continue;
  • code/branches/core3/src/network/GameStateManager.cc

    r1534 r1574  
    7070    return;
    7171  }
    72  
     72
    7373  void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){
    7474    if(!gs)
     
    8383    return;
    8484  }
    85  
     85
    8686  void GameStateManager::processGameStates(){
    8787    std::map<int, GameStateCompressed*>::iterator it;
     
    9393    gameStateQueue.clear();
    9494  }
    95  
    96  
     95
     96
    9797  /**
    9898   * this function is used to keep the memory usage low
    9999   * it tries to delete all the unused gamestates
    100    * 
    101    * 
     100   *
     101   *
    102102   */
    103103  void GameStateManager::cleanup(){
     
    155155    }
    156156  }
    157  
     157
    158158  bool GameStateManager::pushGameState( GameStateCompressed *gs, int clientID ){
    159159    GameState *ugs = decompress(gs);
     
    190190    int offset=0, size=0;
    191191    // get total size of gamestate
    192     for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     192    for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
    193193      size+=it->getSize(); // size of the actual data of the synchronisable
    194194      size+=3*sizeof(int); // size of datasize, classID and objectID
     
    204204    memsize=size;
    205205    // go through all Synchronisables
    206     for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     206    for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
    207207      //get size of the synchronisable
    208208      tempsize=it->getSize();
     
    246246    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
    247247    // get the start of the Synchronisable list
    248     orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
     248    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::begin();
    249249    syncData sync;
    250250    /*ClientInformation *client = head_->findClient(clientID);
     
    308308    return true;
    309309  }
    310  
    311  
     310
     311
    312312  //##### ADDED FOR TESTING PURPOSE #####
    313313  GameStateCompressed* GameStateManager::testCompress( GameState* g ) {
     
    405405    switch ( retval ) {
    406406      case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
    407       case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 
     407      case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl;
    408408      return NULL;
    409409      case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
     
    426426    return compressedGamestate;
    427427  }
    428  
     428
    429429  GameState *GameStateManager::decompress(GameStateCompressed *a) {
    430430    //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
     
    464464    return gamestate;
    465465  }
    466  
     466
    467467
    468468  void GameStateManager::ackGameState(int clientID, int gamestateID) {
     
    471471      return;
    472472    int curid = temp->getGamestateID();
    473    
     473
    474474    if(gamestateID == GAMESTATEID_INITIAL){
    475475      temp->setGameStateID(GAMESTATEID_INITIAL);
     
    481481    }
    482482    if(curid > gamestateID)
    483       // the network packets got messed up 
     483      // the network packets got messed up
    484484      return;
    485485    COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
     
    512512    return true;
    513513  }
    514  
     514
    515515  bool GameStateManager::checkAccess(int clientID, int objectID){
    516516    // currently we only check, wheter the object is the clients spaceship
     
    518518    return true; // TODO: change this
    519519  }
    520  
     520
    521521  void GameStateManager::removeClient(ClientInformation* client){
    522522    if(!client)
  • code/branches/core3/src/network/Server.cc

    r1556 r1574  
    5757  #define MAX_FAILURES 20;
    5858  #define NETWORK_FREQUENCY 30
    59  
     59
    6060  Server *Server::instance_=0;
    61  
     61
    6262  Server *Server::createSingleton(){
    6363    if(!instance_)
     
    8080    return instance_;
    8181  }
    82  
     82
    8383  Server *Server::getSingleton(){
    8484    return instance_;
    8585  }
    86  
    87  
     86
     87
    8888  /**
    8989  * Constructor for default values (bindaddress is set to ENET_HOST_ANY
     
    9797    gamestates = new GameStateManager(clients);
    9898  }
    99  
     99
    100100  Server::Server(int port){
    101101    timeSinceLastUpdate_=0;
     
    217217        if(clients->findClient(&event->peer->address)){
    218218          clientID = clients->findClient(&event->peer->address)->getID();
    219           if( !elaborate(event->packet, clientID) ) 
     219          if( !elaborate(event->packet, clientID) )
    220220            COUT(3) << "Server: could not elaborate" << std::endl;
    221221        }
     
    276276        continue;
    277277      if ( !(connection->addPacket(packet, cid)) ){
    278         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 
     278        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
    279279        temp->addFailure();
    280280        /*if(temp->getFailures() > 0 )
     
    302302    delete data;
    303303  }
    304  
     304
    305305  bool Server::processConnectRequest( connectRequest *con, int clientID ){
    306306    //(COUT(3) << "processing connectRequest " << std::endl;
     
    310310    return true;
    311311  }
    312  
     312
    313313  void Server::processGamestate( GameStateCompressed *data, int clientID){
    314314    COUT(4) << "processing partial gamestate from client " << clientID << std::endl;
     
    319319        clients->findClient(clientID)->resetFailures();*/
    320320  }
    321  
     321
    322322  void Server::processChat( chat *data, int clientId){
    323323    char *message = new char [strlen(data->message)+10+1];
     
    329329    delete data;
    330330  }
    331  
     331
    332332  bool Server::addClient(ENetEvent *event){
    333333    ClientInformation *temp = clients->insertBack(new ClientInformation);
     
    346346    return createClient(temp->getID());
    347347  }
    348  
     348
    349349  bool Server::createClient(int clientID){
    350350    ClientInformation *temp = clients->findClient(clientID);
     
    366366    return true;
    367367  }
    368  
     368
    369369  bool Server::createShip(ClientInformation *client){
    370370    if(!client)
     
    390390    no->classID = id->getNetworkID();
    391391    no->create();
    392    
     392
    393393    client->setShipID(no->objectID);
    394394    return true;
    395395  }
    396  
     396
    397397  bool Server::disconnectClient(ENetEvent *event){
    398398    COUT(4) << "removing client from list" << std::endl;
    399399    //return removeClient(head_->findClient(&(peer->address))->getID());
    400    
     400
    401401    //boost::recursive_mutex::scoped_lock lock(head_->mutex_);
    402     orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
     402    orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::begin();
    403403    ClientInformation *client = clients->findClient(&event->peer->address);
    404404    if(!client)
     
    426426    gamestates->removeClient(client);
    427427  }
    428  
     428
    429429}
Note: See TracChangeset for help on using the changeset viewer.