Changeset 2011 for code/branches/objecthierarchy/src
- Timestamp:
- Oct 25, 2008, 7:56:40 PM (16 years ago)
- Location:
- code/branches/objecthierarchy/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/network/Synchronisable.cc
r1990 r2011 42 42 43 43 #include <cstring> 44 #include <string> 44 45 #include <iostream> 45 46 #include <assert.h> … … 198 199 */ 199 200 void Synchronisable::registerVar(void *var, int size, variableType t, int mode, NetworkCallbackBase *cb){ 201 assert( mode==direction::toclient || mode==direction::toserver || mode==direction::serverMaster || mode==direction::clientMaster); 200 202 // create temporary synch.Var struct 201 203 synchronisableVariable *temp = new synchronisableVariable; … … 205 207 temp->type = t; 206 208 temp->callback = cb; 209 if( ( mode & direction::bidirectional ) ) 210 { 211 temp->varBuffer = new uint8_t[size]; 212 memcpy(temp->varBuffer, temp->var, size); //now fill the buffer for the first time 213 temp->varReference = 0; 214 } 207 215 COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl; 208 216 //std::cout << "push temp to syncList (at the bottom) " << datasize << std::endl; … … 270 278 continue; // this variable should only be received 271 279 } 280 // if the variable gets synchronised bidirectional, then add the reference to the bytestream 281 if( ( (*i)->mode & direction::bidirectional ) ) 282 { 283 *(uint8_t*)mem = (*i)->varReference; 284 mem += sizeof( (*i)->varReference ); 285 } 272 286 switch((*i)->type){ 273 287 case DATA: 274 288 memcpy( (void *)(mem), (void*)((*i)->var), (*i)->size); 275 289 mem+=(*i)->size; 276 tempsize+=(*i)->size ;290 tempsize+=(*i)->size + sizeof( (*i)->varReference ); 277 291 break; 278 292 case STRING: 279 memcpy( (void *)(mem), (void *)&((*i)->size), sizeof( int) );280 mem+=sizeof( int);293 memcpy( (void *)(mem), (void *)&((*i)->size), sizeof(size_t) ); 294 mem+=sizeof(size_t); 281 295 const char *data = ( ( *(std::string *) (*i)->var).c_str()); 282 296 memcpy( mem, (void*)data, (*i)->size); 283 297 COUT(5) << "synchronisable: char: " << (const char *)(mem) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl; 284 298 mem+=(*i)->size; 285 tempsize+=(*i)->size + 4;299 tempsize+=(*i)->size + sizeof( (*i)->varReference ) + sizeof(size_t); 286 300 break; 287 301 } … … 331 345 switch((*i)->type){ 332 346 case DATA: 347 if( ( (*i)->mode & direction::bidirectional ) ) 348 { 349 if( ( mode == 0x1 && (*i)->mode == direction::serverMaster ) || \ 350 ( mode == 0x2 && (*i)->mode == direction::clientMaster ) ) // if true we are master on this variable 351 { 352 uint8_t refNr = *(uint8_t *)mem; 353 if( refNr != (*i)->varReference ) 354 { 355 mem += sizeof((*i)->varReference) + (*i)->size; // the reference for this variable is not recent, discard data 356 break; 357 } 358 } 359 else //we are slave for this variable 360 { 361 (*i)->varReference = *(uint8_t *)mem; //copy the reference value for this variable 362 } 363 mem += sizeof((*i)->varReference); 364 } 333 365 if((*i)->callback) // check whether this variable changed (but only if callback was set) 334 366 if(strncmp((char *)(*i)->var, (char *)mem, (*i)->size)!=0) … … 338 370 break; 339 371 case STRING: 340 (*i)->size = *(uint32_t *)mem; 372 if( ( (*i)->mode & direction::bidirectional ) ) 373 { 374 if( ( mode == 0x1 && (*i)->mode == direction::serverMaster ) || \ 375 ( mode == 0x2 && (*i)->mode == direction::clientMaster ) ) // if true we are master for this variable 376 { 377 uint8_t refNr = *(uint8_t *)mem; 378 mem += sizeof( (*i)->varReference ); 379 if( refNr != (*i)->varReference ){ 380 mem += sizeof(size_t) + *(size_t *)mem; // the reference for this variable is not recent, discard data 381 break; 382 } 383 } 384 else //we are slave for this variable 385 { 386 (*i)->varReference = *(uint8_t *)mem; //copy the reference value for this variable 387 } 388 mem += sizeof( (*i)->varReference ); 389 } 390 (*i)->size = *(size_t *)mem; 341 391 COUT(5) << "string size: " << (*i)->size << std::endl; 342 mem +=sizeof(int);392 mem += sizeof(size_t); 343 393 if((*i)->callback) // check whether this string changed 344 394 if( *(std::string *)((*i)->var) != std::string((char *)mem) ) … … 383 433 break; 384 434 } 435 if( ( (*i)->mode & direction::bidirectional ) != 0) 436 { 437 tsize+=sizeof( (*i)->varReference ); 438 } 385 439 } 386 440 return tsize; -
code/branches/objecthierarchy/src/network/Synchronisable.h
r1990 r2011 54 54 toclient=0x1, 55 55 toserver=0x2, 56 bidirectional=0x3 56 bidirectional=0x3, 57 serverMaster=0x3, 58 clientMaster=0x7 57 59 }; 58 60 } … … 77 79 }; 78 80 79 typedefstruct _NetworkExport synchronisableVariable{81 struct _NetworkExport synchronisableVariable{ 80 82 unsigned int size; 81 83 int mode; // this determines in which direction the variable gets synchronised … … 83 85 variableType type; 84 86 NetworkCallbackBase *callback; 85 }SYNCVAR; 87 void *varBuffer; 88 uint8_t varReference; 89 }; 86 90 87 91 /** -
code/branches/objecthierarchy/src/orxonox/Settings.cc
r1949 r2011 62 62 void Settings::setConfigValues() 63 63 { 64 SetConfigValue(dataPath_, "../../ Media/").description("Relative path to the game data.").callback(this, &Settings::dataPathChanged);64 SetConfigValue(dataPath_, "../../media/").description("Relative path to the game data.").callback(this, &Settings::dataPathChanged); 65 65 } 66 66
Note: See TracChangeset
for help on using the changeset viewer.