[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> |
---|
| 35 | #include "core/OrxonoxClass.h" |
---|
[1841] | 36 | #include "core/XMLIncludes.h" |
---|
[1534] | 37 | #include "NetworkCallback.h" |
---|
[1505] | 38 | |
---|
| 39 | namespace network |
---|
| 40 | { |
---|
| 41 | enum variableType{ |
---|
| 42 | DATA, |
---|
| 43 | STRING, |
---|
| 44 | }; |
---|
| 45 | |
---|
[1751] | 46 | struct synchronisableHeader{ |
---|
| 47 | unsigned int size; |
---|
[1735] | 48 | unsigned int objectID; |
---|
| 49 | unsigned int classID; |
---|
[1505] | 50 | }; |
---|
| 51 | |
---|
| 52 | typedef struct synchronisableVariable{ |
---|
[1735] | 53 | unsigned int size; |
---|
[1505] | 54 | int mode; // this determines in which direction the variable gets synchronised |
---|
| 55 | void *var; |
---|
| 56 | variableType type; |
---|
[1534] | 57 | NetworkCallbackBase *callback; |
---|
[1505] | 58 | }SYNCVAR; |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | /** |
---|
| 62 | * This class is the base class of all the Objects in the universe that need to be synchronised over the network |
---|
| 63 | * Every class, t |
---|
| 64 | int mode;hat inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. Additionally it also has to provide a Constructor, that takes exactly the variables in this linked list. |
---|
| 65 | * @author Oliver Scheuss |
---|
| 66 | */ |
---|
| 67 | class _NetworkExport Synchronisable : virtual public orxonox::OrxonoxClass{ |
---|
| 68 | public: |
---|
[1751] | 69 | |
---|
[1505] | 70 | virtual ~Synchronisable(); |
---|
[1735] | 71 | unsigned int objectID; |
---|
| 72 | unsigned int classID; |
---|
[1505] | 73 | |
---|
[1534] | 74 | void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0); |
---|
[1751] | 75 | bool getData(unsigned char*& men, unsigned int id, int mode=0x0); |
---|
| 76 | int getSize2(unsigned int id, int mode=0x0); |
---|
[1735] | 77 | bool updateData(unsigned char*& mem, int mode=0x0); |
---|
| 78 | bool isMyData(unsigned char* mem); |
---|
[1751] | 79 | void setObjectMode(int mode); |
---|
| 80 | void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; } |
---|
| 81 | |
---|
[1505] | 82 | virtual void registerAllVariables()=0; |
---|
| 83 | virtual bool create(); |
---|
| 84 | static void setClient(bool b); |
---|
[1735] | 85 | |
---|
| 86 | static bool fabricate(unsigned char*& mem, int mode=0x0); |
---|
[1505] | 87 | protected: |
---|
| 88 | Synchronisable(); |
---|
| 89 | private: |
---|
[1751] | 90 | int getSize(unsigned int id, int mode=0x0); |
---|
| 91 | bool isMyTick(unsigned int id); |
---|
[1505] | 92 | std::list<synchronisableVariable *> *syncList; |
---|
| 93 | int datasize; |
---|
| 94 | static int state_; // detemines wheter we are server (default) or client |
---|
| 95 | bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server) |
---|
[1751] | 96 | unsigned int objectFrequency_; |
---|
| 97 | int objectMode_; |
---|
[1505] | 98 | }; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | #endif /* _Synchronisable_H__ */ |
---|