Changeset 1907 for code/trunk/src/network/Synchronisable.h
- Timestamp:
- Oct 12, 2008, 7:40:47 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/Synchronisable.h
r1841 r1907 33 33 34 34 #include <list> 35 #include <map> 36 #include <queue> 35 37 #include "core/OrxonoxClass.h" 36 38 #include "core/XMLIncludes.h" 37 39 #include "NetworkCallback.h" 38 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 46 //TODO: this is only a very ugly hack ... 47 namespace orxonox{ 48 class SpaceShip; 49 } 50 39 51 namespace network 40 52 { 53 namespace direction{ 54 enum syncdirection{ 55 toclient=0x1, 56 toserver=0x2, 57 bidirectional=0x3 58 }; 59 } 60 61 namespace syncmode{ 62 enum mode{ 63 one=0, 64 always=1 65 }; 66 } 67 41 68 enum variableType{ 42 69 DATA, … … 45 72 46 73 struct synchronisableHeader{ 47 unsigned int size; 48 unsigned int objectID; 49 unsigned int classID; 74 uint32_t size:31; 75 bool dataAvailable:1; 76 uint32_t objectID; 77 uint32_t classID; 50 78 }; 51 79 … … 58 86 }SYNCVAR; 59 87 60 61 88 /** 62 89 * 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. 90 * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. 65 91 * @author Oliver Scheuss 66 92 */ 67 93 class _NetworkExport Synchronisable : virtual public orxonox::OrxonoxClass{ 68 94 public: 95 friend class packet::Gamestate; 96 friend class GamestateClient; 97 friend class Server; 98 friend class orxonox::SpaceShip; 99 virtual ~Synchronisable(); 100 69 101 70 virtual ~Synchronisable();71 unsigned int objectID;72 unsigned int classID;73 74 void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);75 bool getData(unsigned char*& men, unsigned int id, int mode=0x0);76 int getSize2(unsigned int id, int mode=0x0);77 bool updateData(unsigned char*& mem, int mode=0x0);78 bool isMyData(unsigned char* mem);79 void setObjectMode(int mode);80 void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }81 82 virtual void registerAllVariables()=0;83 102 virtual bool create(); 84 103 static void setClient(bool b); 85 104 86 static bool fabricate(unsigned char*& mem, int mode=0x0); 105 static Synchronisable *fabricate(uint8_t*& mem, int mode=0x0); 106 static bool deleteObject(unsigned int objectID); 107 static Synchronisable *getSynchronisable(unsigned int objectID); 108 static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); } 109 static unsigned int popDeletedObject(){ unsigned int i = deletedObjects_.front(); deletedObjects_.pop(); return i; } 110 111 inline unsigned int getObjectID(){return objectID;} 112 inline unsigned int getClassID(){return classID;} 87 113 protected: 88 114 Synchronisable(); 115 void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0); 116 void setObjectMode(int mode); 117 void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; } 118 virtual void registerAllVariables()=0; 119 120 89 121 private: 90 int getSize(unsigned int id, int mode=0x0); 122 bool getData(uint8_t*& men, unsigned int id, int mode=0x0); 123 uint32_t getSize(unsigned int id, int mode=0x0); 124 bool updateData(uint8_t*& mem, int mode=0x0); 125 bool isMyData(uint8_t* mem); 126 bool doSelection(unsigned int id); 91 127 bool isMyTick(unsigned int id); 128 129 unsigned int objectID; 130 unsigned int classID; 131 92 132 std::list<synchronisableVariable *> *syncList; 93 int datasize;94 133 static int state_; // detemines wheter we are server (default) or client 95 134 bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server) 96 135 unsigned int objectFrequency_; 97 136 int objectMode_; 137 static std::map<unsigned int, Synchronisable *> objectMap_; 138 static std::queue<unsigned int> deletedObjects_; 98 139 }; 99 140 }
Note: See TracChangeset
for help on using the changeset viewer.