Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1173


Ignore:
Timestamp:
Apr 24, 2008, 3:24:19 PM (17 years ago)
Author:
scheusso
Message:

changed some things

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network3/src/network/GameStateManager.cc

    r1168 r1173  
    129129    retval->id=id++;
    130130    COUT(4) << "G.ST.Man: producing gamestate with id: " << retval->id << std::endl;
    131     // reserve a little memory and increase it later on
    132     COUT(5) << "G.ST.Man: mallocing: " << memsize << std::endl;
    133     retval->data = (unsigned char*)malloc(memsize);
    134     COUT(5) << "G.ST.Man: malloced: " << memsize << std::endl;
    135 
    136131    // offset of memory functions
    137     int offset=0;
     132    int offset=0, size=0;
     133    // get total size of gamestate
     134    for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     135      size+=it->getSize();
     136      size+=3*sizeof(int);
     137    }
     138    retval->data = (unsigned char*)malloc(size);
     139    if(!retval->data){
     140      COUT(2) << "GameStateManager: could not allocate memory" << std::endl;
     141      return NULL;
     142    }
     143    memsize=size;
    138144    // go through all Synchronisables
    139145    for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
    140       //std::cout << "begin inner loop" << std::endl;
    141       //std::cout << "gamestatemanager: in for loop" << std::endl;
    142146      //get size of the synchronisable
    143147      tempsize=it->getSize();
    144       //COUT(5) << "size of temp gamestate: " << tempsize << std::endl;
    145       //COUT(2) << "size of synchronisable: " << tempsize << std::endl;
    146148      // add place for data and 3 ints (length,classid,objectid)
    147149      totalsize+=tempsize+3*sizeof(int);
    148       //std::cout << "totalsize: " << totalsize << std::endl;
    149       //COUT(5) << "G.St.Man: current totalsize=" << totalsize << std::endl;
    150       //COUT(5) << "G.St.Man: current it->classID=" << it->classID << " it->objectID=" << it->objectID << std::endl;
    151150      // allocate additional space
    152151      if((totalsize+tempsize) > memsize){
    153152        COUT(5) << "G.St.Man: need additional memory" << std::endl;
    154         if(tempsize < 1000){
    155           retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000);
    156           memsize+=1000;
    157         } else {
    158           retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000);
    159           memsize+=tempsize+1000;
    160         }
    161         COUT(5) << "G.St.Man: additional space allocation finished" << std::endl;
     153//         if(tempsize < 1000){
     154//           retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000);
     155//           memsize+=1000;
     156//         } else {
     157//           retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000);
     158//           memsize+=tempsize+1000;
     159//         }
     160//         COUT(5) << "G.St.Man: additional space allocation finished" << std::endl;
    162161      }
    163162
    164163      // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length)
    165164      sync=it->getData((retval->data)+offset+3*sizeof(int));
    166       memcpy(retval->data+offset, (void *)&sync.length, sizeof(int));
    167       //*(retval->data+offset)=sync.length;
    168       memcpy(retval->data+offset+sizeof(int), (void *)&sync.objectID, sizeof(int));
    169       //*(retval->data+offset+sizeof(int))=sync.objectID;
    170       memcpy(retval->data+offset+2*sizeof(int), (void *)&sync.classID, sizeof(int));
    171       //*(retval->data+offset+2*sizeof(int))=sync.classID;
     165      memcpy(retval->data+offset, (void *)&(sync.length), sizeof(int));
     166      memcpy(retval->data+offset+sizeof(int), (void *)&(sync.objectID), sizeof(int));
     167      memcpy(retval->data+offset+2*sizeof(int), (void *)&(sync.classID), sizeof(int));
    172168      // increase data pointer
    173169      offset+=tempsize+3*sizeof(int);
    174       //std::cout << "end inner loop" << std::endl;
    175170    }
    176171    retval->size=totalsize;
     
    179174    //std::cout << "end snapShot" << std::endl;
    180175    COUT(5) << "G.ST.Man: Gamestate size: " << totalsize << std::endl;
     176    COUT(5) << "G.ST.Man: 'estimated' Gamestate size: " << size << std::endl;
    181177    return retval;
    182178  }
Note: See TracChangeset for help on using the changeset viewer.