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 | |
---|
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 | |
---|
52 | /** |
---|
53 | *a vector of objects of this type will be given by the Server's Gamestate Manager |
---|
54 | */ |
---|
55 | struct objInfo |
---|
56 | { |
---|
57 | unsigned int objCreatorID; |
---|
58 | unsigned int objCurGS;//current GameState ID |
---|
59 | unsigned int objDiffGS;//difference between current and latest GameState |
---|
60 | unsigned int objSize; |
---|
61 | unsigned int objValuePerm; |
---|
62 | unsigned int objValueSched; |
---|
63 | }; |
---|
64 | |
---|
65 | /** |
---|
66 | *a vector of objects of this type will be given by the Server's Gamestate Manager |
---|
67 | */ |
---|
68 | struct obj |
---|
69 | { |
---|
70 | unsigned int objID; |
---|
71 | unsigned int objCreatorID; |
---|
72 | unsigned int objSize; |
---|
73 | }; |
---|
74 | |
---|
75 | /** |
---|
76 | *eigener sortieralgorithmus |
---|
77 | */ |
---|
78 | bool priodiffer(obj i, obj j) |
---|
79 | { |
---|
80 | map<unsigned int, objInfo>::iterator iti; |
---|
81 | map<unsigned int, objInfo>::iterator itj; |
---|
82 | iti=listToProcess_->find(i.objID); |
---|
83 | itj=listToProcess_->find(j.objID); |
---|
84 | return iti->second.objValuePerm < itj->second.objValuePerm; |
---|
85 | } |
---|
86 | |
---|
87 | /** |
---|
88 | * |
---|
89 | */ |
---|
90 | class TrafficControl{ |
---|
91 | private: |
---|
92 | |
---|
93 | //start: lists to be used |
---|
94 | /** |
---|
95 | *creates list (typ map) that contains objids, struct with info concerning object(objid) |
---|
96 | */ |
---|
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 GS |
---|
98 | /** |
---|
99 | *reference list: contains object ids and the reference belonging to this id. |
---|
100 | */ |
---|
101 | // std::map<unsigned int, Synchronisable*> *referenceList_;//has to be created with constructor and then needs to be updated by evaluateList(). |
---|
102 | /** |
---|
103 | *permanent client list: contains client ids, gamestate ids and object ids (in this order) |
---|
104 | */ |
---|
105 | std::map<unsigned int, std::map<unsigned int, objInfo>> *clientListPerm_; |
---|
106 | //has to be created with constructor and then needs to be updated by evaluateList(). |
---|
107 | |
---|
108 | /** |
---|
109 | *temporary client list: contains client ids, gamestate ids and object ids (in this order) |
---|
110 | */ |
---|
111 | std::map<unsigned int, std::map<unsigned int, std::vector<obj>>> *clientListTemp_; |
---|
112 | /** |
---|
113 | *static priority list: contains obj id, basic priority (in this order) |
---|
114 | */ |
---|
115 | std::map<unsigned int, unsigned int> *permObjPrio_; |
---|
116 | /** |
---|
117 | *dynamic priority list: contains obj id, dynamic priority (eg scheduled) (in this order) |
---|
118 | */ |
---|
119 | std::map<unsigned int, unsigned int> *schedObjPrio_; |
---|
120 | //end: lists to be used |
---|
121 | |
---|
122 | /** |
---|
123 | *currentGamestateID and currentClientID will be defined as soon as TrafficControl is being called by Server |
---|
124 | */ |
---|
125 | unsigned int currentGamestateID; |
---|
126 | 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 |
---|
130 | |
---|
131 | void updateReferenceList(std::map<unsigned int, objInfo> *list); |
---|
132 | void insertinClientListPerm(unsigned int objid, objInfo objinf); |
---|
133 | /** |
---|
134 | *creates listToProcess, which can be easialy compared with other lists |
---|
135 | */ |
---|
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*>); |
---|
141 | /** |
---|
142 | *evaluates Data given (vector) and produces result(->Data to be updated) |
---|
143 | */ |
---|
144 | void evaluateList(std::map<obj> *list); |
---|
145 | |
---|
146 | |
---|
147 | |
---|
148 | |
---|
149 | protected: |
---|
150 | TrafficControl(); |
---|
151 | virtual ~TrafficControl();//virtual because??? |
---|
152 | static TrafficControl *instance_; |
---|
153 | |
---|
154 | public: |
---|
155 | /** |
---|
156 | *is being used by GSManager from Server: |
---|
157 | *vector contains: ObjIds, CreatorIds, Size (in this order) from Client XY |
---|
158 | *Elements of vector are accessed by *list[i] |
---|
159 | *Elements of struct i are therefore: *list[i].objID |
---|
160 | */ |
---|
161 | 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 |
---|
162 | void processAck(unsigned int clientID, unsigned int gamestateID); // this function gets called when the server receives an ack from the client |
---|
163 | void deleteObject(unsigned int objectID); // this function gets called when an object has been deleted (in order to clean up lists and maps) |
---|
164 | }; |
---|
165 | |
---|
166 | } |
---|
167 | |
---|
168 | #endif |
---|
169 | |
---|