Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2351


Ignore:
Timestamp:
Dec 7, 2008, 10:57:09 PM (16 years ago)
Author:
scheusso
Message:

some changes. still not working yet, but will correct theese problems after merge with network64

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

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/ClientInformation.h

    r2009 r2351  
    4545#include <enet/enet.h>
    4646#include <boost/thread/recursive_mutex.hpp>
     47
    4748
    4849// WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE
  • code/branches/network/src/network/GamestateManager.cc

    r2341 r2351  
    134134    if(!reference)
    135135      return 0;
    136     gs = reference->doSelection(clientID);
     136    gs = reference->doSelection(clientID, 10000);
     137//     gs = new packet::Gamestate(*reference);
    137138    // save the (undiffed) gamestate in the clients gamestate map
    138139    gamestateMap_[clientID].insert(std::pair<int, packet::Gamestate*>(gs->getID(), gs));
  • code/branches/network/src/network/Synchronisable.h

    r2348 r2351  
    113113
    114114    inline unsigned int getObjectID(){return objectID;}
     115    inline unsigned int getCreatorID(){return creatorID;}
    115116    inline unsigned int getClassID(){return classID;}
    116117    inline unsigned int getPriority(){ return objectFrequency_;}
  • code/branches/network/src/network/TrafficControl.cc

    r2348 r2351  
    3131#include <cassert>
    3232#include <boost/bind.hpp>
    33 #include "Synchronisable.h"
    34 #include "ClientInformation.h"
    3533
    3634namespace network {
     
    8684    assert(clientListPerm_[clientID].find(j.objID) != clientListPerm_[clientID].end()); // make sure the object j is in the client list
    8785   
    88     return clientListPerm_[clientID][i.objID].objID < clientListPerm_[clientID][j.objID].objID;
     86    int prio1 = clientListPerm_[clientID][i.objID].objValuePerm + clientListPerm_[clientID][i.objID].objValueSched;
     87    int prio2 = clientListPerm_[clientID][j.objID].objValuePerm + clientListPerm_[clientID][j.objID].objValueSched;
     88    // NOTE: smaller priority is better
     89    return prio1 < prio2;
    8990  }
    9091
    9192
    92         std::vector<obj>* TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj> *list)
     93        void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj> *list)
    9394        {
    94           copiedVector = *list;
     95//        copiedVector = *list;
    9596          currentClientID=clientID;
    9697          currentGamestateID=gamestateID;
    9798          evaluateList(clientID, list);
    9899          //list hatte vorher ja vielmehr elemente, nach zuweisung nicht mehr... speicherplatz??
    99           *list=copiedVector;
     100//        *list=copiedVector;
    100101    //später wird copiedVector ja überschrieben, ist das ein problem für list-dh. für gamestatemanager?
    101           return list;
     102          return;
    102103        }
    103104       
     
    212213    std::vector<obj>::iterator itvec;
    213214    itvec = list->begin();
    214 //     unsigned int i=0;
    215215    for(itvec = list->begin(); itvec != list->end() && size<targetsize; itvec++)
    216 //     while(size<targetsize && (itvec!=list.end()))
    217216    {
    218       size = size + (*itvec).objSize;//objSize is given in bytes!??
    219 //       i++;
    220 //       itvec = list.begin()+i;
     217      if ( size + (*itvec).objSize < targetsize )
     218      {
     219        size = size + (*itvec).objSize;//objSize is given in bytes
     220      }
     221      else
     222      {
     223        clientListPerm_[currentClientID][(*itvec).objID].objValueSched -= SCHED_PRIORITY_OFFSET;
     224        list->erase(itvec++);
     225      }
    221226    }
    222     list->erase(itvec, list->end());
    223227  }
    224228
     
    235239          //compare listToProcess vs clientListPerm
    236240    //if listToProcess contains new Objects, add them to clientListPerm
    237           std::map<unsigned int, objInfo>::iterator itproc;
     241//        std::map<unsigned int, objInfo>::iterator itproc;
    238242    std::vector<obj>::iterator itvec;
    239           std::map<unsigned int, std::map<unsigned int, objInfo> >::iterator itperm;
     243//        std::map<unsigned int, std::map<unsigned int, objInfo> >::iterator itperm;
    240244//        std::map<unsigned int, objInfo>::iterator itpermobj;
    241           unsigned int permprio;
    242245          for( itvec=list->begin(); itvec != list->end(); itvec++)
    243246          {
    244             itperm = clientListPerm_.find(clientID);
     247//          itperm = clientListPerm_.find(clientID);
    245248            if ( clientListPerm_[clientID].find( (*itvec).objID) != clientListPerm_[clientID].end() )
    246249      {
     
    306309    // use boost bind here because we need to pass a memberfunction to stl sort
    307310    sort(list->begin(), list->end(), boost::bind(&TrafficControl::priodiffer, this, clientID, _1, _2) );
    308     //swappen aufgrund von creator oder ganz rausnehmen!?
     311   
     312    //now we check, that the creator of an object always exists on a client
     313    std::vector<obj>::iterator itcreator;
    309314    for(itvec = list->begin(); itvec != list->end(); itvec++)
    310315    {
    311       //TODO: TODO TODO TODO
    312       itproc = (listToProcess_).find((*itvec).objID);
    313       if((*itproc).second.objCreatorID)
    314       {
    315       //vor dem child in copiedvector einfügen, wie?
    316         copiedVector.insert(copiedVector.find((*itproc).first),(*itproc).second.objCreatorID);
    317       }
    318       else continue;
     316      if ( (*itvec).objCreatorID != OBJECTID_UNKNOWN )
     317      {
     318        if( clientListPerm_[clientID][(*itvec).objCreatorID].objCurGS != GAMESTATEID_INITIAL )
     319          continue;
     320        for( itcreator = list->begin(); itcreator != list->end(); itcreator++)
     321        {
     322          if ( (*itcreator).objID == (*itvec).objCreatorID )
     323            break;
     324        }
     325        // if the creator is before the object everything is fine
     326        if( itcreator < itvec )
     327          continue;
     328        // otherwise insert the creator right before our object and delete it at the old position
     329        list->insert(itvec, *itcreator);
     330        list->erase(itcreator);
     331      }
    319332    }
    320333    //end of sorting
    321334    //now the cutting, work the same obj out in processobjectlist and copiedvector, compression rate muss noch festgelegt werden.
    322     cut(copiedVector,targetSize);
     335    cut(list, targetSize);
    323336    //diese Funktion updateClientList muss noch gemacht werden
    324337    updateClientListTemp(list);
    325338    //end of sorting
    326339  }
    327 
    328340
    329341
  • code/branches/network/src/network/TrafficControl.h

    r2348 r2351  
    3737#include "NetworkPrereqs.h"
    3838#include "Synchronisable.h"
     39#include "ClientInformation.h"
    3940#include "util/Integers.h"
    4041
     
    4849  uint32_t objID;
    4950  uint32_t objCreatorID;
    50   int32_t objCurGS;//current GameState ID
    51   int32_t objDiffGS;//difference between current and latest GameState
     51  uint32_t objCurGS;//current GameState ID
     52  uint32_t objDiffGS;//difference between current and latest GameState
    5253  uint32_t objSize;
    5354  unsigned int objValuePerm;
     
    5556  objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched)
    5657    { objID = ID; objCreatorID = creatorID; objCurGS = curGsID; objDiffGS = diffGsID; objSize = size; objValuePerm = prioperm; objValueSched = priosched; }
     58  objInfo()
     59    { objID = OBJECTID_UNKNOWN; objCreatorID = OBJECTID_UNKNOWN; objCurGS = GAMESTATEID_INITIAL; objDiffGS = objCurGS; objSize = 0; objValuePerm = 0; objValueSched = 0; }
    5760};
    5861
     
    6265struct obj
    6366{
    64   unsigned int objID;
    65   unsigned int objCreatorID;
    66   unsigned int objSize;
     67  uint32_t objID;
     68  uint32_t objCreatorID;
     69  uint32_t objSize;
     70  uint32_t objDataOffset;
     71  obj()
     72    { objID = OBJECTID_UNKNOWN; objCreatorID = OBJECTID_UNKNOWN; objSize = 0; objDataOffset = 0; }
     73  obj( uint32_t ID, uint32_t creatorID, uint32_t size, uint32_t offset )
     74  { objID = ID; objCreatorID = creatorID; objSize = size; objDataOffset = offset; }
    6775};
    6876
     77
     78const unsigned int SCHED_PRIORITY_OFFSET = -5;
    6979
    7080
     
    8898    *creates list (typ map) that contains objids, struct with info concerning object(objid)
    8999    */
    90     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
     100//     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
    91101    /**
    92102    *permanent client list: contains client ids, object ids and objectInfos (in this order)
     
    118128    *copiedVector is a copy of the given Vector by the GSmanager, on this vector all manipulations are performed
    119129    */
    120     std::vector<obj> copiedVector;
     130//     std::vector<obj> copiedVector;
    121131
    122132//     void updateReferenceList(std::map<unsigned int, objInfo> *list);//done
     
    132142    *evaluates Data given (vector) and produces result(->Data to be updated)
    133143    */
    134     void evaluateList(unsigned int clientID, std::vector<obj> *list);//done
     144    void evaluateList(unsigned int clientID, std::vector<obj> *list);//done   
    135145
    136146  protected:
     
    146156    *Elements of struct i are therefore: *list[i].objID
    147157    */
    148     std::vector<obj>* processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj>* list); //gets a pointer to the vector (containing objectIDs) and sorts it
     158    void processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj>* list); //gets a pointer to the vector (containing objectIDs) and sorts it
    149159    //done
    150160    void processAck(unsigned int clientID, unsigned int gamestateID);   // this function gets called when the server receives an ack from the client
  • code/branches/network/src/network/packet/Gamestate.cc

    r2041 r2351  
    117117
    118118    //if(it->doSelection(id))
    119     dataMap_[mem-data_]=(*it);  // save the mem location of the synchronisable data
     119    dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
     120//     dataMap_[mem-data_]=(*it);  // save the mem location of the synchronisable data
    120121    if(!it->getData(mem, id, mode))
    121122      return false; // mem pointer gets automatically increased because of call by reference
     
    333334}
    334335
    335 Gamestate* Gamestate::doSelection(unsigned int clientID){
     336Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
    336337  assert(data_);
    337   std::map<unsigned int, Synchronisable *>::iterator it;
     338  std::vector<obj>::iterator it;
    338339
    339340  // allocate memory for new data
     
    342343  Gamestate *gs = new Gamestate(gdata);
    343344  uint8_t *newdata = gdata + sizeof(GamestateHeader);
    344   uint8_t *origdata = GAMESTATE_START(data_);
     345//   uint8_t *origdata = GAMESTATE_START(data_);
    345346
    346347  //copy the GamestateHeader
     
    349350  synchronisableHeader *oldobjectheader, *newobjectheader;
    350351  unsigned int objectOffset;
     352  unsigned int objectsize;
     353  Synchronisable *object;
    351354
    352355  //copy in the zeros
    353356  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
    354     oldobjectheader = (synchronisableHeader*)origdata;
     357    oldobjectheader = (synchronisableHeader*)(data_ + (*it).objDataOffset);
    355358    newobjectheader = (synchronisableHeader*)newdata;
    356     unsigned int objectsize = oldobjectheader->size;
    357     assert(it->second->objectID==oldobjectheader->objectID);
     359    objectsize = oldobjectheader->size;
     360    object = Synchronisable::getSynchronisable( (*it).objID );
     361    assert(object->objectID == oldobjectheader->objectID);
    358362    *newobjectheader = *oldobjectheader;
    359363    objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableDate variables in the objectheader
    360     if(it->second->doSelection(HEADER->id)){
     364    if ( object->doSelection(HEADER->id) ){
    361365      newobjectheader->dataAvailable=true; //TODO: probably not neccessary
    362366      while(objectOffset<objectsize){
    363         *(newdata + objectOffset)=*(origdata + objectOffset);    // copy the data
     367        *(newdata + objectOffset)=*(data_ + (*it).objDataOffset + objectOffset);    // copy the data
    364368        objectOffset++;
    365369      }
     
    367371      newobjectheader->dataAvailable=false;
    368372      while(objectOffset<objectsize){
    369         *(newdata+objectOffset)=0;    // set to 0
     373        *(data_ + (*it).objDataOffset + objectOffset)=0;    // set to 0
    370374        objectOffset++;
    371375      }
     
    373377    }
    374378    newdata += objectsize;
    375     origdata += objectsize;
     379//     origdata += objectsize;
    376380  }
    377381  return gs;
     
    389393
    390394  //preparations
    391   std::map<unsigned int, Synchronisable *>::iterator it;
     395  std::vector<obj>::iterator it;
    392396  uint8_t *origdata, *basedata, *destdata, *ndata;
    393397  unsigned int objectOffset, streamOffset=0;    //data offset
     
    395399  synchronisableHeader *origheader;
    396400  synchronisableHeader *destheader;
     401  Synchronisable *object;
    397402
    398403  origdata = GAMESTATE_START(this->data_);
     
    404409  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
    405410    assert(streamOffset<HEADER->datasize);
    406     bool sendData = it->second->doSelection(HEADER->id);
    407411    origheader = (synchronisableHeader *)(origdata+streamOffset);
    408412    destheader = (synchronisableHeader *)(destdata+streamOffset);
     413    object = Synchronisable::getSynchronisable(origheader->objectID);
     414    bool sendData = object->doSelection(HEADER->id);
    409415
    410416    //copy and partially diff the object header
     
    457463
    458464  //preparations
    459   std::map<unsigned int, Synchronisable *>::iterator it;
     465  std::vector<obj>::iterator it;
    460466  uint8_t *origdata, *basedata, *destdata, *ndata;
    461467  unsigned int objectOffset, streamOffset=0;    //data offset
     
    463469  synchronisableHeader *origheader;
    464470  synchronisableHeader *destheader;
     471  Synchronisable *object;
    465472
    466473  origdata = GAMESTATE_START(this->data_);
     
    474481    origheader = (synchronisableHeader *)(origdata+streamOffset);
    475482    destheader = (synchronisableHeader *)(destdata+streamOffset);
     483    object = Synchronisable::getSynchronisable( origheader->objectID );
    476484    bool sendData;
    477485
  • code/branches/network/src/network/packet/Gamestate.h

    r1916 r2351  
    3535#include "Packet.h"
    3636#include "network/Synchronisable.h"
     37#include "network/TrafficControl.h"
    3738#include <map>
     39#include <vector>
    3840#ifndef NDEBUG
    3941#include "util/CRC32.h"
     
    7981    Gamestate *undiff(Gamestate *base);
    8082    Gamestate* intelligentUnDiff(Gamestate *base);
    81     Gamestate* doSelection(unsigned int clientID);
     83    Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
    8284    bool compressData();
    8385    bool decompressData();
     
    9294    unsigned int calcGamestateSize(unsigned int id, int mode=0x0);
    9395    void removeObject(orxonox::ObjectListIterator<Synchronisable> &it);
    94     std::map<unsigned int, Synchronisable*> dataMap_;
     96    std::vector<obj> dataMap_;
    9597};
    9698
Note: See TracChangeset for help on using the changeset viewer.