Changeset 2533 for code/branches/bugger/src/network
- Timestamp:
- Dec 23, 2008, 11:34:35 PM (17 years ago)
- Location:
- code/branches/bugger
- Files:
-
- 11 edited
-
. (modified) (1 prop)
-
src/network/NetworkPrereqs.h (modified) (3 diffs)
-
src/network/Server.cc (modified) (1 diff)
-
src/network/Server.h (modified) (1 diff)
-
src/network/TrafficControl.cc (modified) (15 diffs, 1 prop)
-
src/network/TrafficControl.h (modified) (6 diffs, 1 prop)
-
src/network/packet/Gamestate.cc (modified) (3 diffs)
-
src/network/synchronisable/NetworkCallbackManager.cc (modified) (1 prop)
-
src/network/synchronisable/NetworkCallbackManager.h (modified) (1 prop)
-
src/network/synchronisable/Synchronisable.cc (modified) (4 diffs)
-
src/network/synchronisable/Synchronisable.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
code/branches/bugger
- Property svn:mergeinfo changed
/code/branches/lodfinal (added) merged: 2372,2380,2388,2394-2395,2402,2411
- Property svn:mergeinfo changed
-
code/branches/bugger/src/network/NetworkPrereqs.h
r2531 r2533 61 61 #include "util/Integers.h" 62 62 63 //----------------------------------------------------------------------- 64 // Library global contants 65 //----------------------------------------------------------------------- 66 namespace orxonox 67 { 68 static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1; 69 static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2; 70 static const uint32_t OBJECTID_UNKNOWN = (uint32_t)(-1); 71 } 63 72 64 73 //----------------------------------------------------------------------- … … 67 76 namespace orxonox 68 77 { 69 70 // Constants definition71 72 static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;73 static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2;74 static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1);75 static const unsigned int SCHED_PRIORITY_OFFSET = -5;76 77 78 79 80 78 class Client; 81 79 class ClientConnection; … … 103 101 class obj; 104 102 class objInfo; 105 namespace packet{ 103 104 namespace packet 105 { 106 106 class Gamestate; 107 107 class Packet; -
code/branches/bugger/src/network/Server.cc
r2171 r2533 63 63 { 64 64 const unsigned int MAX_FAILURES = 20; 65 const unsigned int NETWORK_FREQUENCY = 25;66 const float NETWORK_PERIOD = (float)1/NETWORK_FREQUENCY;67 65 68 66 /** -
code/branches/bugger/src/network/Server.h
r2171 r2533 52 52 { 53 53 const int CLIENTID_SERVER = 0; 54 const unsigned int NETWORK_FREQUENCY = 25; 55 const float NETWORK_PERIOD = 1./NETWORK_FREQUENCY; 54 56 55 57 /** -
code/branches/bugger/src/network/TrafficControl.cc
- Property svn:eol-style set to native
r2532 r2533 36 36 37 37 namespace orxonox { 38 39 static const unsigned int SCHED_PRIORITY_OFFSET = -1; 38 40 39 41 objInfo::objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched) … … 68 70 TrafficControl::TrafficControl() 69 71 { 70 Register RootObject(TrafficControl);72 RegisterObject(TrafficControl); 71 73 assert(instance_==0); 72 74 instance_=this; 73 // targetSize = 2500;//5000bytes 74 SetConfigValue ( targetSize, 28000./25. ); 75 this->setConfigValues(); 75 76 } 76 77 … … 79 80 */ 80 81 TrafficControl::~TrafficControl() 81 { 82 //was macht das genau? da instance ja gleich this ist im moment 82 { 83 83 instance_=0; 84 //muss ich alles deallozieren was ich im constructor aufgebaut habe?85 84 } 86 85 … … 89 88 */ 90 89 90 void TrafficControl::setConfigValues() 91 { 92 SetConfigValue ( bActive_, true ); 93 SetConfigValue ( targetSize, 5000 ); 94 } 95 91 96 /** 92 *eigener sortieralgorithmus97 * sort-algorithm for sorting the objectlist after priorities 93 98 */ 94 // bool TrafficControl::priodiffer(obj i, obj j) 95 // { 96 // std::map<unsigned int, objInfo>::iterator iti; 97 // std::map<unsigned int, objInfo>::iterator itj; 98 // iti=listToProcess_.find(i.objID); 99 // itj=listToProcess_.find(j.objID); 100 // return iti->second.objValuePerm < itj->second.objValuePerm; 101 // } 102 103 /** 104 * eigener sortieralgorithmus 105 */ 106 bool TrafficControl::priodiffer(uint32_t clientID, obj i, obj j) 99 bool TrafficControl::prioritySort(uint32_t clientID, obj i, obj j) 107 100 { 108 101 assert(clientListPerm_.find(clientID) != clientListPerm_.end()); //make sure the client exists in our list … … 112 105 int prio1 = clientListPerm_[clientID][i.objID].objValuePerm + clientListPerm_[clientID][i.objID].objValueSched; 113 106 int prio2 = clientListPerm_[clientID][j.objID].objValuePerm + clientListPerm_[clientID][j.objID].objValueSched; 114 // int prio1 = clientListPerm_[clientID][i.objID].objID;115 // int prio2 = clientListPerm_[clientID][j.objID].objID;116 // NOTE: smaller priority is better117 107 return prio1 < prio2; 118 108 } 119 109 110 /** 111 * sort-algorithm for sorting the objectList after position in original data stream 112 */ 113 bool TrafficControl::dataSort(obj i, obj j) 114 { 115 int pos1 = i.objDataOffset; 116 int pos2 = j.objDataOffset; 117 return pos1 < pos2; 118 } 119 120 120 121 121 122 void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj> *list) … … 125 126 currentGamestateID=gamestateID; 126 127 evaluateList(clientID, list); 127 //list hatte vorher ja vielmehr elemente, nach zuweisung nicht mehr... speicherplatz??128 // *list=copiedVector;129 //später wird copiedVector ja überschrieben, ist das ein problem für list-dh. für gamestatemanager?130 128 return; 131 129 } … … 169 167 *Definition of private members 170 168 */ 171 172 173 /** 174 *copyList gets list of Gamestate Manager and turns it to *listToProcess 175 */ 176 // void TrafficControl::copyList(std::list<obj> *list) 177 // { 178 // std::list<obj>::iterator itvec; 179 // for(itvec = (*list).begin(); itvec != (*list).end(); itvec++) 180 // { 181 // objInfo objectA; 182 // objectA.objCreatorID=(*itvec).objCreatorID; 183 // objectA.objSize = (*itvec).objSize; 184 // listToProcess_.insert(std::pair<currentClientID, map<(*itvec).objID,objectA>>);//unsicher: ob map<...> so richtig ist 185 // } 186 // } 187 /** 188 *updateReferenceList compares the sent list by GSmanager with the current *reference list and updates it. 189 *returns void 190 */ 191 // void TrafficControl::updateReferenceList(std::map<unsigned int, objInfo> *list) 192 // { 193 // std::map<unsigned int, Synchronisable*>::iterator itref; 194 // std::map<unsigned int, objInfo>::iterator itproc; 195 // for(itproc=listToProcess_.begin(); itproc != listToProcess_.end(); itproc++) 196 // { 197 // //itproc->first=objectid that is looked for 198 // if(referenceList_->find(itproc->first)) 199 // { 200 // continue; 201 // } 202 // else 203 // { 204 // (*referenceList_).insert(pair<unsigned int, Synchronisable*>((*itproc).first,Synchronisable::getSynchronisable((*itproc).first)));//important: how to get adress of an object! 205 // insertinClientListPerm(currentClientID,itproc->first,itproc->second); 206 // } 207 // } 208 // } 169 209 170 /** 210 171 *updateClientListPerm … … 229 190 { 230 191 clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(*list); 231 // std::list<obj>::iterator itvec;232 // std::map<unsigned int,std::map<unsigned int, obj> >::iterator ittemp;233 // std::map<unsigned int, obj>::iterator ittempgs;234 // ittemp = clientListTemp_.find(currentClientID);235 // ittempgs = (*ittemp).find(currentGamestateID);236 // for(itvec = list.begin(); itvec!=list.end(), itvec++)237 // {238 // ittempgs.insert(itvec);static239 // }240 192 } 241 193 … … 252 204 { 253 205 assert( (*itvec).objSize < 1000); 254 // COUT(0) << "==targetsize== " << targetsize << endl;255 206 if ( ( size + (*itvec).objSize ) < targetsize ) 256 207 { 257 // COUT(0) << "no cut" << endl;258 208 size += (*itvec).objSize;//objSize is given in bytes 259 209 ++itvec; … … 261 211 else 262 212 { 263 // COUT(0) << "cut" << endl;264 213 clientListPerm_[currentClientID][(*itvec).objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative 265 // ittemp = itvec;266 214 list->erase(itvec++); 267 // itvec = ittemp;268 215 } 269 216 // printList(list, currentClientID); … … 278 225 void TrafficControl::evaluateList(unsigned int clientID, std::list<obj> *list) 279 226 { 280 //copyList(list);281 227 282 228 //now the sorting … … 284 230 //compare listToProcess vs clientListPerm 285 231 //if listToProcess contains new Objects, add them to clientListPerm 286 // std::map<unsigned int, objInfo>::iterator itproc;287 232 std::list<obj>::iterator itvec; 288 // std::map<unsigned int, std::map<unsigned int, objInfo> >::iterator itperm;289 // std::map<unsigned int, objInfo>::iterator itpermobj;290 233 for( itvec=list->begin(); itvec != list->end(); itvec++) 291 234 { 292 // itperm = clientListPerm_.find(clientID);293 235 if ( clientListPerm_[clientID].find( (*itvec).objID) != clientListPerm_[clientID].end() ) 294 236 { … … 296 238 //obj bleibt in liste und permanente prio wird berechnet 297 239 clientListPerm_[clientID][(*itvec).objID].objDiffGS = currentGamestateID - clientListPerm_[clientID][(*itvec).objID].objCurGS; 298 // ((*itpermobj).second).objDiffGS = ((*itpermobj).second).objCurGS - currentGamestateID;299 // permprio = clientListPerm_[clientID][(*itproc).first].objValuePerm;300 // itpermprio = (permObjPrio_).find((*itproc).first);301 // ((*itpermobj).second).objValuePerm = ((*itpermobj).second).objDiffGS * (*itpermprio).second;302 240 continue;//check next objId 303 241 } … … 306 244 // insert the object into clientListPerm 307 245 insertinClientListPerm(clientID,*itvec); 308 // itpermobj=(*itperm).find((*itproc).first)309 // ((*itpermobj).second).objDiffGS = ((*itpermobj).second).objCurGS - currentGamestateID;310 // itpermprio = (permObjPrio_).find((*itproc).first);311 // ((*itpermobj).second).objValuePerm = ((*itpermobj).second).objDiffGS * (*itpermprio).second;312 246 continue;//check next objId 313 247 } 314 248 } 315 249 //end compare listToProcess vs clientListPerm 316 317 //listToProc vs clientListTemp 318 //TODO: uncomment it again and change some things 319 /* 320 std::map<unsigned int, std::map<unsigned int, unsigned int> >::iterator ittemp; 321 std::map<unsigned int, unsigned int>::iterator ittempgs; 322 for( itproc=listToProcess_.begin(); itproc != listToProcess_.end();itproc++) 250 251 if( bActive_ ) 323 252 { 324 ittemp = clientListTemp_->find(currentClientID); 325 if( ittempgs = (*ittemp).find(currentGamestateID)) 326 { 327 if((*itproc).first == (*ittempgs).find((*itproc).first))//ja, dann ist objekt schon in der zu sendenden liste-muss nicht nochmal gesendet werden 328 { 329 (listToProcess_).erase (itproc); 330 } 331 else 332 continue; 333 } 334 else 335 continue; 336 }*/ 337 //end listToProc vs clientListTemp 338 339 //TODO: check whether we need this, cause i don't think so. 340 //listToProcess contains obj to send now, and since we give gsmanager the copiedlist and not listToProcess shorten copiedlist therefor too. 341 /*std::list<obj>::iterator itvec; 342 for(itvec = copiedVector.begin(); itvec != copiedVector.end(); itvec++) 343 { 344 if ( listToProcess_.find(itvec->objID) ) 345 { 346 continue;//therefore object wasnt thrown out yet and has to be sent back to gsmanager 347 } 348 else 349 { 350 copiedVector.remove(itvec); 351 } 352 }*/ 353 //sort copied list aufgrund der objprioperm in clientlistperm 354 // use boost bind here because we need to pass a memberfunction to stl sort 355 list->sort(boost::bind(&TrafficControl::priodiffer, this, clientID, _1, _2) ); 356 357 //now we check, that the creator of an object always exists on a client 358 // printList(list, clientID); 359 std::list<obj>::iterator itcreator; 360 for(itvec = list->begin(); itvec != list->end(); itvec++) 361 { 362 fixCreatorDependencies(itvec, list, clientID); 253 //sort copied list according to priorities 254 // use boost bind here because we need to pass a memberfunction to stl sort 255 list->sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) ); 256 257 //now we check, that the creator of an object always exists on a client 258 std::list<obj>::iterator itcreator; 259 for(itvec = list->begin(); itvec != list->end(); itvec++) 260 { 261 fixCreatorDependencies(itvec, list, clientID); 262 } 263 //end of sorting 264 //now the cutting, work the same obj out in processobjectlist and copiedlist, compression rate muss noch festgelegt werden. 265 // printList(list, clientID); 266 cut(list, targetSize); 267 268 //now sort again after objDataOffset 269 list->sort(boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 363 270 } 364 //end of sorting365 //now the cutting, work the same obj out in processobjectlist and copiedlist, compression rate muss noch festgelegt werden.366 cut(list, targetSize);367 // printList(list, clientID);368 271 //diese Funktion updateClientList muss noch gemacht werden 369 272 updateClientListTemp(list); … … 398 301 } 399 302 } 400 401 402 /* 403 void bvlabla(list *a){ 404 //sort a 405 list *cache; 406 cache = new list<unsigned int>(*a); 407 return a; 408 } 409 */ 303 304 void TrafficControl::clientDisconnected(unsigned int clientID) 305 { 306 assert(clientListTemp_.find(clientID) != clientListTemp_.end() ); 307 assert(clientListPerm_.find(clientID) != clientListPerm_.end() ); 308 clientListTemp_.erase(clientListTemp_.find(clientID)); 309 clientListPerm_.erase(clientListPerm_.find(clientID)); 310 } 410 311 411 312 -
code/branches/bugger/src/network/TrafficControl.h
- Property svn:eol-style set to native
r2532 r2533 38 38 #include "util/Integers.h" 39 39 #include "core/OrxonoxClass.h" 40 #include "network/ClientConnectionListener.h" 40 41 41 42 namespace orxonox { … … 79 80 * 80 81 */ 81 class TrafficControl : public OrxonoxClass{82 class TrafficControl : public ClientConnectionListener { 82 83 private: 83 84 … … 122 123 unsigned int currentClientID; 123 124 unsigned int targetSize; 125 bool bActive_; 124 126 /** 125 127 *copiedVector is a copy of the given Vector by the GSmanager, on this list all manipulations are performed … … 141 143 void evaluateList(unsigned int clientID, std::list<obj> *list);//done 142 144 void ack(unsigned int clientID, unsigned int gamestateID); // this function gets called when the server receives an ack from the client 145 146 //ClientConnectionListener functions 147 virtual void clientConnected(unsigned int clientID){}; 148 virtual void clientDisconnected(unsigned int clientID); 143 149 150 144 151 protected: 145 152 static TrafficControl *instance_; … … 154 161 *Elements of struct i are therefore: *list[i].objID 155 162 */ 163 void setConfigValues(); 156 164 static TrafficControl *getInstance(); 157 165 void processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>* list); //gets a pointer to the list (containing objectIDs) and sorts it … … 162 170 void deleteObject(unsigned int objectID); // this function gets called when an object has been deleted (in order to clean up lists and maps) 163 171 164 bool priodiffer(uint32_t clientID, obj i, obj j); 172 bool prioritySort(uint32_t clientID, obj i, obj j); 173 bool dataSort(obj i, obj j); 165 174 void printList(std::list<obj> *list, unsigned int clientID); 166 175 void fixCreatorDependencies(std::list<obj>::iterator it, std::list<obj> *list, unsigned int clientID); -
code/branches/bugger/src/network/packet/Gamestate.cc
r2532 r2533 349 349 Gamestate *gs = new Gamestate(gdata); 350 350 uint8_t *newdata = gdata + sizeof(GamestateHeader); 351 //uint8_t *origdata = GAMESTATE_START(data_);351 uint8_t *origdata = GAMESTATE_START(data_); 352 352 353 353 //copy the GamestateHeader … … 357 357 uint32_t objectOffset; 358 358 unsigned int objectsize, destsize=0; 359 Synchronisable *object; 359 // TODO: Why is this variable not used? 360 //Synchronisable *object; 360 361 361 362 //call TrafficControl … … 366 367 if((*it).objSize==0) 367 368 continue; 368 oldobjectheader = (synchronisableHeader*) (data_ + (*it).objDataOffset);369 oldobjectheader = (synchronisableHeader*)origdata; 369 370 newobjectheader = (synchronisableHeader*)newdata; 370 object = Synchronisable::getSynchronisable( (*it).objID );371 assert(object->objectID == oldobjectheader->objectID);371 // object = Synchronisable::getSynchronisable( (*it).objID ); 372 // assert(object->objectID == oldobjectheader->objectID); 372 373 objectsize = oldobjectheader->size; 373 *newobjectheader = *oldobjectheader;374 374 objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader 375 if ( /*object->doSelection(HEADER->id)*/true ){ 375 if ( (*it).objID == oldobjectheader->objectID ){ 376 memcpy(newdata, origdata, objectsize); 376 377 assert(newobjectheader->dataAvailable==true); 377 memcpy(newdata+objectOffset, data_ + (*it).objDataOffset + objectOffset, objectsize-objectOffset);378 ++it; 378 379 }else{ 380 *newobjectheader = *oldobjectheader; 379 381 newobjectheader->dataAvailable=false; 380 382 memset(newdata+objectOffset, 0, objectsize-objectOffset); 381 assert(objectOffset==objectsize);382 383 } 383 384 newdata += objectsize; 385 origdata += objectsize; 384 386 destsize += objectsize; 385 387 // origdata += objectsize; 386 388 } 387 389 ((GamestateHeader*)gdata)->datasize = destsize; 390 assert(destsize==HEADER->datasize); 388 391 assert(destsize!=0); 389 392 return gs; -
code/branches/bugger/src/network/synchronisable/NetworkCallbackManager.cc
- Property svn:eol-style set to native
-
code/branches/bugger/src/network/synchronisable/NetworkCallbackManager.h
- Property svn:eol-style set to native
-
code/branches/bugger/src/network/synchronisable/Synchronisable.cc
r2531 r2533 66 66 RegisterRootObject(Synchronisable); 67 67 static uint32_t idCounter=0; 68 objectFrequency_=1;69 68 objectMode_=0x1; // by default do not send data to server 70 69 if ( !Host::running() || ( Host::running() && Host::isServer() ) ) … … 78 77 classID = static_cast<uint32_t>(-1); 79 78 80 81 //#ifndef NDEBUG 82 // ObjectList<Synchronisable>::iterator it; 83 // for(it = ObjectList<Synchronisable>::begin(); it!=ObjectList<Synchronisable>::end(); ++it){ 84 // if(!(*it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0))) 85 // { 86 // COUT(1) << "Assertion failed: *it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0)" << std::endl; 87 // COUT(1) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl; 88 // abort(); 89 // } 90 // } 91 //#endif 79 // set standard priority 80 this->setPriority( priority::normal ); 81 82 83 // get creator id 84 #ifndef NDEBUG 85 ObjectList<Synchronisable>::iterator it; 86 for(it = ObjectList<Synchronisable>::begin(); it!=ObjectList<Synchronisable>::end(); ++it){ 87 if( it->getObjectID()==this->objectID ) 88 if(!(*it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0))){ 89 COUT(1) << "Assertion failed: *it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0)" << std::endl; 90 COUT(1) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl; 91 abort(); 92 } 93 } 94 #endif 92 95 93 96 this->creatorID = OBJECTID_UNKNOWN; … … 177 180 { 178 181 mem += header->size; //.TODO: this suckz.... remove size from header 182 assert(0); 179 183 return 0; 180 184 } … … 360 364 //assert( (mode ^ objectMode_) != 0); 361 365 if(syncList.empty()){ 366 assert(0); 362 367 COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl; 363 368 return false; -
code/branches/bugger/src/network/synchronisable/Synchronisable.h
r2531 r2533 61 61 }; 62 62 } 63 64 namespace priority{ 65 enum prio{ 66 very_high = -100, 67 high = -15, 68 normal = 0, 69 low = 15, 70 very_low = 100 71 }; 72 } 63 73 64 74 struct _NetworkExport synchronisableHeader{ … … 101 111 template <class T> void unregisterVariable(T& var); 102 112 void setObjectMode(uint8_t mode); 103 void set ObjectPriority(unsigned int freq){ objectFrequency_ = freq; }113 void setPriority(unsigned int freq){ objectFrequency_ = freq; } 104 114 105 115
Note: See TracChangeset
for help on using the changeset viewer.










