Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

still not complete yet but much better i hope…

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