Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/TrafficControl.h @ 3122

Last change on this file since 3122 was 3084, checked in by landauf, 15 years ago

merged netp3 branch back to trunk

  • Property svn:eol-style set to native
File size: 4.7 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:
[3084]23 *      Oliver Scheuss <scheusso [at] ee.ethz.ch>
[2355]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>
[2382]38#include "core/OrxonoxClass.h"
[2413]39#include "network/ClientConnectionListener.h"
[2355]40
41namespace orxonox {
42
43
44  /**
45   *a list of objects of this type will be given by the Server's Gamestate Manager
46   */
47  class objInfo
48  {
49    public:
50      uint32_t objID;
51      uint32_t objCreatorID;
52      uint32_t objCurGS;//current GameState ID
53      uint32_t objDiffGS;//difference between current and latest GameState
54      uint32_t objSize;
[2381]55      int objValuePerm;
56      int objValueSched;
[2355]57      objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched);
58      objInfo();
59  };
60
61/**
62   *a list of objects of this type will be given by the Server's Gamestate Manager
63 */
64  class obj
65  {
66    public:
67      uint32_t objID;
68      uint32_t objCreatorID;
69      uint32_t objSize;
70      uint32_t objDataOffset;
71      obj();
72      obj( uint32_t ID, uint32_t creatorID, uint32_t size, uint32_t offset );
73  };
74 
75
76
77
78/**
79*
80*/
[2413]81class TrafficControl : public ClientConnectionListener {
[2355]82  private:
83
84    /**
85    *permanent client list: contains client ids, object ids and objectInfos (in this order)
86    */
87    std::map<unsigned int, std::map<unsigned int, objInfo > > clientListPerm_;
88    //has to be created with constructor and then needs to be updated by evaluateList().
89
90    /**
91    *temporary client list: contains client ids, gamestate ids and object ids (in this order)
92    */
93    std::map<unsigned int, std::map<unsigned int, std::list<obj> > > clientListTemp_;
94
95    /**updateReferenceList
96    *currentGamestateID and currentClientID will be defined as soon as TrafficControl is being called by Server
97    */
98    unsigned int currentGamestateID;
99    unsigned int currentClientID;
100    unsigned int targetSize;
[2416]101    bool         bActive_;
[2355]102   
[3084]103    void insertinClientListPerm(unsigned int clientID, obj objinf);
104   
105    void cut(std::list<obj>& list, unsigned int targetsize);
106    void updateClientListTemp(std::list<obj>& list);//done
[2355]107    /**
108    *evaluates Data given (list) and produces result(->Data to be updated)
109    */
[3084]110    void evaluateList(unsigned int clientID, std::list<obj>& list);//done   
[2381]111    void ack(unsigned int clientID, unsigned int gamestateID);  // this function gets called when the server receives an ack from the client
[2413]112   
113    //ClientConnectionListener functions
114    virtual void clientConnected(unsigned int clientID){};
115    virtual void clientDisconnected(unsigned int clientID);
116
[2387]117 
[2355]118  protected:
119    static TrafficControl *instance_;
120
121  public:
122    TrafficControl();
123    virtual ~TrafficControl();
124    /**
125    *is being used by GSManager from Server:
126    *list contains: ObjIds, CreatorIds, Size (in this order) from Client XY
127    *Elements of list are accessed by *list[i]
128    *Elements of struct i are therefore: *list[i].objID
129    */
[2413]130    void setConfigValues();
[2382]131    static TrafficControl *getInstance();
[3084]132    void processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>& list); //gets a pointer to the list (containing objectIDs) and sorts it
[2381]133    static void processAck(unsigned int clientID, unsigned int gamestateID)
134    { return instance_->ack(clientID, gamestateID); }
[2355]135    void deleteObject(unsigned int objectID);                           // this function gets called when an object has been deleted (in order to clean up lists and maps)
136   
[2416]137    bool prioritySort(uint32_t clientID, obj i, obj j);
138    bool dataSort(obj i, obj j);
[3084]139    void printList(std::list<obj>& list, unsigned int clientID);
140    void fixCreatorDependencies(std::list<obj>::iterator it, std::list<obj>& list, unsigned int clientID);
[2355]141};
142
143}
144
145#endif
146
Note: See TracBrowser for help on using the repository browser.