Changeset 1173
- Timestamp:
- Apr 24, 2008, 3:24:19 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network3/src/network/GameStateManager.cc
r1168 r1173 129 129 retval->id=id++; 130 130 COUT(4) << "G.ST.Man: producing gamestate with id: " << retval->id << std::endl; 131 // reserve a little memory and increase it later on132 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 136 131 // 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; 138 144 // go through all Synchronisables 139 145 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;142 146 //get size of the synchronisable 143 147 tempsize=it->getSize(); 144 //COUT(5) << "size of temp gamestate: " << tempsize << std::endl;145 //COUT(2) << "size of synchronisable: " << tempsize << std::endl;146 148 // add place for data and 3 ints (length,classid,objectid) 147 149 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;151 150 // allocate additional space 152 151 if((totalsize+tempsize) > memsize){ 153 152 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; 162 161 } 163 162 164 163 // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length) 165 164 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)); 172 168 // increase data pointer 173 169 offset+=tempsize+3*sizeof(int); 174 //std::cout << "end inner loop" << std::endl;175 170 } 176 171 retval->size=totalsize; … … 179 174 //std::cout << "end snapShot" << std::endl; 180 175 COUT(5) << "G.ST.Man: Gamestate size: " << totalsize << std::endl; 176 COUT(5) << "G.ST.Man: 'estimated' Gamestate size: " << size << std::endl; 181 177 return retval; 182 178 }
Note: See TracChangeset
for help on using the changeset viewer.