Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/network/TrafficControl.h @ 12288

Last change on this file since 12288 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

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