- Timestamp:
- Dec 3, 2008, 5:17:07 PM (16 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/TrafficControl.cc
r2317 r2332 36 36 *Initializing protected members 37 37 */ 38 TrafficControl *TraffiControl::instance_=0; 39 40 /** 41 * @brief Constructor: assures that only one reference will be created and sets the pointer 42 */ 43 TrafficControl::TrafficControl() 44 { 45 assert(instance_=0); 46 instance_=this; 47 clientListPerm_=new std::map<unsigned int,std::map<unsigned int, objInfo>>; 48 referenceList_=new std::map<unsigned int, Synchronisable*>; 49 } 50 51 /** 52 * @brief Destructor: resets the instance pointer to 0 53 */ 54 TrafficControl::~TrafficControl() 55 { 56 instance_=0; 57 } 38 TrafficControl *TraffiControl::instance_=0; 39 40 /** 41 * @brief Constructor: assures that only one reference will be created and sets the pointer 42 */ 43 TrafficControl::TrafficControl() 44 { 45 assert(instance_=0); 46 instance_=this; 47 listToProcess_ = new std::map<unsigned int, objInfo>; 48 clientListPerm_ = new std::map<unsigned int,std::map<unsigned int, objInfo>>; 49 clientListTemp_ = new std::map std::map<unsigned int, std::map<unsigned int, std::vector<obj>>>; 50 referenceList_ = new std::map<unsigned int, Synchronisable*>; 51 permObjPrio_ = new std::map<unsigned int, unsigned int> ; 52 schedObjPrio_ = new std::map<unsigned int, unsigned int> schedObjPrio_; 53 } 54 55 /** 56 * @brief Destructor: resets the instance pointer to 0 57 */ 58 TrafficControl::~TrafficControl() 59 { 60 //was macht das genau? da instance ja gleich this ist im moment 61 instance_=0; 62 //muss ich alles deallozieren was ich im constructor aufgebaut habe? 63 } 58 64 59 65 /** … … 61 67 */ 62 68 63 TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj> *list) 64 { 65 currentClientID=clientID; 66 currentGamestateID=gamestateID; 67 list = evaluateList(list); 68 return list; 69 } 69 TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj> *list) 70 { 71 copiedVector = *list; 72 currentClientID=clientID; 73 currentGamestateID=gamestateID; 74 evaluateList(list); 75 //list hatte vorher ja vielmehr elemente, nach zuweisung nicht mehr... speicherplatz?? 76 list=copiedVector; 77 //später wird copiedVector ja überschrieben, ist das ein problem für list-dh. für gamestatemanager? 78 return list; 79 } 80 81 TrafficControl::processAck(unsigned int clientID, unsigned int gamestateID) 82 { 83 map<unsigned int,std::map<unsigned int, objInfo>>::iterator itperm;//iterator clientListPerm 84 map<unsigned int, objInfo>::iterator itpermoid;//iterator over objectid 85 map<unsigned int, std::map<unsigned int, obj>>::iterator ittemp;//iterator clientListTemp, iterates over clientIDs 86 map<unsigned int, unsigned int>::iterator ittempgs;//iterator that iterates over gsIDs of a client 87 vector<obj>::iterator itvec; 88 //following code helps to put clientListTemp infos into clientListPerm infos 89 ittemp = (clientListTemp_).find(clientID); 90 assert(ittemp != clientListTemp_.end() ); //muss da nicht was anderes überprüft werden? 91 itperm = (clientListPerm_).find(clientID); 92 assert(itperm != clientListPerm_.end() ); 93 ittempgs = (*ittemp).find(gamestateID); 94 assert( ittempgs != (*ittemp).end() );//gleiche frage wie vorher 95 for(itvec = *ittempgs.begin(); itvec = *ittempgs.end(); itvec++) 96 { 97 if(itpermoid = (*itperm).find(itvec.objID)) 98 { 99 if(gamestateID>(*itpermoid).second.objCurGS) 100 { 101 (*itpermoid).second.objCurGS = gamestateID; 102 } 103 else continue; 104 } 105 else 106 { 107 objInfo objinf = new objInfo; 108 objinf.objCurGS = gamestateID; 109 insertinClientListPerm(clientID, itvec.objID, objinf); 110 } 111 //entferne objekt aus temporärer liste 112 ittempgs.erase(itvec); 113 } 114 115 } 70 116 71 117 /** 72 118 *Definition of private members 73 119 */ 74 75 //brauch ich die noch?? 76 TrafficControl::createReferenceList(Synchronisable *list) 77 { 78 map<unsigned int, Synchronisable*>::iterator itref; 79 itref=referenceList_->begin(); 80 referenceList_->insert(itref,pair<unsigned int, Synchronisable*>(itref->getObjectID,itref->getSynchronisable)); 81 } 82 //end brauch ich die noch 83 84 /** 85 *copyList gets vector of Gamestate Manager and turns it to *listToProcess 86 */ 87 TrafficControl::copyList(std::map<obj> *list) 88 { 89 listToProcess_=new std::map<unsigned int,std::map<unsigned int, unsigned int>>; 90 vector<obj>::iterator itvec; 91 for(itvec = list->begin(); itvec < list->end(); itvec++) 92 { 93 objInfo * objectA = new objInfo; 94 objectA.objCreatorID=*itvec.objCreatorID; 95 objectA.objSize = *itvec.objSize; 96 listToProcess_->insert(pair<currentClientID, map<*itvec.objID,objectA>)//unsicher: ob map<...> so richtig ist 97 } 98 } 99 /** 100 *updateReferenceList compares the sent list by GSmanager with *the current reference list and updates it. 101 *returns void 102 */ 103 TrafficControl::updateReferenceList(std::map<unsigned int, objInfo> *list) 104 { 105 map<unsigned int, Synchronisable*>::iterator itref; 106 map<unsigned int, objInfo>::iterator itproc; 107 for(itproc=listToProcess_->begin();itproc != listToProcess_->.end(); itproc++) 108 { 109 //itproc->first=objectid that is looked for 110 if(referenceList_->find(itproc->first)) 111 { 112 continue; 113 } 114 else 115 { 116 referenceList_->insert(pair<unsigned int, Synchronisable*>(itproc->first,Synchronisable::getSynchronisable(itproc->first)); 117 insertinClientListPerm(itproc->first,itproc->second); 118 } 119 } 120 } 121 /** 122 *updateClientListPerm 123 *returns void 124 */ 125 TrafficControl::insertinClientListPerm(unsigned int objid, objInfo objinf) 126 { 127 clientListPerm_->insert(pair<unsigned int,objInfo>(objid,objinf)); 128 } 129 130 131 /** 132 *evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this. 133 */ 134 TrafficControl::evaluateList(std::map<obj> *list) 135 { 136 copyList(list); 137 updateReferenceList(listToProcess_); 138 139 //now the sorting 140 141 //compare listToProcess vs clientListPerm 142 map<unsigned int, objInfo>::iterator itproc; 143 map<unsigned int,std::map<unsigned int, objInfo>>::iterator itperm; 144 map<unsigned int, objInfo>::iterator itpermobj; 145 map<unsigned int, unsigned int>::iterator itpermprio 146 for(itproc=listToProcess_->begin(); itproc != listToProcess_->end();it++) 147 { 148 itperm=clientListPerm->find(currentClientID); 149 itpermobj=itperm->find(itproc->first); 150 if(currentGamestateID < (itpermobj->second).objCurGS) 151 { 152 //obj bleibt in liste und permanente prio wird berechnet 153 (itpermobj->second).objDiffGS = (itpermobj->second).objCurGS - currentGamestateID; 154 itpermprio = permObjPrio_->find(itproc->first); 155 (itpermobj->second).objValuePerm = (itpermobj->second).objDiffGS * itpermprio->second; 156 continue;//check next objId 157 } 158 else 159 { 160 listToProcess_->erase (itproc); 161 } 162 } 163 //end compare listToProcess vs clientListPerm 164 165 //listToProc vs clientListTemp 166 map<unsigned int, std::map<unsigned int, unsigned int>>::iterator ittemp; 167 map<unsigned int, unsigned int>::iterator ittempgs; 168 for(itproc=listToProcess_->begin(); itproc != listToProcess_->end();it++) 169 { 170 ittemp = clientListTemp_->find(currentClientID); 171 if(ittempgs = ittemp->find(currentGamestateID)) 172 { 173 if(itproc->first == ittempgs->find(itproc->first)) 174 { 175 listToProcess_->erase (itproc); 120 121 //brauch ich die noch??, 122 TrafficControl::createReferenceList(Synchronisable *list) 123 { 124 map<unsigned int, Synchronisable*>::iterator itref; 125 itref=referenceList_->begin(); 126 referenceList_->insert(itref,pair<unsigned int, Synchronisable*>((*itref).getObjectID,(*itref).getSynchronisable)); 127 } 128 //end brauch ich die noch 129 130 /** 131 *copyList gets vector of Gamestate Manager and turns it to *listToProcess 132 */ 133 TrafficControl::copyList(std::map<obj> *list) 134 { 135 vector<obj>::iterator itvec; 136 for(itvec = (*list).begin(); itvec < (*list).end(); itvec++) 137 { 138 objInfo objectA = new objInfo; 139 (*objectA).objCreatorID=(*itvec).objCreatorID; 140 (*objectA).objSize = (*itvec).objSize; 141 (*listToProcess_).insert(pair<currentClientID, map<(*itvec).objID,objectA>>)//unsicher: ob map<...> so richtig ist 142 } 143 } 144 /** 145 *updateReferenceList compares the sent list by GSmanager with the current *reference list and updates it. 146 *returns void 147 */ 148 TrafficControl::updateReferenceList(std::map<unsigned int, objInfo> *list) 149 { 150 map<unsigned int, Synchronisable*>::iterator itref; 151 map<unsigned int, objInfo>::iterator itproc; 152 for(itproc=(*listToProcess_).begin();itproc != (*listToProcess_).end(); itproc++) 153 { 154 //itproc->first=objectid that is looked for 155 if(referenceList_->find(itproc->first)) 156 { 157 continue; 158 } 159 else 160 { 161 (*referenceList_).insert(pair<unsigned int, Synchronisable*>((*itproc).first,Synchronisable::getSynchronisable((*itproc).first));//important: how to get adress of an object! 162 insertinClientListPerm(currentClientID,itproc->first,itproc->second); 163 } 164 } 165 } 166 /** 167 *updateClientListPerm 168 *returns void 169 */ 170 TrafficControl::insertinClientListPerm(unsigned int clientid, unsigned int objid, objInfo objinf) 171 { 172 map<unsigned int,std::map<unsigned int, objInfo>>::iterator itperm;//iterator clientListPerm over clientIDs 173 itperm = (clientListPerm_).find(clientiD); 174 assert(itperm != clientListPerm_.end() ); 175 (*itperm).insert(pair<unsigned int, objInfo>(objid,objinf)); 176 } 177 178 179 /** 180 *evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this. 181 */ 182 TrafficControl::evaluateList(std::map<obj> *list) 183 { 184 copyList(list); 185 updateReferenceList(listToProcess_); 186 187 //now the sorting 188 189 //compare listToProcess vs clientListPerm 190 map<unsigned int, objInfo>::iterator itproc; 191 map<unsigned int,std::map<unsigned int, objInfo>>::iterator itperm; 192 map<unsigned int, objInfo>::iterator itpermobj; 193 map<unsigned int, unsigned int>::iterator itpermprio; 194 for((*itproc=listToProcess_).begin(); itproc != (*listToProcess_).end();it++) 195 { 196 itperm=(clientListPerm_).find(currentClientID); 197 itpermobj=(*itperm).find((*itproc).first); 198 if(currentGamestateID < ((*itpermobj).second).objCurGS) 199 { 200 //obj bleibt in liste und permanente prio wird berechnet 201 ((*itpermobj).second).objDiffGS = ((*itpermobj).second).objCurGS - currentGamestateID; 202 itpermprio = (permObjPrio_).find((*itproc).first); 203 ((*itpermobj).second).objValuePerm = ((*itpermobj).second).objDiffGS * (*itpermprio).second; 204 continue;//check next objId 205 } 206 else 207 { 208 (listToProcess_).erase(itproc); 209 } 210 } 211 //end compare listToProcess vs clientListPerm 212 213 //listToProc vs clientListTemp 214 map<unsigned int, std::map<unsigned int, unsigned int>>::iterator ittemp; 215 map<unsigned int, unsigned int>::iterator ittempgs; 216 for((itproc=listToProcess_).begin(); itproc != (listToProcess_).end();itproc++) 217 { 218 ittemp = clientListTemp_->find(currentClientID); 219 if(ittempgs = (*ittemp).find(currentGamestateID)) 220 { 221 if((*itproc).first == (*ittempgs).find((*itproc).first))//ja, dann ist objekt schon in der zu sendenden liste-muss nicht nochmal gesendet werden 222 { 223 (listToProcess_).erase (itproc); 224 } 225 else continue; 226 } 227 else continue; 228 } 229 //end listToProc vs clientListTemp 230 231 //listToProcess contains obj to send now, shorten copiedvector therefor too. 232 vector<obj>::iterator itvec; 233 for(itvec = copiedVector.begin(); itvec < copiedVector.end(); itvec++) 234 { 235 if((listToProcess_).find(itvec->objID)) 236 { 237 continue;//therefore object wasnt thrown out yet and has to be sent back to gsmanager 238 } 239 else 240 { 241 copiedVector.remove(itvec); 242 } 243 } 244 //sort copied vector aufgrund der objprioperm in clientlistperm 245 sort(copiedVector.begin(),copiedVector.end(),priodiffer); 246 //swappen aufgrund von creator oder ganz rausnehmen!? 247 for(itvec = copiedVector.begin(); itvec < copiedVector.end(); itvec++) 248 { 249 itproc = (listToProcess_).find((*itvec).objID); 250 if((*itproc).second.objCreatorID) 251 { 252 //vor dem child in copiedvector einfügen, wie? 253 copiedVector.insert(copiedVector.find((*itproc).first),(*itproc).second.objCreatorID); 254 } 255 else continue; 256 } 257 //end of sorting 258 //now the cutting, work the same obj out in processobjectlist and copiedvector, compression rate muss noch festgelegt werden. 259 cut(copiedVector,currentClientID???bandWidth); 260 //diese Funktion updateClientList muss noch gemacht werden 261 updateClientListTemp(copiedVector); 262 //end of sorting 176 263 } 177 else continue; 178 } 179 else continue; 180 } 181 //end listToProc vs clientListTemp 182 183 //listToProcess contains obj to send now, shorten copiedvector therefor too. 184 vector<obj>::iterator itvec; 185 for(itvec = copiedvector.begin(); itvec < copiedvector.end(); itvec++) 186 { 187 if(listToProcess_->find(itvec->objID)) 188 { 189 continue; 190 } 191 else 192 { 193 copiedvector.remove(itvec); 194 } 195 } 196 //sort copied vector aufgrund der objprioperm in clientlistperm 197 sort(copiedvector.begin(),copiedvector.end(),priodiffer); 198 //swappen aufgrund von creator oder ganz rausnehmen!? 199 for(itvec = copiedVector.begin(); itvec < copiedVector.end(); itvec++) 200 { 201 itproc = listToProcess_->find(itvec->objID); 202 if(itproc->second.objCreatorID) 203 { 204 //vor dem child in copiedvector einfügen, wie? 205 copiedVector.insert(itproc->second.objCreatorID); 206 } 207 else continue; 208 } 209 //end of sorting 210 //now the cutting, work the same obj out in processobjectlist and copiedvector, compression rate muss noch festgelegt werden. 211 cut(copiedVector,compressionRate-1); 212 //diese Funktion updateClientList muss noch gemacht werden 213 updateClientListTemp(copiedVector); 214 //end of sorting 215 } 216 217 TrafficControl::processAck(unsigned int clientID, unsigned int gamestateID) 218 { 219 map<unsigned int,std::map<unsigned int, objInfo>>::iterator itperm; 220 map<unsigned int, std::map<unsigned int, unsigned int>>::iterator ittemp; 221 map<unsigned int, unsigned int>::iterator ittempgs; 222 vector<obj>::iterator itvec; 223 //put temporarylist infos into permanentlist infos 224 ittemp = clientListTemp_->find(clientID); 225 assert(ittemp != clientListTemp_.end() ); 226 ittempgs = (*ittemp).find(gamestateID); 227 assert( ittempgs != (*ittemp).end() ); 228 for(itvec = *ittempgs.begin(); itvec = *ittempgs.end(); itvec++) 229 { 230 if(itperm = (*clientListPerm_).find(itvec.objID)) 231 { 232 itperm = (*clientListPerm_).find(itvec.objID); 233 if(gamestateID>itperm.second.objCurGS) 234 { 235 itperm.second.objCurGS = gamestateID; 236 } 237 else continue; 238 } 239 else 240 { 241 objInfo objinf = new objInfo; 242 objinf.objCurGS = gamestateID; 243 insertinClientListPerm(itvec.objID, objinf); 244 } 245 //entferne objekt aus temporärer liste 246 ittempgs.erase(itvec); 247 } 248 249 } 264 265 250 266 251 267 -
code/branches/network/src/network/TrafficControl.h
r2276 r2332 39 39 40 40 namespace network { 41 42 // Synchronisable *bla = Synchronisable::getSynchronisable(objectID);43 44 //stuff to iterate through: map<unsigned int, objInfo>::iterator itproc;45 // map<unsigned int, Synchronisable>::iterator itref;46 // for(it=listToProcess_->begin(); it != listToProcess_->end();it++)47 // {48 //49 // itref=referenceList_->find((*itproc).first);50 // refCurObj=(*itref).second;51 41 52 42 /** … … 91 81 private: 92 82 83 /** 84 *Lists that will be used: 85 *listToProcess 86 *clientListPerm 87 *clientListTemp 88 *referenceList 89 *permObjPrio list 90 *schedObjPrio 91 */ 93 92 //start: lists to be used 94 93 /** 95 94 *creates list (typ map) that contains objids, struct with info concerning object(objid) 96 95 */ 97 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 GS96 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 98 97 /** 99 98 *reference list: contains object ids and the reference belonging to this id. 100 99 */ 101 //std::map<unsigned int, Synchronisable*> *referenceList_;//has to be created with constructor and then needs to be updated by evaluateList().100 //std::map<unsigned int, Synchronisable*> *referenceList_;//has to be created with constructor and then needs to be updated by evaluateList(). 102 101 /** 103 *permanent client list: contains client ids, gamestate ids and object ids (in this order)102 *permanent client list: contains client ids, object ids and objectInfos (in this order) 104 103 */ 105 std::map<unsigned int, std::map<unsigned int, objInfo>> *clientListPerm_;104 std::map<unsigned int, std::map<unsigned int, objInfo>> clientListPerm_; 106 105 //has to be created with constructor and then needs to be updated by evaluateList(). 107 106 … … 109 108 *temporary client list: contains client ids, gamestate ids and object ids (in this order) 110 109 */ 111 std::map<unsigned int, std::map<unsigned int, std::vector<obj>>> *clientListTemp_;110 std::map<unsigned int, std::map<unsigned int, std::vector<obj>>> clientListTemp_; 112 111 /** 113 112 *static priority list: contains obj id, basic priority (in this order) 114 113 */ 115 std::map<unsigned int, unsigned int> *permObjPrio_;114 std::map<unsigned int, unsigned int> permObjPrio_; 116 115 /** 117 116 *dynamic priority list: contains obj id, dynamic priority (eg scheduled) (in this order) 118 117 */ 119 std::map<unsigned int, unsigned int> *schedObjPrio_;118 std::map<unsigned int, unsigned int> schedObjPrio_; 120 119 //end: lists to be used 121 120 … … 125 124 unsigned int currentGamestateID; 126 125 unsigned int currentClientID; 127 Synchronisable *refCurObj;//reference to current object, uninitialized yet, do I have to or can I just set refCurObj=...; later on? 128 //not used yet anyway 129 std::vector<obj> copiedVector; //copy of original that I get from GSmanager 126 /** 127 *copiedVector is a copy of the given Vector by the GSmanager, on this vector all manipulations are performed 128 */ 129 std::vector<obj> copiedVector; 130 130 131 void updateReferenceList(std::map<unsigned int, objInfo> *list); 132 void insertinClientListPerm(unsigned int objid, objInfo objinf); 131 void updateReferenceList(std::map<unsigned int, objInfo> *list);//done 132 void insertinClientListPerm(unsigned int objid, objInfo objinf);//done 133 void createReferenceList(Synchronisable *list);//done 133 134 /** 134 135 *creates listToProcess, which can be easialy compared with other lists 135 136 */ 136 void copyList(std::vector<obj> *list); 137 /** 138 *copies Data to be updated into vector, therefore vector can trashed by server 139 */ 140 std::vector<unsigned int>* copyBackList(std::map<unsigned int,Synchronisable*>); 137 void copyList(std::vector<obj> *list);//done 138 139 void cut(vector<obj> *list,int bandwidth); 140 void updateClientListTemp(vector<obj> *list); 141 141 /** 142 142 *evaluates Data given (vector) and produces result(->Data to be updated) 143 143 */ 144 144 void evaluateList(std::map<obj> *list); 145 146 147 148 145 149 146 protected: … … 160 157 */ 161 158 std::vector<obj>* processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj>* list); //gets a pointer to the vector (containing objectIDs) and sorts it 159 //done 162 160 void processAck(unsigned int clientID, unsigned int gamestateID); // this function gets called when the server receives an ack from the client 161 //done 163 162 void deleteObject(unsigned int objectID); // this function gets called when an object has been deleted (in order to clean up lists and maps) 164 163 };
Note: See TracChangeset
for help on using the changeset viewer.