Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2440 was 2436, checked in by rgrieder, 16 years ago

Added svn:eol-style "native" to all files.

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