[2052] | 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> |
---|
[2231] | 34 | #include <utility> |
---|
[2276] | 35 | #include <algorithm> |
---|
[2052] | 36 | |
---|
| 37 | #include "NetworkPrereqs.h" |
---|
| 38 | #include "Synchronisable.h" |
---|
[2351] | 39 | #include "ClientInformation.h" |
---|
[2341] | 40 | #include "util/Integers.h" |
---|
[2052] | 41 | |
---|
| 42 | namespace network { |
---|
| 43 | |
---|
| 44 | /** |
---|
[2231] | 45 | *a vector of objects of this type will be given by the Server's Gamestate Manager |
---|
| 46 | */ |
---|
| 47 | struct objInfo |
---|
| 48 | { |
---|
[2341] | 49 | uint32_t objID; |
---|
| 50 | uint32_t objCreatorID; |
---|
[2351] | 51 | uint32_t objCurGS;//current GameState ID |
---|
| 52 | uint32_t objDiffGS;//difference between current and latest GameState |
---|
[2341] | 53 | uint32_t objSize; |
---|
[2276] | 54 | unsigned int objValuePerm; |
---|
| 55 | unsigned int objValueSched; |
---|
[2348] | 56 | objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched) |
---|
| 57 | { objID = ID; objCreatorID = creatorID; objCurGS = curGsID; objDiffGS = diffGsID; objSize = size; objValuePerm = prioperm; objValueSched = priosched; } |
---|
[2351] | 58 | objInfo() |
---|
| 59 | { objID = OBJECTID_UNKNOWN; objCreatorID = OBJECTID_UNKNOWN; objCurGS = GAMESTATEID_INITIAL; objDiffGS = objCurGS; objSize = 0; objValuePerm = 0; objValueSched = 0; } |
---|
[2231] | 60 | }; |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | *a vector of objects of this type will be given by the Server's Gamestate Manager |
---|
| 64 | */ |
---|
| 65 | struct obj |
---|
| 66 | { |
---|
[2351] | 67 | uint32_t objID; |
---|
| 68 | uint32_t objCreatorID; |
---|
| 69 | uint32_t objSize; |
---|
| 70 | uint32_t objDataOffset; |
---|
| 71 | obj() |
---|
| 72 | { objID = OBJECTID_UNKNOWN; objCreatorID = OBJECTID_UNKNOWN; objSize = 0; objDataOffset = 0; } |
---|
| 73 | obj( uint32_t ID, uint32_t creatorID, uint32_t size, uint32_t offset ) |
---|
| 74 | { objID = ID; objCreatorID = creatorID; objSize = size; objDataOffset = offset; } |
---|
[2231] | 75 | }; |
---|
| 76 | |
---|
| 77 | |
---|
[2351] | 78 | const unsigned int SCHED_PRIORITY_OFFSET = -5; |
---|
[2334] | 79 | |
---|
[2351] | 80 | |
---|
[2231] | 81 | /** |
---|
[2052] | 82 | * |
---|
| 83 | */ |
---|
[2231] | 84 | class TrafficControl{ |
---|
[2052] | 85 | private: |
---|
| 86 | |
---|
[2332] | 87 | /** |
---|
| 88 | *Lists that will be used: |
---|
| 89 | *listToProcess |
---|
| 90 | *clientListPerm |
---|
| 91 | *clientListTemp |
---|
| 92 | *referenceList |
---|
| 93 | *permObjPrio list |
---|
| 94 | *schedObjPrio |
---|
| 95 | */ |
---|
[2231] | 96 | //start: lists to be used |
---|
| 97 | /** |
---|
| 98 | *creates list (typ map) that contains objids, struct with info concerning object(objid) |
---|
| 99 | */ |
---|
[2351] | 100 | // 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 |
---|
[2231] | 101 | /** |
---|
[2332] | 102 | *permanent client list: contains client ids, object ids and objectInfos (in this order) |
---|
[2231] | 103 | */ |
---|
[2348] | 104 | std::map<unsigned int, std::map<unsigned int, objInfo > > clientListPerm_; |
---|
[2276] | 105 | //has to be created with constructor and then needs to be updated by evaluateList(). |
---|
| 106 | |
---|
[2231] | 107 | /** |
---|
| 108 | *temporary client list: contains client ids, gamestate ids and object ids (in this order) |
---|
| 109 | */ |
---|
[2341] | 110 | std::map<unsigned int, std::map<unsigned int, std::vector<obj> > > clientListTemp_; |
---|
[2231] | 111 | /** |
---|
| 112 | *static priority list: contains obj id, basic priority (in this order) |
---|
| 113 | */ |
---|
[2348] | 114 | // std::map<unsigned int, unsigned int> permObjPrio_; |
---|
[2231] | 115 | /** |
---|
| 116 | *dynamic priority list: contains obj id, dynamic priority (eg scheduled) (in this order) |
---|
| 117 | */ |
---|
[2348] | 118 | // std::map<unsigned int, unsigned int> schedObjPrio_; |
---|
[2231] | 119 | //end: lists to be used |
---|
[2052] | 120 | |
---|
[2341] | 121 | /**updateReferenceList |
---|
[2231] | 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; |
---|
[2340] | 126 | unsigned int targetSize; |
---|
[2332] | 127 | /** |
---|
| 128 | *copiedVector is a copy of the given Vector by the GSmanager, on this vector all manipulations are performed |
---|
| 129 | */ |
---|
[2351] | 130 | // std::vector<obj> copiedVector; |
---|
[2052] | 131 | |
---|
[2348] | 132 | // void updateReferenceList(std::map<unsigned int, objInfo> *list);//done |
---|
| 133 | void insertinClientListPerm(unsigned int clientID, obj objinf);//done |
---|
[2231] | 134 | /** |
---|
| 135 | *creates listToProcess, which can be easialy compared with other lists |
---|
| 136 | */ |
---|
[2348] | 137 | // void copyList(std::vector<obj> *list);//done |
---|
[2332] | 138 | |
---|
[2348] | 139 | void cut(std::vector<obj> *list, unsigned int targetsize); |
---|
[2340] | 140 | void updateClientListTemp(std::vector<obj> *list);//done |
---|
[2231] | 141 | /** |
---|
| 142 | *evaluates Data given (vector) and produces result(->Data to be updated) |
---|
| 143 | */ |
---|
[2351] | 144 | void evaluateList(unsigned int clientID, std::vector<obj> *list);//done |
---|
[2231] | 145 | |
---|
[2052] | 146 | protected: |
---|
| 147 | TrafficControl(); |
---|
[2231] | 148 | virtual ~TrafficControl();//virtual because??? |
---|
[2052] | 149 | static TrafficControl *instance_; |
---|
| 150 | |
---|
| 151 | public: |
---|
[2231] | 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 | */ |
---|
[2351] | 158 | void processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj>* list); //gets a pointer to the vector (containing objectIDs) and sorts it |
---|
[2332] | 159 | //done |
---|
[2052] | 160 | void processAck(unsigned int clientID, unsigned int gamestateID); // this function gets called when the server receives an ack from the client |
---|
[2332] | 161 | //done |
---|
[2052] | 162 | void deleteObject(unsigned int objectID); // this function gets called when an object has been deleted (in order to clean up lists and maps) |
---|
[2334] | 163 | |
---|
[2348] | 164 | bool priodiffer(uint32_t clientID, obj i, obj j); |
---|
[2052] | 165 | }; |
---|
| 166 | |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | #endif |
---|
| 170 | |
---|