Changeset 2351 for code/branches/network
- Timestamp:
- Dec 7, 2008, 10:57:09 PM (16 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/ClientInformation.h
r2009 r2351 45 45 #include <enet/enet.h> 46 46 #include <boost/thread/recursive_mutex.hpp> 47 47 48 48 49 // WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE -
code/branches/network/src/network/GamestateManager.cc
r2341 r2351 134 134 if(!reference) 135 135 return 0; 136 gs = reference->doSelection(clientID); 136 gs = reference->doSelection(clientID, 10000); 137 // gs = new packet::Gamestate(*reference); 137 138 // save the (undiffed) gamestate in the clients gamestate map 138 139 gamestateMap_[clientID].insert(std::pair<int, packet::Gamestate*>(gs->getID(), gs)); -
code/branches/network/src/network/Synchronisable.h
r2348 r2351 113 113 114 114 inline unsigned int getObjectID(){return objectID;} 115 inline unsigned int getCreatorID(){return creatorID;} 115 116 inline unsigned int getClassID(){return classID;} 116 117 inline unsigned int getPriority(){ return objectFrequency_;} -
code/branches/network/src/network/TrafficControl.cc
r2348 r2351 31 31 #include <cassert> 32 32 #include <boost/bind.hpp> 33 #include "Synchronisable.h"34 #include "ClientInformation.h"35 33 36 34 namespace network { … … 86 84 assert(clientListPerm_[clientID].find(j.objID) != clientListPerm_[clientID].end()); // make sure the object j is in the client list 87 85 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; 89 90 } 90 91 91 92 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) 93 94 { 94 copiedVector = *list;95 // copiedVector = *list; 95 96 currentClientID=clientID; 96 97 currentGamestateID=gamestateID; 97 98 evaluateList(clientID, list); 98 99 //list hatte vorher ja vielmehr elemente, nach zuweisung nicht mehr... speicherplatz?? 99 *list=copiedVector;100 // *list=copiedVector; 100 101 //später wird copiedVector ja überschrieben, ist das ein problem für list-dh. für gamestatemanager? 101 return list;102 return; 102 103 } 103 104 … … 212 213 std::vector<obj>::iterator itvec; 213 214 itvec = list->begin(); 214 // unsigned int i=0;215 215 for(itvec = list->begin(); itvec != list->end() && size<targetsize; itvec++) 216 // while(size<targetsize && (itvec!=list.end()))217 216 { 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 } 221 226 } 222 list->erase(itvec, list->end());223 227 } 224 228 … … 235 239 //compare listToProcess vs clientListPerm 236 240 //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; 238 242 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; 240 244 // std::map<unsigned int, objInfo>::iterator itpermobj; 241 unsigned int permprio;242 245 for( itvec=list->begin(); itvec != list->end(); itvec++) 243 246 { 244 itperm = clientListPerm_.find(clientID);247 // itperm = clientListPerm_.find(clientID); 245 248 if ( clientListPerm_[clientID].find( (*itvec).objID) != clientListPerm_[clientID].end() ) 246 249 { … … 306 309 // use boost bind here because we need to pass a memberfunction to stl sort 307 310 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; 309 314 for(itvec = list->begin(); itvec != list->end(); itvec++) 310 315 { 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 } 319 332 } 320 333 //end of sorting 321 334 //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); 323 336 //diese Funktion updateClientList muss noch gemacht werden 324 337 updateClientListTemp(list); 325 338 //end of sorting 326 339 } 327 328 340 329 341 -
code/branches/network/src/network/TrafficControl.h
r2348 r2351 37 37 #include "NetworkPrereqs.h" 38 38 #include "Synchronisable.h" 39 #include "ClientInformation.h" 39 40 #include "util/Integers.h" 40 41 … … 48 49 uint32_t objID; 49 50 uint32_t objCreatorID; 50 int32_t objCurGS;//current GameState ID51 int32_t objDiffGS;//difference between current and latest GameState51 uint32_t objCurGS;//current GameState ID 52 uint32_t objDiffGS;//difference between current and latest GameState 52 53 uint32_t objSize; 53 54 unsigned int objValuePerm; … … 55 56 objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched) 56 57 { 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; } 57 60 }; 58 61 … … 62 65 struct obj 63 66 { 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; } 67 75 }; 68 76 77 78 const unsigned int SCHED_PRIORITY_OFFSET = -5; 69 79 70 80 … … 88 98 *creates list (typ map) that contains objids, struct with info concerning object(objid) 89 99 */ 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 GS100 // 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 91 101 /** 92 102 *permanent client list: contains client ids, object ids and objectInfos (in this order) … … 118 128 *copiedVector is a copy of the given Vector by the GSmanager, on this vector all manipulations are performed 119 129 */ 120 std::vector<obj> copiedVector;130 // std::vector<obj> copiedVector; 121 131 122 132 // void updateReferenceList(std::map<unsigned int, objInfo> *list);//done … … 132 142 *evaluates Data given (vector) and produces result(->Data to be updated) 133 143 */ 134 void evaluateList(unsigned int clientID, std::vector<obj> *list);//done 144 void evaluateList(unsigned int clientID, std::vector<obj> *list);//done 135 145 136 146 protected: … … 146 156 *Elements of struct i are therefore: *list[i].objID 147 157 */ 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 it158 void processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj>* list); //gets a pointer to the vector (containing objectIDs) and sorts it 149 159 //done 150 160 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 117 117 118 118 //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 120 121 if(!it->getData(mem, id, mode)) 121 122 return false; // mem pointer gets automatically increased because of call by reference … … 333 334 } 334 335 335 Gamestate* Gamestate::doSelection(unsigned int clientID ){336 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){ 336 337 assert(data_); 337 std:: map<unsigned int, Synchronisable *>::iterator it;338 std::vector<obj>::iterator it; 338 339 339 340 // allocate memory for new data … … 342 343 Gamestate *gs = new Gamestate(gdata); 343 344 uint8_t *newdata = gdata + sizeof(GamestateHeader); 344 uint8_t *origdata = GAMESTATE_START(data_);345 // uint8_t *origdata = GAMESTATE_START(data_); 345 346 346 347 //copy the GamestateHeader … … 349 350 synchronisableHeader *oldobjectheader, *newobjectheader; 350 351 unsigned int objectOffset; 352 unsigned int objectsize; 353 Synchronisable *object; 351 354 352 355 //copy in the zeros 353 356 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ 354 oldobjectheader = (synchronisableHeader*) origdata;357 oldobjectheader = (synchronisableHeader*)(data_ + (*it).objDataOffset); 355 358 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); 358 362 *newobjectheader = *oldobjectheader; 359 363 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) ){ 361 365 newobjectheader->dataAvailable=true; //TODO: probably not neccessary 362 366 while(objectOffset<objectsize){ 363 *(newdata + objectOffset)=*( origdata+ objectOffset); // copy the data367 *(newdata + objectOffset)=*(data_ + (*it).objDataOffset + objectOffset); // copy the data 364 368 objectOffset++; 365 369 } … … 367 371 newobjectheader->dataAvailable=false; 368 372 while(objectOffset<objectsize){ 369 *( newdata+objectOffset)=0; // set to 0373 *(data_ + (*it).objDataOffset + objectOffset)=0; // set to 0 370 374 objectOffset++; 371 375 } … … 373 377 } 374 378 newdata += objectsize; 375 origdata += objectsize;379 // origdata += objectsize; 376 380 } 377 381 return gs; … … 389 393 390 394 //preparations 391 std:: map<unsigned int, Synchronisable *>::iterator it;395 std::vector<obj>::iterator it; 392 396 uint8_t *origdata, *basedata, *destdata, *ndata; 393 397 unsigned int objectOffset, streamOffset=0; //data offset … … 395 399 synchronisableHeader *origheader; 396 400 synchronisableHeader *destheader; 401 Synchronisable *object; 397 402 398 403 origdata = GAMESTATE_START(this->data_); … … 404 409 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ 405 410 assert(streamOffset<HEADER->datasize); 406 bool sendData = it->second->doSelection(HEADER->id);407 411 origheader = (synchronisableHeader *)(origdata+streamOffset); 408 412 destheader = (synchronisableHeader *)(destdata+streamOffset); 413 object = Synchronisable::getSynchronisable(origheader->objectID); 414 bool sendData = object->doSelection(HEADER->id); 409 415 410 416 //copy and partially diff the object header … … 457 463 458 464 //preparations 459 std:: map<unsigned int, Synchronisable *>::iterator it;465 std::vector<obj>::iterator it; 460 466 uint8_t *origdata, *basedata, *destdata, *ndata; 461 467 unsigned int objectOffset, streamOffset=0; //data offset … … 463 469 synchronisableHeader *origheader; 464 470 synchronisableHeader *destheader; 471 Synchronisable *object; 465 472 466 473 origdata = GAMESTATE_START(this->data_); … … 474 481 origheader = (synchronisableHeader *)(origdata+streamOffset); 475 482 destheader = (synchronisableHeader *)(destdata+streamOffset); 483 object = Synchronisable::getSynchronisable( origheader->objectID ); 476 484 bool sendData; 477 485 -
code/branches/network/src/network/packet/Gamestate.h
r1916 r2351 35 35 #include "Packet.h" 36 36 #include "network/Synchronisable.h" 37 #include "network/TrafficControl.h" 37 38 #include <map> 39 #include <vector> 38 40 #ifndef NDEBUG 39 41 #include "util/CRC32.h" … … 79 81 Gamestate *undiff(Gamestate *base); 80 82 Gamestate* intelligentUnDiff(Gamestate *base); 81 Gamestate* doSelection(unsigned int clientID );83 Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); 82 84 bool compressData(); 83 85 bool decompressData(); … … 92 94 unsigned int calcGamestateSize(unsigned int id, int mode=0x0); 93 95 void removeObject(orxonox::ObjectListIterator<Synchronisable> &it); 94 std:: map<unsigned int, Synchronisable*> dataMap_;96 std::vector<obj> dataMap_; 95 97 }; 96 98
Note: See TracChangeset
for help on using the changeset viewer.