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