Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/network/Synchronisable.h @ 1945

Last change on this file since 1945 was 1945, checked in by landauf, 16 years ago

added option "forceCallback" to updateData(…) in Synchronisable to get a callback when synchronizing a variable for the first time (even if it didn't changed)

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