Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 10, 2008, 12:05:03 AM (15 years ago)
Author:
landauf
Message:

merged revisions 2111-2170 from objecthierarchy branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/network/packet/Gamestate.cc

    r2087 r2171  
    3838
    3939
    40 namespace network {
     40namespace orxonox {
    4141
    4242namespace packet {
     
    7171}
    7272
    73 bool Gamestate::collectData(int id, int mode)
    74 {
    75   int tempsize=0, currentsize=0;
     73bool Gamestate::collectData(int id, uint8_t mode)
     74{
     75  unsigned int tempsize=0, currentsize=0;
    7676  assert(data_==0);
    77   int size = calcGamestateSize(id, mode);
     77  unsigned int size = calcGamestateSize(id, mode);
    7878
    7979  COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
     
    8686  }
    8787
    88 #ifndef NDEBUG
    89   std::list<Synchronisable*> slist;
    90   std::list<Synchronisable*>::iterator iit;
    91 #endif
    9288  //start collect data synchronisable by synchronisable
    9389  uint8_t *mem=data_;
    9490  mem+=sizeof(GamestateHeader);
    95   orxonox::ObjectList<Synchronisable>::iterator it;
    96   for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
     91  ObjectList<Synchronisable>::iterator it;
     92  for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    9793    tempsize=it->getSize(id, mode);
    9894
    9995    if(currentsize+tempsize > size){
     96      assert(0); // if we don't use multithreading this part shouldn't be neccessary
    10097      // start allocate additional memory
    10198      COUT(3) << "G.St.Man: need additional memory" << std::endl;
    102       orxonox::ObjectList<Synchronisable>::iterator temp = it;
     99      ObjectList<Synchronisable>::iterator temp = it;
    103100      int addsize=tempsize;
    104101      while(++temp)
     
    110107    }// stop allocate additional memory
    111108
    112 #ifndef NDEBUG
    113     for(iit=slist.begin(); iit!=slist.end(); iit++)
    114       assert((*iit)!=*it);
    115     slist.push_back(*it);
    116 #endif
    117109
    118110    //if(it->doSelection(id))
     
    127119  //start write gamestate header
    128120  HEADER->packetType = ENUM::Gamestate;
    129   assert( *(ENUM::Type *)(data_) == ENUM::Gamestate);
    130121  HEADER->datasize = currentsize;
    131122  HEADER->id = id;
     
    140131}
    141132
    142 bool Gamestate::spreadData(int mode)
     133bool Gamestate::spreadData(uint8_t mode)
    143134{
    144135  assert(data_);
     
    147138  uint8_t *mem=data_+sizeof(GamestateHeader);
    148139    // get the start of the Synchronisable list
    149   //orxonox::ObjectList<Synchronisable>::iterator it=orxonox::ObjectList<Synchronisable>::begin();
     140  //ObjectList<Synchronisable>::iterator it=ObjectList<Synchronisable>::begin();
    150141  Synchronisable *s;
    151142
     
    163154      bool b = s->updateData(mem, mode);
    164155      assert(b);
    165       //if(!s->updateData(mem, mode))
    166         //return false;
    167156    }
    168157  }
     
    367356    assert(it->second->objectID==oldobjectheader->objectID);
    368357    *newobjectheader = *oldobjectheader;
    369     objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableData variables in the objectheader
     358    objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader
    370359    if(it->second->doSelection(HEADER->id)){
    371       newobjectheader->dataAvailable=true; //TODO: probably not neccessary
    372       while(objectOffset<objectsize){
    373         *(newdata + objectOffset)=*(origdata + objectOffset);    // copy the data
    374         objectOffset++;
    375       }
     360      assert(newobjectheader->dataAvailable==true);
     361      memcpy(newdata+objectOffset, origdata+objectOffset, objectsize-objectOffset);
    376362    }else{
    377363      newobjectheader->dataAvailable=false;
    378       while(objectOffset<objectsize){
    379         *(newdata+objectOffset)=0;    // set to 0
    380         objectOffset++;
    381       }
     364      memset(newdata+objectOffset, 0, objectsize-objectOffset);
    382365      assert(objectOffset==objectsize);
    383366    }
     
    565548
    566549
    567 unsigned int Gamestate::calcGamestateSize(unsigned int id, int mode)
    568 {
    569   int size=0;
     550unsigned int Gamestate::calcGamestateSize(unsigned int id, uint8_t mode)
     551{
     552  unsigned int size=0;
    570553    // get the start of the Synchronisable list
    571   orxonox::ObjectList<Synchronisable>::iterator it;
     554  ObjectList<Synchronisable>::iterator it;
    572555    // get total size of gamestate
    573   for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it)
     556  for(it = ObjectList<Synchronisable>::begin(); it; ++it)
    574557    size+=it->getSize(id, mode); // size of the actual data of the synchronisable
    575558//  size+=sizeof(GamestateHeader);
     
    582565 * @return iterator pointing to the next object in the list
    583566 */
    584   void Gamestate::removeObject(orxonox::ObjectList<Synchronisable>::iterator &it) {
    585     orxonox::ObjectList<Synchronisable>::iterator temp=it;
     567  void Gamestate::removeObject(ObjectList<Synchronisable>::iterator &it) {
     568    ObjectList<Synchronisable>::iterator temp=it;
    586569    ++it;
    587570    delete  *temp;
Note: See TracChangeset for help on using the changeset viewer.