Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3015 for code/branches/netp3


Ignore:
Timestamp:
May 22, 2009, 9:46:53 AM (16 years ago)
Author:
scheusso
Message:

trying to make some performance improvements in TrafficControl

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

Legend:

Unmodified
Added
Removed
  • code/branches/netp3/src/network/TrafficControl.cc

    r2990 r3015  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
     23 *      Oliver Scheuss <scheusso [at] ee.ethz.ch>
    2424 *   Co-authors:
    2525 *      ...
     
    121121
    122122
    123         void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj> *list)
    124         {
    125 //        copiedVector = *list;
     123        void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj>& list)
     124        {
    126125          currentClientID=clientID;
    127126          currentGamestateID=gamestateID;
     
    138137        void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID)
    139138        {
    140           std::list<obj>::iterator itvec;  // iterator to iterate through the acked objects
     139          std::vector<obj>::iterator itvec;  // iterator to iterate through the acked objects
    141140
    142141    //assertions to make sure the maps already exist
     
    176175        {
    177176          std::map<unsigned int,std::map<unsigned int, objInfo> >::iterator itperm;//iterator clientListPerm over clientIDs
    178 //        itperm = (clientListPerm_).find(clientID);
    179 //        assert(itperm != clientListPerm_.end() );
    180177    unsigned int gsid=GAMESTATEID_INITIAL, gsdiff=currentGamestateID, prioperm=Synchronisable::getSynchronisable(objinf.objID)->getPriority(), priomom=0;
    181178    clientListPerm_[clientID][objinf.objID] = objInfo(objinf.objID, objinf.objCreatorID,gsid,gsdiff, objinf.objSize,prioperm,priomom);
    182 //        itperm->second.insert(std::pair<unsigned int, objInfo>(objid,objinf));
    183 //     permObjPrio_.insert(objid, objinf.objValuePerm);
    184179        }
    185180
     
    188183  * takes the shortened list which will be sent to the gsmanager and puts the *info into clientListTemp
    189184  */
    190   void TrafficControl::updateClientListTemp(std::list<obj> *list)
    191   {
    192     clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(*list);
     185  void TrafficControl::updateClientListTemp(std::vector<obj>& list)
     186  {
     187    clientListTemp_[currentClientID][currentGamestateID] = std::vector<obj>(list);
    193188  }
    194189
     
    197192  *takes the current list that has to be returned to the gsmanager and shortens it in criteria of bandwidth of clientID(XY)
    198193  */
    199   void TrafficControl::cut(std::list<obj> *list, unsigned int targetsize)
     194  void TrafficControl::cut(std::vector<obj>& list, unsigned int targetsize)
    200195  {
    201196    unsigned int size=0;
    202     std::list<obj>::iterator itvec, ittemp;
    203     assert(!list->empty());
    204     for(itvec = list->begin(); itvec != list->end();)
     197    std::vector<obj>::iterator itvec, ittemp;
     198    assert(!list.empty());
     199    for(itvec = list.begin(); itvec != list.end();)
    205200    {
    206201      assert( (*itvec).objSize < 1000);
     
    213208      {
    214209        clientListPerm_[currentClientID][(*itvec).objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative
    215         list->erase(itvec++);
     210        list.erase(itvec++);
    216211      }
    217212//       printList(list, currentClientID);
    218213    }
    219     assert(!list->empty());
     214    assert(!list.empty());
    220215  }
    221216
     
    224219        *evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this.
    225220        */
    226         void TrafficControl::evaluateList(unsigned int clientID, std::list<obj> *list)
     221        void TrafficControl::evaluateList(unsigned int clientID, std::vector<obj>& list)
    227222        {
    228223
     
    231226          //compare listToProcess vs clientListPerm
    232227    //if listToProcess contains new Objects, add them to clientListPerm
    233     std::list<obj>::iterator itvec;
    234           for( itvec=list->begin(); itvec != list->end(); itvec++)
     228    std::vector<obj>::iterator itvec;
     229          for( itvec=list.begin(); itvec != list.end(); itvec++)
    235230          {
    236231            if ( clientListPerm_[clientID].find( (*itvec).objID) != clientListPerm_[clientID].end() )
     
    254249      //sort copied list according to priorities
    255250      // use boost bind here because we need to pass a memberfunction to stl sort
    256       list->sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
     251      sort( list.begin(), list.end(), boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
     252//       list.sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
    257253
    258254      //now we check, that the creator of an object always exists on a client
    259       std::list<obj>::iterator itcreator;
    260       for(itvec = list->begin(); itvec != list->end(); itvec++)
     255      std::vector<obj>::iterator itcreator;
     256      for(itvec = list.begin(); itvec != list.end(); itvec++)
    261257      {
    262258        fixCreatorDependencies(itvec, list, clientID);
     
    268264
    269265      //now sort again after objDataOffset
    270       list->sort(boost::bind(&TrafficControl::dataSort, this, _1, _2) );
     266      sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) );
    271267    }
    272268    //diese Funktion updateClientList muss noch gemacht werden
     
    275271  }
    276272
    277   void TrafficControl::printList(std::list<obj> *list, unsigned int clientID)
    278   {
    279     std::list<obj>::iterator it;
     273  void TrafficControl::printList(std::vector<obj>& list, unsigned int clientID)
     274  {
     275    std::vector<obj>::iterator it;
    280276    COUT(0) << "=========== Objectlist ===========" << endl;
    281     for( it=list->begin(); it!=list->end(); it++)
     277    for( it=list.begin(); it!=list.end(); it++)
    282278      COUT(0) << "ObjectID: " << (*it).objID << " creatorID: " << (*it).objCreatorID << " Priority: " << clientListPerm_[clientID][(*it).objID].objValuePerm + clientListPerm_[clientID][(*it).objID].objValueSched << " size: " << (*it).objSize << endl;
    283279  }
    284280
    285   void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj> *list, unsigned int clientID)
     281  void TrafficControl::fixCreatorDependencies(std::vector<obj>::iterator it1, std::vector<obj>& list, unsigned int clientID)
    286282  {
    287283    if ( (*it1).objCreatorID == OBJECTID_UNKNOWN )
     
    289285    if( clientListPerm_[clientID][(*it1).objCreatorID].objCurGS != GAMESTATEID_INITIAL )
    290286      return;
    291     std::list<obj>::iterator it2, it3=it1;
    292     for( it2 = ++it3; it2 != list->end(); it2++ )
     287    std::vector<obj>::iterator it2, it3=it1;
     288    for( it2 = ++it3; it2 != list.end(); it2++ )
    293289    {
    294290      if( (*it2).objID == (*it1).objCreatorID )
    295291      {
    296         it3 = list->insert(it1, *it2); //insert creator before it1
    297         list->erase(it2);
     292        it3 = list.insert(it1, *it2); //insert creator before it1
     293        list.erase(it2);
    298294//         printList(list, clientID);
    299295        fixCreatorDependencies( it3, list, clientID );
  • code/branches/netp3/src/network/TrafficControl.h

    r2710 r3015  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
     23 *      Oliver Scheuss <scheusso [at] ee.ethz.ch>
    2424 *   Co-authors:
    2525 *      ...
     
    3232
    3333#include <string>
    34 #include <list>
     34#include <vector>
    3535#include <map>
    3636#include <utility>
     
    8383
    8484    /**
    85     *Lists that will be used:
    86     *listToProcess
    87     *clientListPerm
    88     *clientListTemp
    89     *referenceList
    90     *permObjPrio list
    91     *schedObjPrio
    92     */
    93     //start: lists to be used
    94     /**
    95     *creates list (typ map) that contains objids, struct with info concerning object(objid)
    96     */
    97 //     std::map<unsigned int, objInfo> listToProcess_;//copy of argument, when traffic control tool is being called, the original of this must be returned later on, eg the list given by GS
    98     /**
    9985    *permanent client list: contains client ids, object ids and objectInfos (in this order)
    10086    */
     
    10591    *temporary client list: contains client ids, gamestate ids and object ids (in this order)
    10692    */
    107     std::map<unsigned int, std::map<unsigned int, std::list<obj> > > clientListTemp_;
    108     /**
    109     *static priority list: contains obj id, basic priority (in this order)
    110     */
    111 //     std::map<unsigned int, unsigned int> permObjPrio_;
    112     /**
    113     *dynamic priority list: contains obj id, dynamic priority (eg scheduled) (in this order)
    114     */
    115 //     std::map<unsigned int, unsigned int> schedObjPrio_;
    116     //end: lists to be used
     93    std::map<unsigned int, std::map<unsigned int, std::vector<obj> > > clientListTemp_;
    11794
    11895    /**updateReferenceList
     
    123100    unsigned int targetSize;
    124101    bool         bActive_;
    125     /**
    126     *copiedVector is a copy of the given Vector by the GSmanager, on this list all manipulations are performed
    127     */
    128 //     std::list<obj> copiedVector;
    129 
    130 //     void updateReferenceList(std::map<unsigned int, objInfo> *list);//done
    131     void insertinClientListPerm(unsigned int clientID, obj objinf);//done
    132     /**
    133     *creates listToProcess, which can be easialy compared with other lists
    134     */
    135 //     void copyList(std::list<obj> *list);//done
    136102   
    137     void cut(std::list<obj> *list, unsigned int targetsize);
    138     void updateClientListTemp(std::list<obj> *list);//done
     103    void insertinClientListPerm(unsigned int clientID, obj objinf);
     104   
     105    void cut(std::vector<obj>& list, unsigned int targetsize);
     106    void updateClientListTemp(std::vector<obj>& list);//done
    139107    /**
    140108    *evaluates Data given (list) and produces result(->Data to be updated)
    141109    */
    142     void evaluateList(unsigned int clientID, std::list<obj> *list);//done   
     110    void evaluateList(unsigned int clientID, std::vector<obj>& list);//done   
    143111    void ack(unsigned int clientID, unsigned int gamestateID);  // this function gets called when the server receives an ack from the client
    144112   
     
    162130    void setConfigValues();
    163131    static TrafficControl *getInstance();
    164     void processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>* list); //gets a pointer to the list (containing objectIDs) and sorts it
    165     //done
     132    void processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj>& list); //gets a pointer to the list (containing objectIDs) and sorts it
    166133    static void processAck(unsigned int clientID, unsigned int gamestateID)
    167134    { return instance_->ack(clientID, gamestateID); }
    168     //done
    169135    void deleteObject(unsigned int objectID);                           // this function gets called when an object has been deleted (in order to clean up lists and maps)
    170136   
    171137    bool prioritySort(uint32_t clientID, obj i, obj j);
    172138    bool dataSort(obj i, obj j);
    173     void printList(std::list<obj> *list, unsigned int clientID);
    174     void fixCreatorDependencies(std::list<obj>::iterator it, std::list<obj> *list, unsigned int clientID);
     139    void printList(std::vector<obj>& list, unsigned int clientID);
     140    void fixCreatorDependencies(std::vector<obj>::iterator it, std::vector<obj>& list, unsigned int clientID);
    175141};
    176142
  • code/branches/netp3/src/network/packet/Gamestate.cc

    r3003 r3015  
    111111    tempsize = it->getData(mem, id, mode);
    112112    if ( it->doSync( id, mode ) )
    113       dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
     113      dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
    114114   
    115115#ifndef NDEBUG
     
    364364Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
    365365  assert(data_);
    366   std::list<obj>::iterator it;
     366  std::vector<obj>::iterator it;
    367367
    368368  // allocate memory for new data
     
    383383
    384384  //call TrafficControl
    385   TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), &dataMap_ );
     385  TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), dataVector_ );
    386386
    387387  //copy in the zeros
    388   for(it=dataMap_.begin(); it!=dataMap_.end();){
     388  for(it=dataVector_.begin(); it!=dataVector_.end();){
    389389    SynchronisableHeader oldobjectheader(origdata);
    390390    SynchronisableHeader newobjectheader(newdata);
  • code/branches/netp3/src/network/packet/Gamestate.h

    r2896 r3015  
    3737#include <string.h>
    3838#include <map>
    39 #include <list>
     39#include <vector>
    4040#include <cassert>
    4141#ifndef NDEBUG
     
    129129  private:
    130130    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
    131     std::list<obj> dataMap_;
     131    std::vector<obj> dataVector_;
    132132    GamestateHeader* header_;
    133133};
Note: See TracChangeset for help on using the changeset viewer.