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 | |
---|
36 | #include "NetworkPrereqs.h" |
---|
37 | #include "Synchronisable.h" |
---|
38 | |
---|
39 | namespace network { |
---|
40 | |
---|
41 | // Synchronisable *bla = Synchronisable::getSynchronisable(objectID); |
---|
42 | |
---|
43 | /** |
---|
44 | *a vector of objects of this type will be given by the Server's Gamestate Manager |
---|
45 | */ |
---|
46 | struct objInfo |
---|
47 | { |
---|
48 | unsigned int objCreatorID; |
---|
49 | unsigned int objCurGS;//current GameState ID |
---|
50 | unsigned int objDiffGS;//difference between current and latest GameState |
---|
51 | unsigned int objSize; |
---|
52 | }; |
---|
53 | |
---|
54 | /** |
---|
55 | *a vector of objects of this type will be given by the Server's Gamestate Manager |
---|
56 | */ |
---|
57 | struct obj |
---|
58 | { |
---|
59 | unsigned int objID; |
---|
60 | unsigned int objCreatorID; |
---|
61 | unsigned int objSize; |
---|
62 | }; |
---|
63 | |
---|
64 | |
---|
65 | /** |
---|
66 | * |
---|
67 | */ |
---|
68 | class TrafficControl{ |
---|
69 | private: |
---|
70 | |
---|
71 | //start: lists to be used |
---|
72 | /** |
---|
73 | *creates list (typ map) that contains objids, struct with info concerning object(objid) |
---|
74 | */ |
---|
75 | 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 |
---|
76 | /** |
---|
77 | *reference list: contains object ids and the reference belonging to this id. |
---|
78 | */ |
---|
79 | std::map<unsigned int, Synchronisable*> *referenceList_;//has to be created with constructor and then needs to be updated by evaluateList(). |
---|
80 | /** |
---|
81 | *permanent client list: contains client ids, gamestate ids and object ids (in this order) |
---|
82 | */ |
---|
83 | std::map<unsigned int, objInfo> *clientListPerm_; //has to be created with constructor and then needs to be updated by evaluateList(). |
---|
84 | /** |
---|
85 | *temporary client list: contains client ids, gamestate ids and object ids (in this order) |
---|
86 | */ |
---|
87 | std::map<unsigned int,std::map<unsigned int, unsigned int>> *clientListTemp_; |
---|
88 | /** |
---|
89 | *static priority list: contains obj id, basic priority (in this order) |
---|
90 | */ |
---|
91 | std::map<unsigned int, unsigned int> *permObjPrio_; |
---|
92 | /** |
---|
93 | *dynamic priority list: contains obj id, dynamic priority (eg scheduled) (in this order) |
---|
94 | */ |
---|
95 | std::map<unsigned int, unsigned int> *schedObjPrio_; |
---|
96 | //end: lists to be used |
---|
97 | |
---|
98 | /** |
---|
99 | *currentGamestateID and currentClientID will be defined as soon as TrafficControl is being called by Server |
---|
100 | */ |
---|
101 | unsigned int currentGamestateID; |
---|
102 | unsigned int currentClientID; |
---|
103 | |
---|
104 | void updateReferenceList(std::map<unsigned int, objInfo> *list); |
---|
105 | void insertinClientListPerm(unsigned int objid, objInfo objinf); |
---|
106 | /** |
---|
107 | *creates listToProcess, which can be easialy compared with other lists |
---|
108 | */ |
---|
109 | void copyList(std::vector<obj> *list); |
---|
110 | /** |
---|
111 | *copies Data to be updated into vector, therefore vector can trashed by server |
---|
112 | */ |
---|
113 | std::vector<unsigned int>* copyBackList(std::map<unsigned int,Synchronisable*>); |
---|
114 | /** |
---|
115 | *evaluates Data given (vector) and produces result(->Data to be updated) |
---|
116 | */ |
---|
117 | void evaluateList(std::map<obj> *list); |
---|
118 | |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | protected: |
---|
123 | TrafficControl(); |
---|
124 | virtual ~TrafficControl();//virtual because??? |
---|
125 | static TrafficControl *instance_; |
---|
126 | |
---|
127 | public: |
---|
128 | /** |
---|
129 | *is being used by GSManager from Server: |
---|
130 | *vector contains: ObjIds, CreatorIds, Size (in this order) from Client XY |
---|
131 | *Elements of vector are accessed by *list[i] |
---|
132 | *Elements of struct i are therefore: *list[i].objID |
---|
133 | */ |
---|
134 | 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 |
---|
135 | void processAck(unsigned int clientID, unsigned int gamestateID); // this function gets called when the server receives an ack from the client |
---|
136 | void deleteObject(unsigned int objectID); // this function gets called when an object has been deleted (in order to clean up lists and maps) |
---|
137 | }; |
---|
138 | |
---|
139 | } |
---|
140 | |
---|
141 | #endif |
---|
142 | |
---|