Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

made some changes, but now yet complete

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