Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2351 was 2351, checked in by scheusso, 15 years ago

some changes. still not working yet, but will correct theese problems after merge with network64

File size: 5.8 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#include "ClientInformation.h"
40#include "util/Integers.h"
41
42namespace network {
43
44/**
45*a vector of objects of this type will be given by the Server's Gamestate Manager
46*/
47struct objInfo
48{
49  uint32_t objID;
50  uint32_t objCreatorID;
51  uint32_t objCurGS;//current GameState ID
52  uint32_t objDiffGS;//difference between current and latest GameState
53  uint32_t objSize;
54  unsigned int objValuePerm;
55  unsigned int objValueSched;
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; }
58  objInfo()
59    { objID = OBJECTID_UNKNOWN; objCreatorID = OBJECTID_UNKNOWN; objCurGS = GAMESTATEID_INITIAL; objDiffGS = objCurGS; objSize = 0; objValuePerm = 0; objValueSched = 0; }
60};
61
62/**
63*a vector of objects of this type will be given by the Server's Gamestate Manager
64*/
65struct obj
66{
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; }
75};
76
77
78const unsigned int SCHED_PRIORITY_OFFSET = -5;
79
80
81/**
82*
83*/
84class TrafficControl{
85  private:
86
87    /**
88    *Lists that will be used:
89    *listToProcess
90    *clientListPerm
91    *clientListTemp
92    *referenceList
93    *permObjPrio list
94    *schedObjPrio
95    */
96    //start: lists to be used
97    /**
98    *creates list (typ map) that contains objids, struct with info concerning object(objid)
99    */
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
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    /**updateReferenceList
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    unsigned int targetSize;
127    /**
128    *copiedVector is a copy of the given Vector by the GSmanager, on this vector all manipulations are performed
129    */
130//     std::vector<obj> copiedVector;
131
132//     void updateReferenceList(std::map<unsigned int, objInfo> *list);//done
133    void insertinClientListPerm(unsigned int clientID, obj objinf);//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(std::vector<obj> *list, unsigned int targetsize);
140    void updateClientListTemp(std::vector<obj> *list);//done
141    /**
142    *evaluates Data given (vector) and produces result(->Data to be updated)
143    */
144    void evaluateList(unsigned int clientID, std::vector<obj> *list);//done   
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    void 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    bool priodiffer(uint32_t clientID, obj i, obj j);
165};
166
167}
168
169#endif
170
Note: See TracBrowser for help on using the repository browser.