Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2334 for code


Ignore:
Timestamp:
Dec 3, 2008, 5:35:20 PM (16 years ago)
Author:
scheusso
Message:

made some adjustments and corrections
used boost::bind to pass the member function to stl sort

Location:
code/branches/network/src/network
Files:
2 edited

Legend:

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

    r2332 r2334  
    3030
    3131#include <cassert>
     32#include <boost/bind.hpp>
    3233
    3334namespace network {
     
    3637*Initializing protected members
    3738*/
    38         TrafficControl *TraffiControl::instance_=0;
     39        TrafficControl *TrafficControl::instance_=0;
    3940       
    4041        /**
     
    4849          clientListPerm_ = new std::map<unsigned int,std::map<unsigned int, objInfo>>;
    4950          clientListTemp_ = new std::map std::map<unsigned int, std::map<unsigned int, std::vector<obj>>>;
    50           referenceList_ = new std::map<unsigned int, Synchronisable*>;
    5151          permObjPrio_ = new std::map<unsigned int, unsigned int> ;
    5252          schedObjPrio_ = new std::map<unsigned int, unsigned int> schedObjPrio_;
     
    6767*/
    6868
    69         TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj> *list)
     69        /**
     70                *eigener sortieralgorithmus
     71        */
     72        bool TrafficControl::priodiffer(obj i, obj j)
     73        {
     74          map<unsigned int, objInfo>::iterator iti;
     75          map<unsigned int, objInfo>::iterator itj;
     76          iti=listToProcess_->find(i.objID);
     77          itj=listToProcess_->find(j.objID);
     78          return iti->second.objValuePerm < itj->second.objValuePerm;
     79        }
     80
     81
     82
     83        std::vector<obj>* TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj> *list)
    7084        {
    7185          copiedVector = *list;
     
    7993        }
    8094       
    81         TrafficControl::processAck(unsigned int clientID, unsigned int gamestateID)
     95        void TrafficControl::processAck(unsigned int clientID, unsigned int gamestateID)
    8296        {
    8397          map<unsigned int,std::map<unsigned int, objInfo>>::iterator itperm;//iterator clientListPerm
     
    119133*/
    120134       
    121         //brauch ich die noch??,
    122         TrafficControl::createReferenceList(Synchronisable *list)
    123         {
    124           map<unsigned int, Synchronisable*>::iterator itref;
    125           itref=referenceList_->begin();
    126           referenceList_->insert(itref,pair<unsigned int, Synchronisable*>((*itref).getObjectID,(*itref).getSynchronisable));
    127         }
    128         //end brauch ich die noch
    129135       
    130136        /**
    131137        *copyList gets vector of Gamestate Manager and turns it to *listToProcess
    132138        */
    133         TrafficControl::copyList(std::map<obj> *list)
     139        void TrafficControl::copyList(std::map<obj> *list)
    134140        {
    135141          vector<obj>::iterator itvec;
     
    139145            (*objectA).objCreatorID=(*itvec).objCreatorID;
    140146            (*objectA).objSize = (*itvec).objSize;
    141             (*listToProcess_).insert(pair<currentClientID, map<(*itvec).objID,objectA>>)//unsicher: ob map<...> so richtig ist
     147            (*listToProcess_).insert(pair<currentClientID, map<(*itvec).objID,objectA>>);//unsicher: ob map<...> so richtig ist
    142148          }
    143149        }
     
    146152        *returns void
    147153        */
    148         TrafficControl::updateReferenceList(std::map<unsigned int, objInfo> *list)
    149         {
    150           map<unsigned int, Synchronisable*>::iterator itref;
    151           map<unsigned int, objInfo>::iterator itproc;
     154        void TrafficControl::updateReferenceList(std::map<unsigned int, objInfo> *list)
     155        {
     156          std::map<unsigned int, Synchronisable*>::iterator itref;
     157          std::map<unsigned int, objInfo>::iterator itproc;
    152158          for(itproc=(*listToProcess_).begin();itproc != (*listToProcess_).end(); itproc++)
    153159          {
     
    159165            else
    160166            {
    161               (*referenceList_).insert(pair<unsigned int,          Synchronisable*>((*itproc).first,Synchronisable::getSynchronisable((*itproc).first));//important: how to get adress of an object!
     167              (*referenceList_).insert(pair<unsigned int,          Synchronisable*>((*itproc).first,Synchronisable::getSynchronisable((*itproc).first)));//important: how to get adress of an object!
    162168              insertinClientListPerm(currentClientID,itproc->first,itproc->second);
    163169            }
     
    168174        *returns void
    169175        */
    170         TrafficControl::insertinClientListPerm(unsigned int clientid, unsigned int objid, objInfo objinf)
     176        void TrafficControl::insertinClientListPerm(unsigned int clientid, unsigned int objid, objInfo objinf)
    171177        {
    172           map<unsigned int,std::map<unsigned int, objInfo>>::iterator itperm;//iterator clientListPerm over clientIDs
     178          std::map<unsigned int,std::map<unsigned int, objInfo>>::iterator itperm;//iterator clientListPerm over clientIDs
    173179          itperm = (clientListPerm_).find(clientiD);
    174180          assert(itperm != clientListPerm_.end() );
     
    180186        *evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this.
    181187        */
    182         TrafficControl::evaluateList(std::map<obj> *list)
     188        void TrafficControl::evaluateList(std::map<obj> *list)
    183189        {
    184190          copyList(list);
     
    188194       
    189195          //compare listToProcess vs clientListPerm
    190           map<unsigned int, objInfo>::iterator itproc;
    191           map<unsigned int,std::map<unsigned int, objInfo>>::iterator itperm;
    192           map<unsigned int, objInfo>::iterator itpermobj;
    193           map<unsigned int, unsigned int>::iterator itpermprio;
     196          std::map<unsigned int, objInfo>::iterator itproc;
     197          std::map<unsigned int, std::map<unsigned int, objInfo>>::iterator itperm;
     198          std::map<unsigned int, objInfo>::iterator itpermobj;
     199          std::map<unsigned int, unsigned int>::iterator itpermprio;
    194200          for((*itproc=listToProcess_).begin(); itproc != (*listToProcess_).end();it++)
    195201          {
     
    243249        }
    244250        //sort copied vector aufgrund der objprioperm in clientlistperm
    245         sort(copiedVector.begin(),copiedVector.end(),priodiffer);
     251        // use boost bind here because we need to pass a memberfunction to stl sort
     252        sort(copiedvector.begin(), copiedvector.end(), boost::bind(&TrafficControl::priodiffer,this,_1,_2) );
    246253        //swappen aufgrund von creator oder ganz rausnehmen!?
    247254        for(itvec = copiedVector.begin(); itvec < copiedVector.end(); itvec++)
  • code/branches/network/src/network/TrafficControl.h

    r2332 r2334  
    6363};
    6464
    65 /**
    66 *eigener sortieralgorithmus
    67 */
    68 bool priodiffer(obj i, obj j)
    69 {
    70   map<unsigned int, objInfo>::iterator iti;
    71   map<unsigned int, objInfo>::iterator itj;
    72   iti=listToProcess_->find(i.objID);
    73   itj=listToProcess_->find(j.objID);
    74   return iti->second.objValuePerm < itj->second.objValuePerm;
    75 }
     65
    7666
    7767/**
     
    9585    */
    9686    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 vector given by GS
    97     /**
    98     *reference list: contains object ids and the reference belonging to this id.
    99     */
    100     //std::map<unsigned int, Synchronisable*> *referenceList_;//has to be created with constructor and then needs to be updated by evaluateList().
    10187    /**
    10288    *permanent client list: contains client ids, object ids and objectInfos (in this order)
     
    131117    void updateReferenceList(std::map<unsigned int, objInfo> *list);//done
    132118    void insertinClientListPerm(unsigned int objid, objInfo objinf);//done
    133     void createReferenceList(Synchronisable *list);//done
    134119    /**
    135120    *creates listToProcess, which can be easialy compared with other lists
     
    161146    //done
    162147    void deleteObject(unsigned int objectID);                           // this function gets called when an object has been deleted (in order to clean up lists and maps)
     148   
     149    bool priodiffer(obj i, obj j);
    163150};
    164151
Note: See TracChangeset for help on using the changeset viewer.