Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

current progress

File size: 5.3 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#ifndef NETWORKTRAFFICCONTROL_H
29#define NETWORKTRAFFICCONTROL_H
30
31#include <string>
32#include <vector>
33#include <map>
34#include <utility>
35#include <algorithm>
36
37#include "NetworkPrereqs.h"
38#include "Synchronisable.h"
39
40namespace network {
41
42/**
43*a vector of objects of this type will be given by the Server's Gamestate Manager
44*/
45struct objInfo
46{
47  unsigned int objCreatorID;
48  unsigned int objCurGS;//current GameState ID
49  unsigned int objDiffGS;//difference between current and latest GameState
50  unsigned int objSize;
51  unsigned int objValuePerm;
52  unsigned int objValueSched;
53};
54
55/**
56*a vector of objects of this type will be given by the Server's Gamestate Manager
57*/
58struct obj
59{
60  unsigned int objID;
61  unsigned int objCreatorID;
62  unsigned int objSize;
63};
64
65/**
66*eigener sortieralgorithmus
67*/
68bool priodiffer(obj i, obj j)
69{ 
70  map<unsigned int, objInfo>::iterator iti;
71  map<unsigned int, objInfo>::iterator itj;
72  iti=listToProcess_->find(i.objID);
73  itj=listToProcess_->find(j.objID);
74  return iti->second.objValuePerm < itj->second.objValuePerm;
75}
76
77/**
78*
79*/
80class TrafficControl{
81  private:
82
83    /**
84    *Lists that will be used:
85    *listToProcess
86    *clientListPerm
87    *clientListTemp
88    *referenceList
89    *permObjPrio list
90    *schedObjPrio
91    */
92    //start: lists to be used
93    /**
94    *creates list (typ map) that contains objids, struct with info concerning object(objid)
95    */
96    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
97    /**
98    *reference list: contains object ids and the reference belonging to this id.
99    */
100    //std::map<unsigned int, Synchronisable*> *referenceList_;//has to be created with constructor and then needs to be updated by evaluateList().
101    /**
102    *permanent client list: contains client ids, object ids and objectInfos (in this order)
103    */
104    std::map<unsigned int, std::map<unsigned int, objInfo>> clientListPerm_;
105    //has to be created with constructor and then needs to be updated by evaluateList().
106
107    /**
108    *temporary client list: contains client ids, gamestate ids and object ids (in this order)
109    */
110    std::map<unsigned int, std::map<unsigned int, std::vector<obj>>> clientListTemp_;
111    /**
112    *static priority list: contains obj id, basic priority (in this order)
113    */
114    std::map<unsigned int, unsigned int> permObjPrio_;
115    /**
116    *dynamic priority list: contains obj id, dynamic priority (eg scheduled) (in this order)
117    */
118    std::map<unsigned int, unsigned int> schedObjPrio_;
119    //end: lists to be used
120
121    /**
122    *currentGamestateID and currentClientID will be defined as soon as TrafficControl is being called by Server
123    */
124    unsigned int currentGamestateID;
125    unsigned int currentClientID;
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
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
134    /**
135    *creates listToProcess, which can be easialy compared with other lists
136    */
137    void copyList(std::vector<obj> *list);//done
138   
139    void cut(vector<obj> *list,int bandwidth);
140    void updateClientListTemp(vector<obj> *list);
141    /**
142    *evaluates Data given (vector) and produces result(->Data to be updated)
143    */
144    void evaluateList(std::map<obj> *list);
145
146  protected:
147    TrafficControl();
148    virtual ~TrafficControl();//virtual because???
149    static TrafficControl *instance_;
150
151  public:
152    /**
153    *is being used by GSManager from Server:
154    *vector contains: ObjIds, CreatorIds, Size (in this order) from Client XY
155    *Elements of vector are accessed by *list[i]
156    *Elements of struct i are therefore: *list[i].objID
157    */
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
160    void processAck(unsigned int clientID, unsigned int gamestateID);   // this function gets called when the server receives an ack from the client
161    //done
162    void deleteObject(unsigned int objectID);                           // this function gets called when an object has been deleted (in order to clean up lists and maps)
163};
164
165}
166
167#endif
168
Note: See TracBrowser for help on using the repository browser.