Changeset 2087 for code/trunk/src/network/Synchronisable.h
- Timestamp:
- Nov 1, 2008, 7:04:09 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/network/Synchronisable.h
r1910 r2087 41 41 #include "util/Integers.h" 42 42 43 #define REGISTERDATA(varname) registerVar(&varname, sizeof(varname), network::DATA) 44 #define REGISTERDATA_WITHDIR(varname, mode) registerVar(&varname, sizeof(varname), network::DATA, mode) 45 #define REGISTERSTRING(stringname) registerVar(&stringname, stringname.length()+1, network::STRING) 46 #define REGISTERSTRING_WITHDIR(stringname, mode) registerVar(&stringname, stringname.length()+1, network::STRING, mode) 47 48 //TODO: this is only a very ugly hack ... 49 namespace orxonox{ 50 class SpaceShip; 51 } 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__) 52 47 53 48 namespace network 54 49 { 50 static const unsigned int OBJECTID_UNKNOWN = (unsigned int)-1; 51 55 52 namespace direction{ 56 53 enum syncdirection{ 57 54 toclient=0x1, 58 55 toserver=0x2, 59 bidirectional=0x3 56 bidirectional=0x3, 57 serverMaster=0x3, 58 clientMaster=0x7 60 59 }; 61 60 } 62 61 63 62 namespace syncmode{ 64 63 enum mode{ … … 67 66 }; 68 67 } 69 68 70 69 enum variableType{ 71 70 DATA, … … 73 72 }; 74 73 75 struct synchronisableHeader{74 struct _NetworkExport synchronisableHeader{ 76 75 uint32_t size:31; 77 76 bool dataAvailable:1; 78 77 uint32_t objectID; 78 uint32_t creatorID; 79 79 uint32_t classID; 80 80 }; 81 81 82 typedef struct synchronisableVariable{82 struct _NetworkExport synchronisableVariable{ 83 83 unsigned int size; 84 84 int mode; // this determines in which direction the variable gets synchronised … … 86 86 variableType type; 87 87 NetworkCallbackBase *callback; 88 }SYNCVAR; 88 void *varBuffer; 89 uint8_t varReference; 90 }; 89 91 90 92 /** … … 98 100 friend class GamestateClient; 99 101 friend class Server; 100 friend class orxonox::SpaceShip;101 102 virtual ~Synchronisable(); 102 103 103 104 104 105 virtual bool create(); 105 106 static void setClient(bool b); 106 107 107 108 static Synchronisable *fabricate(uint8_t*& mem, int mode=0x0); 108 109 static bool deleteObject(unsigned int objectID); … … 110 111 static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); } 111 112 static unsigned int popDeletedObject(){ unsigned int i = deletedObjects_.front(); deletedObjects_.pop(); return i; } 112 113 113 114 inline unsigned int getObjectID(){return objectID;} 114 115 inline unsigned int getClassID(){return classID;} 115 116 protected: 116 Synchronisable( );117 Synchronisable(orxonox::BaseObject* creator); 117 118 void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0); 118 119 void setObjectMode(int mode); 119 120 void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; } 120 virtual void registerAllVariables()=0; 121 122 121 122 123 123 private: 124 124 bool getData(uint8_t*& men, unsigned int id, int mode=0x0); 125 125 uint32_t getSize(unsigned int id, int mode=0x0); 126 bool updateData(uint8_t*& mem, int mode=0x0 );126 bool updateData(uint8_t*& mem, int mode=0x0, bool forceCallback=false); 127 127 bool isMyData(uint8_t* mem); 128 128 bool doSelection(unsigned int id); 129 bool isMyTick(unsigned int id);130 129 bool doSync(unsigned int id); 130 131 131 unsigned int objectID; 132 unsigned int creatorID; 132 133 unsigned int classID; 133 134 134 135 std::list<synchronisableVariable *> *syncList; 135 136 static int state_; // detemines wheter we are server (default) or client
Note: See TracChangeset
for help on using the changeset viewer.