Changeset 1793 for code/branches/network/src/network/Synchronisable.cc
- Timestamp:
- Sep 17, 2008, 5:24:56 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Synchronisable.cc
r1775 r1793 51 51 namespace network 52 52 { 53 53 54 54 55 std::map<unsigned int, Synchronisable *> Synchronisable::objectMap_; … … 59 60 /** 60 61 * Constructor: 61 * calls registarAllVariables, that has to be implemented by the inheriting classID62 * Initializes all Variables and sets the right objectID 62 63 */ 63 64 Synchronisable::Synchronisable(){ … … 71 72 } 72 73 74 /** 75 * Destructor: 76 * Delete all callback objects and remove objectID from the objectMap_ 77 */ 73 78 Synchronisable::~Synchronisable(){ 74 79 // delete callback function objects … … 81 86 } 82 87 88 /** 89 * This function gets called after all neccessary data has been passed to the object 90 * Overload this function and recall the create function of the parent class 91 * @return true/false 92 */ 83 93 bool Synchronisable::create(){ 84 94 objectMap_[objectID]=this; … … 90 100 91 101 102 /** 103 * This function sets the internal mode for synchronisation 104 * @param b true if this object is located on a client or on a server 105 */ 92 106 void Synchronisable::setClient(bool b){ 93 107 if(b) // client … … 97 111 } 98 112 113 /** 114 * This function fabricated a new synchrnisable (and children of it), sets calls updateData and create 115 * After calling this function the mem pointer will be increased by the size of the needed data 116 * @param mem pointer to where the appropriate data is located 117 * @param mode defines the mode, how the data should be loaded 118 * @return pointer to the newly created synchronisable 119 */ 99 120 Synchronisable *Synchronisable::fabricate(unsigned char*& mem, int mode) 100 121 { … … 119 140 120 141 142 /** 143 * Finds and deletes the Synchronisable with the appropriate objectID 144 * @param objectID objectID of the Synchronisable 145 * @return true/false 146 */ 121 147 bool Synchronisable::deleteObject(unsigned int objectID){ 122 148 assert(getSynchronisable(objectID)); … … 126 152 } 127 153 154 /** 155 * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable 156 * @param objectID objectID of the Synchronisable 157 * @return pointer to the Synchronisable with the objectID 158 */ 128 159 Synchronisable* Synchronisable::getSynchronisable(unsigned int objectID){ 129 160 std::map<unsigned int, Synchronisable *>::iterator i = objectMap_.find(objectID); … … 140 171 * @param var pointer to the variable 141 172 * @param size size of the datatype the variable consists of 173 * @param t the type of the variable (network::DATA or network::STRING 174 * @param mode same as in getData 175 * @param cb callback object that should get called, if the value of the variable changes 142 176 */ 143 177 void Synchronisable::registerVar(void *var, int size, variableType t, int mode, NetworkCallbackBase *cb){ … … 158 192 159 193 /** 160 * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct 161 * Difference to the above function: 194 * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID and classID to the given memory 162 195 * takes a pointer to already allocated memory (must have at least getSize bytes length) 163 196 * structure of the bitstream: 164 * (var1_size,var1,var2_size,var2,...) 165 * varx_size: size = sizeof(int) 166 * varx: size = varx_size 167 * @return data containing all variables and their sizes 197 * |totalsize,objectID,classID,var1,var2,string1_length,string1,var3,...| 198 * length of varx: size saved int syncvarlist 199 * @param mem pointer to allocated memory with enough size 200 * @param id gamestateid of the gamestate to be saved (important for priorities) 201 * @param mode defines the direction in which the data will be send/received 202 * 0x1: server->client 203 * 0x2: client->server (not recommended) 204 * 0x3: bidirectional 205 * @return true: if !isMyTick or if everything was successfully saved 168 206 */ 169 207 bool Synchronisable::getData(unsigned char*& mem, unsigned int id, int mode){ … … 224 262 225 263 /** 226 * This function takes a syncData struct and takes it to update the variables 227 * @param vars data of the variables 264 * This function takes a bytestream and loads the data into the registered variables 265 * @param mem pointer to the bytestream 266 * @param mode same as in getData 228 267 * @return true/false 229 268 */ … … 288 327 /** 289 328 * This function returns the total amount of bytes needed by getData to save the whole content of the variables 329 * @param id id of the gamestate 330 * @param mode same as getData 290 331 * @return amount of bytes 291 332 */ … … 316 357 317 358 /** 318 * 319 * @param id 320 * @return 359 * This function determines, wheter the object should be saved to the bytestream (according to its syncfrequency) 360 * @param id gamestate id 361 * @return true/false 321 362 */ 322 363 bool Synchronisable::isMyTick(unsigned int id){ … … 325 366 } 326 367 368 /** 369 * This function looks at the header located in the bytestream and checks wheter objectID and classID match with the Synchronisables ones 370 * @param mem pointer to the bytestream 371 */ 327 372 bool Synchronisable::isMyData(unsigned char* mem) 328 373 { … … 339 384 } 340 385 386 /** 387 * This function sets the synchronisation mode of the object 388 * If set to 0x1 variables will only be synchronised to the client 389 * If set to 0x2 variables will only be synchronised to the server 390 * If set to 0x3 variables will be synchronised bidirectionally (only if set so in registerVar) 391 * @param mode same as in registerVar 392 */ 341 393 void Synchronisable::setObjectMode(int mode){ 342 394 assert(mode==0x1 || mode==0x2 || mode==0x3);
Note: See TracChangeset
for help on using the changeset viewer.