Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 23, 2008, 11:34:35 PM (17 years ago)
Author:
rgrieder
Message:

Merged revisions 2384-2436 from presentation branch to bugger.

Location:
code/branches/bugger
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • code/branches/bugger

  • code/branches/bugger/src/network/NetworkPrereqs.h

    r2531 r2533  
    6161#include "util/Integers.h"
    6262
     63//-----------------------------------------------------------------------
     64// Library global contants
     65//-----------------------------------------------------------------------
     66namespace orxonox
     67{
     68  static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
     69  static const unsigned int CLIENTID_UNKNOWN    = (unsigned int)-2;
     70  static const uint32_t     OBJECTID_UNKNOWN    = (uint32_t)(-1);
     71}
    6372
    6473//-----------------------------------------------------------------------
     
    6776namespace orxonox
    6877{
    69 
    70 // Constants definition
    71 
    72   static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
    73   static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2;
    74   static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1);
    75   static const unsigned int SCHED_PRIORITY_OFFSET = -5;
    76 
    77  
    78 
    79  
    8078  class Client;
    8179  class ClientConnection;
     
    103101  class obj;
    104102  class objInfo;
    105   namespace packet{
     103
     104  namespace packet
     105  {
    106106    class Gamestate;
    107107    class Packet;
  • code/branches/bugger/src/network/Server.cc

    r2171 r2533  
    6363{
    6464  const unsigned int MAX_FAILURES = 20;
    65   const unsigned int NETWORK_FREQUENCY = 25;
    66   const float NETWORK_PERIOD = (float)1/NETWORK_FREQUENCY;
    6765
    6866  /**
  • code/branches/bugger/src/network/Server.h

    r2171 r2533  
    5252{
    5353  const int CLIENTID_SERVER = 0;
     54  const unsigned int NETWORK_FREQUENCY = 25;
     55  const float NETWORK_PERIOD = 1./NETWORK_FREQUENCY;
    5456
    5557  /**
  • code/branches/bugger/src/network/TrafficControl.cc

    • Property svn:eol-style set to native
    r2532 r2533  
    3636
    3737namespace orxonox {
     38 
     39  static const unsigned int SCHED_PRIORITY_OFFSET = -1;
    3840
    3941  objInfo::objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched)
     
    6870        TrafficControl::TrafficControl()
    6971        {
    70     RegisterRootObject(TrafficControl);
     72    RegisterObject(TrafficControl);
    7173          assert(instance_==0);
    7274          instance_=this;
    73 //     targetSize = 2500;//5000bytes
    74     SetConfigValue ( targetSize, 28000./25. );
     75    this->setConfigValues();
    7576        }
    7677       
     
    7980        */
    8081        TrafficControl::~TrafficControl()
    81         {
    82           //was macht das genau? da instance ja gleich this ist im moment
     82        {
    8383          instance_=0;
    84           //muss ich alles deallozieren was ich im constructor aufgebaut habe?
    8584        }
    8685
     
    8988*/
    9089
     90  void TrafficControl::setConfigValues()
     91  {
     92    SetConfigValue ( bActive_, true );
     93    SetConfigValue ( targetSize, 5000 );
     94  }
     95 
    9196  /**
    92           *eigener sortieralgorithmus
     97  * sort-algorithm for sorting the objectlist after priorities
    9398  */
    94 //   bool TrafficControl::priodiffer(obj i, obj j)
    95 //   {
    96 //     std::map<unsigned int, objInfo>::iterator iti;
    97 //     std::map<unsigned int, objInfo>::iterator itj;
    98 //     iti=listToProcess_.find(i.objID);
    99 //     itj=listToProcess_.find(j.objID);
    100 //     return iti->second.objValuePerm < itj->second.objValuePerm;
    101 //   }
    102  
    103   /**
    104   * eigener sortieralgorithmus
    105   */
    106   bool TrafficControl::priodiffer(uint32_t clientID, obj i, obj j)
     99  bool TrafficControl::prioritySort(uint32_t clientID, obj i, obj j)
    107100  {
    108101    assert(clientListPerm_.find(clientID) != clientListPerm_.end());  //make sure the client exists in our list
     
    112105    int prio1 = clientListPerm_[clientID][i.objID].objValuePerm + clientListPerm_[clientID][i.objID].objValueSched;
    113106    int prio2 = clientListPerm_[clientID][j.objID].objValuePerm + clientListPerm_[clientID][j.objID].objValueSched;
    114 //     int prio1 = clientListPerm_[clientID][i.objID].objID;
    115 //     int prio2 = clientListPerm_[clientID][j.objID].objID;
    116     // NOTE: smaller priority is better
    117107    return prio1 < prio2;
    118108  }
    119109
     110  /**
     111  * sort-algorithm for sorting the objectList after position in original data stream
     112  */
     113  bool TrafficControl::dataSort(obj i, obj j)
     114  {
     115    int pos1 = i.objDataOffset;
     116    int pos2 = j.objDataOffset;
     117    return pos1 < pos2;
     118  }
     119
     120 
    120121
    121122        void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj> *list)
     
    125126          currentGamestateID=gamestateID;
    126127          evaluateList(clientID, list);
    127           //list hatte vorher ja vielmehr elemente, nach zuweisung nicht mehr... speicherplatz??
    128 //        *list=copiedVector;
    129     //später wird copiedVector ja überschrieben, ist das ein problem für list-dh. für gamestatemanager?
    130128          return;
    131129        }
     
    169167*Definition of private members
    170168*/
    171        
    172        
    173         /**
    174         *copyList gets list of Gamestate Manager and turns it to *listToProcess
    175         */
    176 //      void TrafficControl::copyList(std::list<obj> *list)
    177 //      {
    178 //        std::list<obj>::iterator itvec;
    179 //        for(itvec = (*list).begin(); itvec != (*list).end(); itvec++)
    180 //        {
    181 //          objInfo objectA;
    182 //          objectA.objCreatorID=(*itvec).objCreatorID;
    183 //          objectA.objSize = (*itvec).objSize;
    184 //          listToProcess_.insert(std::pair<currentClientID, map<(*itvec).objID,objectA>>);//unsicher: ob map<...> so richtig ist
    185 //        }
    186 //      }
    187         /**
    188         *updateReferenceList compares the sent list by GSmanager with the current *reference list and updates it.
    189         *returns void
    190         */
    191 //      void TrafficControl::updateReferenceList(std::map<unsigned int, objInfo> *list)
    192 //      {
    193 //        std::map<unsigned int, Synchronisable*>::iterator itref;
    194 //        std::map<unsigned int, objInfo>::iterator itproc;
    195 //        for(itproc=listToProcess_.begin(); itproc != listToProcess_.end(); itproc++)
    196 //        {
    197 //          //itproc->first=objectid that is looked for
    198 //          if(referenceList_->find(itproc->first))
    199 //          {
    200 //            continue;
    201 //          }
    202 //          else
    203 //          {
    204 //            (*referenceList_).insert(pair<unsigned int,          Synchronisable*>((*itproc).first,Synchronisable::getSynchronisable((*itproc).first)));//important: how to get adress of an object!
    205 //            insertinClientListPerm(currentClientID,itproc->first,itproc->second);
    206 //          }
    207 //        }
    208 //      }
     169
    209170        /**
    210171        *updateClientListPerm
     
    229190  {
    230191    clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(*list);
    231 //     std::list<obj>::iterator itvec;
    232 //     std::map<unsigned int,std::map<unsigned int, obj> >::iterator ittemp;
    233 //     std::map<unsigned int, obj>::iterator ittempgs;
    234 //     ittemp = clientListTemp_.find(currentClientID);
    235 //     ittempgs = (*ittemp).find(currentGamestateID);
    236 //     for(itvec = list.begin(); itvec!=list.end(), itvec++)
    237 //     {
    238 //       ittempgs.insert(itvec);static
    239 //     }
    240192  }
    241193
     
    252204    {
    253205      assert( (*itvec).objSize < 1000);
    254 //       COUT(0) << "==targetsize==  " << targetsize << endl;
    255206      if ( ( size + (*itvec).objSize ) < targetsize )
    256207      {
    257 //         COUT(0) << "no cut" << endl;
    258208        size += (*itvec).objSize;//objSize is given in bytes
    259209        ++itvec;
     
    261211      else
    262212      {
    263 //         COUT(0) << "cut" << endl;
    264213        clientListPerm_[currentClientID][(*itvec).objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative
    265 //         ittemp = itvec;
    266214        list->erase(itvec++);
    267 //         itvec = ittemp;
    268215      }
    269216//       printList(list, currentClientID);
     
    278225        void TrafficControl::evaluateList(unsigned int clientID, std::list<obj> *list)
    279226        {
    280           //copyList(list);
    281227       
    282228          //now the sorting
     
    284230          //compare listToProcess vs clientListPerm
    285231    //if listToProcess contains new Objects, add them to clientListPerm
    286 //        std::map<unsigned int, objInfo>::iterator itproc;
    287232    std::list<obj>::iterator itvec;
    288 //        std::map<unsigned int, std::map<unsigned int, objInfo> >::iterator itperm;
    289 //        std::map<unsigned int, objInfo>::iterator itpermobj;
    290233          for( itvec=list->begin(); itvec != list->end(); itvec++)
    291234          {
    292 //          itperm = clientListPerm_.find(clientID);
    293235            if ( clientListPerm_[clientID].find( (*itvec).objID) != clientListPerm_[clientID].end() )
    294236      {
     
    296238        //obj bleibt in liste und permanente prio wird berechnet
    297239        clientListPerm_[clientID][(*itvec).objID].objDiffGS = currentGamestateID - clientListPerm_[clientID][(*itvec).objID].objCurGS;
    298 //         ((*itpermobj).second).objDiffGS = ((*itpermobj).second).objCurGS - currentGamestateID;
    299 //         permprio = clientListPerm_[clientID][(*itproc).first].objValuePerm;
    300 //         itpermprio = (permObjPrio_).find((*itproc).first);
    301 //         ((*itpermobj).second).objValuePerm = ((*itpermobj).second).objDiffGS * (*itpermprio).second;
    302240        continue;//check next objId
    303241      }
     
    306244        // insert the object into clientListPerm
    307245        insertinClientListPerm(clientID,*itvec);
    308 //         itpermobj=(*itperm).find((*itproc).first)
    309 //         ((*itpermobj).second).objDiffGS = ((*itpermobj).second).objCurGS - currentGamestateID;
    310 //         itpermprio = (permObjPrio_).find((*itproc).first);
    311 //         ((*itpermobj).second).objValuePerm = ((*itpermobj).second).objDiffGS * (*itpermprio).second;
    312246        continue;//check next objId
    313247      }
    314248    }
    315249          //end compare listToProcess vs clientListPerm
    316        
    317     //listToProc vs clientListTemp
    318     //TODO: uncomment it again and change some things
    319     /*
    320     std::map<unsigned int, std::map<unsigned int, unsigned int> >::iterator ittemp;
    321     std::map<unsigned int, unsigned int>::iterator ittempgs;
    322     for( itproc=listToProcess_.begin(); itproc != listToProcess_.end();itproc++)
     250   
     251    if( bActive_ )
    323252    {
    324       ittemp = clientListTemp_->find(currentClientID);
    325       if( ittempgs = (*ittemp).find(currentGamestateID))
    326       {
    327         if((*itproc).first == (*ittempgs).find((*itproc).first))//ja, dann ist objekt schon in der zu sendenden liste-muss nicht nochmal gesendet werden
    328         {
    329           (listToProcess_).erase (itproc);
    330         }
    331         else
    332           continue;
    333       }
    334       else
    335         continue;
    336     }*/
    337     //end listToProc vs clientListTemp
    338    
    339     //TODO: check whether we need this, cause i don't think so.
    340     //listToProcess contains obj to send now, and since we give gsmanager the copiedlist and not listToProcess shorten copiedlist therefor too.
    341     /*std::list<obj>::iterator itvec;
    342     for(itvec = copiedVector.begin(); itvec != copiedVector.end(); itvec++)
    343     {
    344       if ( listToProcess_.find(itvec->objID) )
    345       {
    346         continue;//therefore object wasnt thrown out yet and has to be sent back to gsmanager
    347       }
    348       else
    349       {
    350         copiedVector.remove(itvec);
    351       }
    352     }*/
    353     //sort copied list aufgrund der objprioperm in clientlistperm
    354     // use boost bind here because we need to pass a memberfunction to stl sort
    355     list->sort(boost::bind(&TrafficControl::priodiffer, this, clientID, _1, _2) );
    356    
    357     //now we check, that the creator of an object always exists on a client
    358 //     printList(list, clientID);
    359     std::list<obj>::iterator itcreator;
    360     for(itvec = list->begin(); itvec != list->end(); itvec++)
    361     {
    362       fixCreatorDependencies(itvec, list, clientID);
     253      //sort copied list according to priorities
     254      // use boost bind here because we need to pass a memberfunction to stl sort
     255      list->sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
     256     
     257      //now we check, that the creator of an object always exists on a client
     258      std::list<obj>::iterator itcreator;
     259      for(itvec = list->begin(); itvec != list->end(); itvec++)
     260      {
     261        fixCreatorDependencies(itvec, list, clientID);
     262      }
     263      //end of sorting
     264      //now the cutting, work the same obj out in processobjectlist and copiedlist, compression rate muss noch festgelegt werden.
     265//       printList(list, clientID);
     266      cut(list, targetSize);
     267     
     268      //now sort again after objDataOffset
     269      list->sort(boost::bind(&TrafficControl::dataSort, this, _1, _2) );
    363270    }
    364     //end of sorting
    365     //now the cutting, work the same obj out in processobjectlist and copiedlist, compression rate muss noch festgelegt werden.
    366     cut(list, targetSize);
    367 //     printList(list, clientID);
    368271    //diese Funktion updateClientList muss noch gemacht werden
    369272    updateClientListTemp(list);
     
    398301    }
    399302  }
    400 
    401 
    402 /*
    403 void bvlabla(list *a){
    404 //sort a
    405 list *cache;
    406 cache = new list<unsigned int>(*a);
    407 return a;
    408 }
    409 */
     303 
     304  void TrafficControl::clientDisconnected(unsigned int clientID)
     305  {
     306    assert(clientListTemp_.find(clientID) != clientListTemp_.end() );
     307    assert(clientListPerm_.find(clientID) != clientListPerm_.end() );
     308    clientListTemp_.erase(clientListTemp_.find(clientID));
     309    clientListPerm_.erase(clientListPerm_.find(clientID));
     310  }
    410311
    411312
  • code/branches/bugger/src/network/TrafficControl.h

    • Property svn:eol-style set to native
    r2532 r2533  
    3838#include "util/Integers.h"
    3939#include "core/OrxonoxClass.h"
     40#include "network/ClientConnectionListener.h"
    4041
    4142namespace orxonox {
     
    7980*
    8081*/
    81 class TrafficControl : public OrxonoxClass{
     82class TrafficControl : public ClientConnectionListener {
    8283  private:
    8384
     
    122123    unsigned int currentClientID;
    123124    unsigned int targetSize;
     125    bool         bActive_;
    124126    /**
    125127    *copiedVector is a copy of the given Vector by the GSmanager, on this list all manipulations are performed
     
    141143    void evaluateList(unsigned int clientID, std::list<obj> *list);//done   
    142144    void ack(unsigned int clientID, unsigned int gamestateID);  // this function gets called when the server receives an ack from the client
     145   
     146    //ClientConnectionListener functions
     147    virtual void clientConnected(unsigned int clientID){};
     148    virtual void clientDisconnected(unsigned int clientID);
    143149
     150 
    144151  protected:
    145152    static TrafficControl *instance_;
     
    154161    *Elements of struct i are therefore: *list[i].objID
    155162    */
     163    void setConfigValues();
    156164    static TrafficControl *getInstance();
    157165    void processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>* list); //gets a pointer to the list (containing objectIDs) and sorts it
     
    162170    void deleteObject(unsigned int objectID);                           // this function gets called when an object has been deleted (in order to clean up lists and maps)
    163171   
    164     bool priodiffer(uint32_t clientID, obj i, obj j);
     172    bool prioritySort(uint32_t clientID, obj i, obj j);
     173    bool dataSort(obj i, obj j);
    165174    void printList(std::list<obj> *list, unsigned int clientID);
    166175    void fixCreatorDependencies(std::list<obj>::iterator it, std::list<obj> *list, unsigned int clientID);
  • code/branches/bugger/src/network/packet/Gamestate.cc

    r2532 r2533  
    349349  Gamestate *gs = new Gamestate(gdata);
    350350  uint8_t *newdata = gdata + sizeof(GamestateHeader);
    351 //   uint8_t *origdata = GAMESTATE_START(data_);
     351  uint8_t *origdata = GAMESTATE_START(data_);
    352352
    353353  //copy the GamestateHeader
     
    357357  uint32_t objectOffset;
    358358  unsigned int objectsize, destsize=0;
    359   Synchronisable *object;
     359  // TODO: Why is this variable not used?
     360  //Synchronisable *object;
    360361
    361362  //call TrafficControl
     
    366367    if((*it).objSize==0)
    367368      continue;
    368     oldobjectheader = (synchronisableHeader*)(data_ + (*it).objDataOffset);
     369    oldobjectheader = (synchronisableHeader*)origdata;
    369370    newobjectheader = (synchronisableHeader*)newdata;
    370     object = Synchronisable::getSynchronisable( (*it).objID );
    371     assert(object->objectID == oldobjectheader->objectID);
     371//     object = Synchronisable::getSynchronisable( (*it).objID );
     372//     assert(object->objectID == oldobjectheader->objectID);
    372373    objectsize = oldobjectheader->size;
    373     *newobjectheader = *oldobjectheader;
    374374    objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader
    375     if ( /*object->doSelection(HEADER->id)*/true ){
     375    if ( (*it).objID == oldobjectheader->objectID ){
     376      memcpy(newdata, origdata, objectsize);
    376377      assert(newobjectheader->dataAvailable==true);
    377       memcpy(newdata+objectOffset, data_ + (*it).objDataOffset + objectOffset, objectsize-objectOffset);
     378      ++it;
    378379    }else{
     380      *newobjectheader = *oldobjectheader;
    379381      newobjectheader->dataAvailable=false;
    380382      memset(newdata+objectOffset, 0, objectsize-objectOffset);
    381       assert(objectOffset==objectsize);
    382383    }
    383384    newdata += objectsize;
     385    origdata += objectsize;
    384386    destsize += objectsize;
    385387//     origdata += objectsize;
    386388  }
    387389  ((GamestateHeader*)gdata)->datasize = destsize;
     390  assert(destsize==HEADER->datasize);
    388391  assert(destsize!=0);
    389392  return gs;
  • code/branches/bugger/src/network/synchronisable/NetworkCallbackManager.cc

    • Property svn:eol-style set to native
  • code/branches/bugger/src/network/synchronisable/NetworkCallbackManager.h

    • Property svn:eol-style set to native
  • code/branches/bugger/src/network/synchronisable/Synchronisable.cc

    r2531 r2533  
    6666    RegisterRootObject(Synchronisable);
    6767    static uint32_t idCounter=0;
    68     objectFrequency_=1;
    6968    objectMode_=0x1; // by default do not send data to server
    7069    if ( !Host::running() || ( Host::running() && Host::isServer() ) )
     
    7877    classID = static_cast<uint32_t>(-1);
    7978
    80 
    81 //#ifndef NDEBUG
    82 //    ObjectList<Synchronisable>::iterator it;
    83 //    for(it = ObjectList<Synchronisable>::begin(); it!=ObjectList<Synchronisable>::end(); ++it){
    84 //        if(!(*it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0)))
    85 //        {
    86 //            COUT(1) << "Assertion failed: *it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0)" << std::endl;
    87 //            COUT(1) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl;
    88 //            abort();
    89 //        }
    90 //    }
    91 //#endif
     79    // set standard priority
     80    this->setPriority( priority::normal );
     81
     82   
     83    // get creator id
     84#ifndef NDEBUG
     85    ObjectList<Synchronisable>::iterator it;
     86    for(it = ObjectList<Synchronisable>::begin(); it!=ObjectList<Synchronisable>::end(); ++it){
     87      if( it->getObjectID()==this->objectID )
     88        if(!(*it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0))){
     89          COUT(1) << "Assertion failed: *it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0)" << std::endl;
     90          COUT(1) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl;
     91          abort();
     92        }
     93    }
     94#endif
    9295
    9396    this->creatorID = OBJECTID_UNKNOWN;
     
    177180      {
    178181        mem += header->size; //.TODO: this suckz.... remove size from header
     182        assert(0);
    179183        return 0;
    180184      }
     
    360364    //assert( (mode ^ objectMode_) != 0);
    361365    if(syncList.empty()){
     366      assert(0);
    362367      COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
    363368      return false;
  • code/branches/bugger/src/network/synchronisable/Synchronisable.h

    r2531 r2533  
    6161    };
    6262  }
     63 
     64  namespace priority{
     65    enum prio{
     66      very_high   = -100,
     67      high        = -15,
     68      normal      = 0,
     69      low         = 15,
     70      very_low    = 100
     71    };
     72  }
    6373
    6474  struct _NetworkExport synchronisableHeader{
     
    101111    template <class T> void unregisterVariable(T& var);
    102112    void setObjectMode(uint8_t mode);
    103     void setObjectPriority(unsigned int freq){ objectFrequency_ = freq; }
     113    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
    104114
    105115
Note: See TracChangeset for help on using the changeset viewer.