Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/network/Synchronisable.h @ 1827

Last change on this file since 1827 was 1827, checked in by scheusso, 16 years ago

another new gamestate concept ;)

  • server does an individual object composition (to be sent) for every client
  • atm objects have sync frequencies and are priorized after their frequency (not clienbased yet)
  • after highlevel diff (object composition) a lowlevel diff is done
  • afterwards compression

→ 65 to 80 percent less data to be transmitted

  • Property svn:eol-style set to native
File size: 4.1 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, (C) 2007
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _Synchronisable_H__
30#define _Synchronisable_H__
31
32#include "NetworkPrereqs.h"
33
34#include <list>
35#include <map>
36#include <queue>
37#include "core/OrxonoxClass.h"
38#include "util/XMLIncludes.h"
39#include "NetworkCallback.h"
40
41#define REGISTERDATA(varname) registerVar(&varname, sizeof(varname), network::DATA)
42#define REGISTERDATA_WITHDIR(varname, mode) registerVar(&varname, sizeof(varname), network::DATA, mode)
43#define REGISTERSTRING(stringname) registerVar(&stringname, stringname.length()+1, network::STRING)
44#define REGISTERSTRING_WITHDIR(stringname, mode) registerVar(&stringname, stringname.length()+1, network::STRING, mode)
45
46namespace network
47{
48  namespace direction{
49    enum syncdirection{
50      toclient=0x1,
51      toserver=0x2,
52      bidirectional=0x3
53    };
54   
55  }
56 
57  enum variableType{
58    DATA,
59    STRING,
60  };
61
62  struct synchronisableHeader{
63    unsigned int size;
64    bool dataAvailable;
65    unsigned int objectID;
66    unsigned int classID;
67  };
68
69  typedef struct synchronisableVariable{
70    unsigned int size;
71    int mode; // this determines in which direction the variable gets synchronised
72    void *var;
73    variableType type;
74    NetworkCallbackBase *callback;
75  }SYNCVAR;
76
77
78  /**
79  * This class is the base class of all the Objects in the universe that need to be synchronised over the network
80   * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list.
81  * @author Oliver Scheuss
82  */
83  class _NetworkExport Synchronisable : virtual public orxonox::OrxonoxClass{
84  public:
85   
86    virtual ~Synchronisable();
87    unsigned int objectID;
88    unsigned int classID;
89
90    bool getData(unsigned char*& men, unsigned int id, int mode=0x0);
91    int getSize(unsigned int id, int mode=0x0);
92    bool updateData(unsigned char*& mem, int mode=0x0);
93    bool isMyData(unsigned char* mem);
94    bool doSelection(unsigned int id);
95    void setObjectMode(int mode);
96    void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }
97   
98    virtual void registerAllVariables()=0;
99    virtual bool create();
100    static void setClient(bool b);
101   
102    static Synchronisable *fabricate(unsigned char*& mem, int mode=0x0);
103    static bool deleteObject(unsigned int objectID);
104    static Synchronisable *getSynchronisable(unsigned int objectID);
105    static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); }
106    static unsigned int popDeletedObject(){ unsigned int i = deletedObjects_.front(); deletedObjects_.pop(); return i; }
107   
108   
109  protected:
110    Synchronisable();
111    void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
112  private:
113    bool isMyTick(unsigned int id);
114    std::list<synchronisableVariable *> *syncList;
115    int datasize;
116    static int state_; // detemines wheter we are server (default) or client
117    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
118    unsigned int objectFrequency_;
119    int objectMode_;
120    static std::map<unsigned int, Synchronisable *> objectMap_;
121    static std::queue<unsigned int> deletedObjects_;
122  };
123}
124
125#endif /* _Synchronisable_H__ */
Note: See TracBrowser for help on using the repository browser.