Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2009, 1:18:03 PM (15 years ago)
Author:
dafrick
Message:

Merged presentation2 branch into pickup2 branch.

Location:
code/branches/pickup2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup2

  • code/branches/pickup2/src/libraries/network/TrafficControl.cc

    r5781 r6412  
    6464*Initializing protected members
    6565*/
    66         TrafficControl *TrafficControl::instance_=0;
    67 
    68         /**
    69         * @brief Constructor: assures that only one reference will be created and sets the pointer
    70         */
    71         TrafficControl::TrafficControl()
    72         {
     66    TrafficControl *TrafficControl::instance_=0;
     67
     68    /**
     69    * @brief Constructor: assures that only one reference will be created and sets the pointer
     70    */
     71    TrafficControl::TrafficControl()
     72    {
    7373    RegisterObject(TrafficControl);
    74           assert(instance_==0);
    75           instance_=this;
     74      assert(instance_==0);
     75      instance_=this;
    7676    this->setConfigValues();
    77         }
    78 
    79         /**
    80         * @brief Destructor: resets the instance pointer to 0
    81         */
    82         TrafficControl::~TrafficControl()
    83         {
    84           instance_=0;
    85         }
     77    }
     78
     79    /**
     80    * @brief Destructor: resets the instance pointer to 0
     81    */
     82    TrafficControl::~TrafficControl()
     83    {
     84      instance_=0;
     85    }
    8686
    8787/**
     
    121121
    122122
    123         void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>& list)
    124         {
    125           currentClientID=clientID;
    126           currentGamestateID=gamestateID;
    127           evaluateList(clientID, list);
    128           return;
    129         }
     123    void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>& list)
     124    {
     125      currentClientID=clientID;
     126      currentGamestateID=gamestateID;
     127      evaluateList(clientID, list);
     128      return;
     129    }
    130130
    131131  TrafficControl *TrafficControl::getInstance()
     
    135135  }
    136136
    137         void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID)
    138         {
     137    void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID)
     138    {
    139139    if ( !this->bActive_ )
    140140      return;
    141           std::list<obj>::iterator itvec;  // iterator to iterate through the acked objects
     141      std::list<obj>::iterator itvec;  // iterator to iterate through the acked objects
    142142
    143143    //assertions to make sure the maps already exist
     
    145145    assert(clientListPerm_.find(clientID) != clientListPerm_.end() );
    146146    assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() );
    147    
     147
    148148    // shortcut for maps
    149149    std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
     
    151151
    152152    for(itvec = objectListTemp[gamestateID].begin(); itvec != objectListTemp[gamestateID].end(); itvec++)
    153           {
    154       if(objectListPerm.find((*itvec).objID) != objectListPerm.end()) // check whether the obj already exists in our lists
    155       {
    156         objectListPerm[(*itvec).objID].objCurGS = gamestateID;
    157         objectListPerm[(*itvec).objID].objValueSched = 0; //set scheduling value back
     153      {
     154      if(objectListPerm.find(itvec->objID) != objectListPerm.end()) // check whether the obj already exists in our lists
     155      {
     156        objectListPerm[itvec->objID].objCurGS = gamestateID;
     157        objectListPerm[itvec->objID].objValueSched = 0; //set scheduling value back
    158158      }
    159159      else
    160160      {
    161161        assert(0);
    162         objectListPerm[(*itvec).objID].objCurGS = gamestateID;
    163         objectListPerm[(*itvec).objID].objID = (*itvec).objID;
    164         objectListPerm[(*itvec).objID].objCreatorID = (*itvec).objCreatorID;
    165         objectListPerm[(*itvec).objID].objSize = (*itvec).objSize;
    166       }
    167           }
    168            // remove temporary list (with acked objects) from the map
     162        objectListPerm[itvec->objID].objCurGS = gamestateID;
     163        objectListPerm[itvec->objID].objID = itvec->objID;
     164        objectListPerm[itvec->objID].objCreatorID = itvec->objCreatorID;
     165        objectListPerm[itvec->objID].objSize = itvec->objSize;
     166      }
     167      }
     168       // remove temporary list (with acked objects) from the map
    169169    objectListTemp.erase( objectListTemp.find(gamestateID) );
    170         }
     170    }
    171171
    172172/**
     
    174174*/
    175175
    176         /**
    177         *updateClientListPerm
    178         *returns void
    179         */
    180         void TrafficControl::insertinClientListPerm(unsigned int clientID, obj objinf)
    181         {
    182           std::map<unsigned int,std::map<unsigned int, objInfo> >::iterator itperm;//iterator clientListPerm over clientIDs
     176    /**
     177    *updateClientListPerm
     178    *returns void
     179    */
     180    void TrafficControl::insertinClientListPerm(unsigned int clientID, obj objinf)
     181    {
     182      std::map<unsigned int,std::map<unsigned int, objInfo> >::iterator itperm;//iterator clientListPerm over clientIDs
    183183    unsigned int gsid=GAMESTATEID_INITIAL, gsdiff=currentGamestateID, prioperm=Synchronisable::getSynchronisable(objinf.objID)->getPriority(), priomom=0;
    184184    clientListPerm_[clientID][objinf.objID] = objInfo(objinf.objID, objinf.objCreatorID,gsid,gsdiff, objinf.objSize,prioperm,priomom);
    185         }
     185    }
    186186
    187187  /**
     
    205205    for(itvec = list.begin(); itvec != list.end();)
    206206    {
    207       assert( (*itvec).objSize < 1000);
    208       if ( ( size + (*itvec).objSize ) < targetsize )
    209       {
    210         size += (*itvec).objSize;//objSize is given in bytes
     207      assert( itvec->objSize < 1000);
     208      if ( ( size + itvec->objSize ) < targetsize )
     209      {
     210        size += itvec->objSize;//objSize is given in bytes
    211211        ++itvec;
    212212      }
    213213      else
    214214      {
    215         clientListPerm_[currentClientID][(*itvec).objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative
     215        clientListPerm_[currentClientID][itvec->objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative
    216216        list.erase(itvec, list.end());
    217217        break;
     
    223223
    224224
    225         /**
    226         *evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this.
    227         */
    228         void TrafficControl::evaluateList(unsigned int clientID, std::list<obj>& list)
    229         {
     225    /**
     226    *evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this.
     227    */
     228    void TrafficControl::evaluateList(unsigned int clientID, std::list<obj>& list)
     229    {
    230230
    231231    if( bActive_ )
     
    236236      //if listToProcess contains new Objects, add them to clientListPerm
    237237      std::list<obj>::iterator itvec;
    238    
     238
    239239      std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
    240    
     240
    241241      for( itvec=list.begin(); itvec != list.end(); itvec++)
    242242      {
    243         if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )
     243        if ( objectListPerm.find( itvec->objID) != objectListPerm.end() )
    244244        {
    245245        // we already have the object in our map
    246246        //obj bleibt in liste und permanente prio wird berechnet
    247           objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;
     247          objectListPerm[itvec->objID].objDiffGS = currentGamestateID - objectListPerm[itvec->objID].objCurGS;
    248248          continue;//check next objId
    249249        }
     
    256256      }
    257257    //end compare listToProcess vs clientListPerm
    258      
     258
    259259      //sort copied list according to priorities
    260260      // use boost bind here because we need to pass a memberfunction to stl sort
    261261//       sort( list.begin(), list.end(), boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
    262262      list.sort( boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
    263      
     263
    264264//       list.sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
    265265
     
    277277//       sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) );
    278278      list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) );
    279      
     279
    280280      //diese Funktion updateClientList muss noch gemacht werden
    281281      updateClientListTemp(list);
     
    289289    COUT(0) << "=========== Objectlist ===========" << endl;
    290290    for( it=list.begin(); it!=list.end(); it++)
    291       COUT(0) << "ObjectID: " << (*it).objID << " creatorID: " << (*it).objCreatorID << " Priority: " << clientListPerm_[clientID][(*it).objID].objValuePerm + clientListPerm_[clientID][(*it).objID].objValueSched << " size: " << (*it).objSize << endl;
     291      COUT(0) << "ObjectID: " << it->objID << " creatorID: " << it->objCreatorID << " Priority: " << clientListPerm_[clientID][it->objID].objValuePerm + clientListPerm_[clientID][it->objID].objValueSched << " size: " << it->objSize << endl;
    292292  }
    293293
    294294  void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj>& list, unsigned int clientID)
    295295  {
    296     if ( (*it1).objCreatorID == OBJECTID_UNKNOWN )
    297       return;
    298     if( clientListPerm_[clientID][(*it1).objCreatorID].objCurGS != GAMESTATEID_INITIAL )
     296    if ( it1->objCreatorID == OBJECTID_UNKNOWN )
     297      return;
     298    if( clientListPerm_[clientID][it1->objCreatorID].objCurGS != GAMESTATEID_INITIAL )
    299299      return;
    300300    std::list<obj>::iterator it2, it3=it1;
    301301    for( it2 = ++it3; it2 != list.end(); it2++ )
    302302    {
    303       if( (*it2).objID == (*it1).objCreatorID )
     303      if( it2->objID == it1->objCreatorID )
    304304      {
    305305        it3 = list.insert(it1, *it2); //insert creator before it1
Note: See TracChangeset for help on using the changeset viewer.