Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2340 was 2340, checked in by chpeter, 15 years ago

finished-well, not really=)

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