Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/network/TrafficControl.h @ 2371

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

merged network branch to presentation branch

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