Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/network/TrafficControl.cc @ 2332

Last change on this file since 2332 was 2332, checked in by chpeter, 15 years ago

current progress

File size: 9.2 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "TrafficControl.h"
30
31#include <cassert>
32
33namespace network {
34
35/**
36*Initializing protected members
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          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        }
64
65/**
66*Definition of public members
67*/
68
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        }
116
117/**
118*Definition of private members
119*/
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
263      }
264
265
266
267
268/*
269void bvlabla(vector *a){
270//sort a
271vector *cache;
272cache = new vector<unsigned int>(*a);
273return a;
274}
275*/
276
277
278}//namespace network
Note: See TracBrowser for help on using the repository browser.