- Timestamp:
- Dec 25, 2009, 1:18:03 PM (15 years ago)
- Location:
- code/branches/pickup2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup2
- Property svn:mergeinfo changed
-
code/branches/pickup2/src/libraries/network/TrafficControl.cc
r5781 r6412 64 64 *Initializing protected members 65 65 */ 66 67 68 69 70 71 72 66 TrafficControl *TrafficControl::instance_=0; 67 68 /** 69 * @brief Constructor: assures that only one reference will be created and sets the pointer 70 */ 71 TrafficControl::TrafficControl() 72 { 73 73 RegisterObject(TrafficControl); 74 75 74 assert(instance_==0); 75 instance_=this; 76 76 this->setConfigValues(); 77 78 79 80 81 82 83 84 85 77 } 78 79 /** 80 * @brief Destructor: resets the instance pointer to 0 81 */ 82 TrafficControl::~TrafficControl() 83 { 84 instance_=0; 85 } 86 86 87 87 /** … … 121 121 122 122 123 124 125 126 127 128 129 123 void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>& list) 124 { 125 currentClientID=clientID; 126 currentGamestateID=gamestateID; 127 evaluateList(clientID, list); 128 return; 129 } 130 130 131 131 TrafficControl *TrafficControl::getInstance() … … 135 135 } 136 136 137 138 137 void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID) 138 { 139 139 if ( !this->bActive_ ) 140 140 return; 141 141 std::list<obj>::iterator itvec; // iterator to iterate through the acked objects 142 142 143 143 //assertions to make sure the maps already exist … … 145 145 assert(clientListPerm_.find(clientID) != clientListPerm_.end() ); 146 146 assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() ); 147 147 148 148 // shortcut for maps 149 149 std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID]; … … 151 151 152 152 for(itvec = objectListTemp[gamestateID].begin(); itvec != objectListTemp[gamestateID].end(); itvec++) 153 154 if(objectListPerm.find( (*itvec).objID) != objectListPerm.end()) // check whether the obj already exists in our lists155 { 156 objectListPerm[ (*itvec).objID].objCurGS = gamestateID;157 objectListPerm[ (*itvec).objID].objValueSched = 0; //set scheduling value back153 { 154 if(objectListPerm.find(itvec->objID) != objectListPerm.end()) // check whether the obj already exists in our lists 155 { 156 objectListPerm[itvec->objID].objCurGS = gamestateID; 157 objectListPerm[itvec->objID].objValueSched = 0; //set scheduling value back 158 158 } 159 159 else 160 160 { 161 161 assert(0); 162 objectListPerm[ (*itvec).objID].objCurGS = gamestateID;163 objectListPerm[ (*itvec).objID].objID = (*itvec).objID;164 objectListPerm[ (*itvec).objID].objCreatorID = (*itvec).objCreatorID;165 objectListPerm[ (*itvec).objID].objSize = (*itvec).objSize;166 } 167 168 162 objectListPerm[itvec->objID].objCurGS = gamestateID; 163 objectListPerm[itvec->objID].objID = itvec->objID; 164 objectListPerm[itvec->objID].objCreatorID = itvec->objCreatorID; 165 objectListPerm[itvec->objID].objSize = itvec->objSize; 166 } 167 } 168 // remove temporary list (with acked objects) from the map 169 169 objectListTemp.erase( objectListTemp.find(gamestateID) ); 170 170 } 171 171 172 172 /** … … 174 174 */ 175 175 176 177 178 179 180 181 182 176 /** 177 *updateClientListPerm 178 *returns void 179 */ 180 void TrafficControl::insertinClientListPerm(unsigned int clientID, obj objinf) 181 { 182 std::map<unsigned int,std::map<unsigned int, objInfo> >::iterator itperm;//iterator clientListPerm over clientIDs 183 183 unsigned int gsid=GAMESTATEID_INITIAL, gsdiff=currentGamestateID, prioperm=Synchronisable::getSynchronisable(objinf.objID)->getPriority(), priomom=0; 184 184 clientListPerm_[clientID][objinf.objID] = objInfo(objinf.objID, objinf.objCreatorID,gsid,gsdiff, objinf.objSize,prioperm,priomom); 185 185 } 186 186 187 187 /** … … 205 205 for(itvec = list.begin(); itvec != list.end();) 206 206 { 207 assert( (*itvec).objSize < 1000);208 if ( ( size + (*itvec).objSize ) < targetsize )209 { 210 size += (*itvec).objSize;//objSize is given in bytes207 assert( itvec->objSize < 1000); 208 if ( ( size + itvec->objSize ) < targetsize ) 209 { 210 size += itvec->objSize;//objSize is given in bytes 211 211 ++itvec; 212 212 } 213 213 else 214 214 { 215 clientListPerm_[currentClientID][ (*itvec).objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative215 clientListPerm_[currentClientID][itvec->objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative 216 216 list.erase(itvec, list.end()); 217 217 break; … … 223 223 224 224 225 226 227 228 229 225 /** 226 *evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this. 227 */ 228 void TrafficControl::evaluateList(unsigned int clientID, std::list<obj>& list) 229 { 230 230 231 231 if( bActive_ ) … … 236 236 //if listToProcess contains new Objects, add them to clientListPerm 237 237 std::list<obj>::iterator itvec; 238 238 239 239 std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID]; 240 240 241 241 for( itvec=list.begin(); itvec != list.end(); itvec++) 242 242 { 243 if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )243 if ( objectListPerm.find( itvec->objID) != objectListPerm.end() ) 244 244 { 245 245 // we already have the object in our map 246 246 //obj bleibt in liste und permanente prio wird berechnet 247 objectListPerm[ (*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;247 objectListPerm[itvec->objID].objDiffGS = currentGamestateID - objectListPerm[itvec->objID].objCurGS; 248 248 continue;//check next objId 249 249 } … … 256 256 } 257 257 //end compare listToProcess vs clientListPerm 258 258 259 259 //sort copied list according to priorities 260 260 // use boost bind here because we need to pass a memberfunction to stl sort 261 261 // sort( list.begin(), list.end(), boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) ); 262 262 list.sort( boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) ); 263 263 264 264 // list.sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) ); 265 265 … … 277 277 // sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 278 278 list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 279 279 280 280 //diese Funktion updateClientList muss noch gemacht werden 281 281 updateClientListTemp(list); … … 289 289 COUT(0) << "=========== Objectlist ===========" << endl; 290 290 for( it=list.begin(); it!=list.end(); it++) 291 COUT(0) << "ObjectID: " << (*it).objID << " creatorID: " << (*it).objCreatorID << " Priority: " << clientListPerm_[clientID][(*it).objID].objValuePerm + clientListPerm_[clientID][(*it).objID].objValueSched << " size: " << (*it).objSize << endl;291 COUT(0) << "ObjectID: " << it->objID << " creatorID: " << it->objCreatorID << " Priority: " << clientListPerm_[clientID][it->objID].objValuePerm + clientListPerm_[clientID][it->objID].objValueSched << " size: " << it->objSize << endl; 292 292 } 293 293 294 294 void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj>& list, unsigned int clientID) 295 295 { 296 if ( (*it1).objCreatorID == OBJECTID_UNKNOWN )297 return; 298 if( clientListPerm_[clientID][ (*it1).objCreatorID].objCurGS != GAMESTATEID_INITIAL )296 if ( it1->objCreatorID == OBJECTID_UNKNOWN ) 297 return; 298 if( clientListPerm_[clientID][it1->objCreatorID].objCurGS != GAMESTATEID_INITIAL ) 299 299 return; 300 300 std::list<obj>::iterator it2, it3=it1; 301 301 for( it2 = ++it3; it2 != list.end(); it2++ ) 302 302 { 303 if( (*it2).objID == (*it1).objCreatorID )303 if( it2->objID == it1->objCreatorID ) 304 304 { 305 305 it3 = list.insert(it1, *it2); //insert creator before it1
Note: See TracChangeset
for help on using the changeset viewer.