Changeset 7153 for code/branches/presentation3
- Timestamp:
- Jul 12, 2010, 1:08:58 PM (14 years ago)
- Location:
- code/branches/presentation3
- Files:
-
- 52 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3
- Property svn:mergeinfo changed
/code/branches/network2 (added) merged: 6448-6450,6455-6458,6462,6464-6465
- Property svn:mergeinfo changed
-
code/branches/presentation3/src/libraries/network/GamestateClient.cc
r6417 r7153 161 161 assert(b); 162 162 } 163 if(gs->isDiffed()){ 164 packet::Gamestate *base = gamestateMap_[gs->getBaseID()]; 165 if(!base){ 166 COUT(3) << "could not find base gamestate id: " << gs->getBaseID() << endl; 167 delete gs; 168 return 0; 169 } 170 // assert(base); //TODO: fix this 171 packet::Gamestate *undiffed = gs->undiff(base); 172 delete gs; 173 gs=undiffed; 174 COUT(5) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl; 163 if(gs->isDiffed()) 164 { 165 assert(0); 166 // packet::Gamestate *base = gamestateMap_[gs->getBaseID()]; 167 // if(!base) 168 // { 169 // COUT(0) << "could not find base gamestate id: " << gs->getBaseID() << endl; 170 // assert(0); 171 // delete gs; 172 // return 0; 173 // } 174 // packet::Gamestate *undiffed = gs->undiff(base); 175 // delete gs; 176 // gs=undiffed; 177 // COUT(5) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl; 175 178 } 176 179 if(gs->spreadData(0x2)) … … 178 181 else 179 182 { 180 COUT(3) << "could not spread gamestate" << endl; 183 COUT(0) << "could not spread gamestate" << endl; 184 assert(0); 181 185 return NULL; 182 186 } -
code/branches/presentation3/src/libraries/network/GamestateManager.cc
r6417 r7153 43 43 #include <cassert> 44 44 #include <queue> 45 #include "util/Clock.h" 45 46 // #include <boost/thread/mutex.hpp> 46 47 … … 158 159 159 160 clientGamestates.push(0); 160 finishGamestate( cid, &clientGamestates.back(), client, reference );161 finishGamestate( cid, clientGamestates.back(), client, reference ); 161 162 //FunctorMember<GamestateManager>* functor = 162 163 // ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) ); … … 180 181 181 182 182 void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate* *destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {183 void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) { 183 184 //why are we searching the same client's gamestate id as we searched in 184 185 //Server::sendGameState? … … 186 187 //chose wheather the next gamestate is the first or not 187 188 188 packet::Gamestate *gs = gamestate->doSelection(clientID, 20000); 189 // packet::Gamestate *gs = new packet::Gamestate(*gamestate); 189 // packet::Gamestate *gs = gamestate->doSelection(clientID, 20000); 190 // packet::Gamestate* gs = new packet::Gamestate(*gamestate); 191 // packet::Gamestate* gs = gamestate; 192 packet::Gamestate *gs = new packet::Gamestate(*gamestate); //TODO: is this neccessary ? 190 193 // packet::Gamestate *gs = new packet::Gamestate(); 191 194 // gs->collectData( id_, 0x1 ); … … 193 196 gamestateMap_[clientID][gamestate->getID()]=gs; 194 197 // this->threadMutex_->unlock(); 198 Clock clock; 199 clock.capture(); 195 200 196 201 if(base) 197 202 { 198 199 // COUT(3) << "diffing" << std::endl; 200 // packet::Gamestate* gs1 = gs; 201 packet::Gamestate *diffed = gs->diff(base); 202 //packet::Gamestate *gs2 = diffed->undiff(gs); 203 // assert(*gs == *gs2); 204 gs = diffed; 205 // packet::Gamestate* gs2 = gs->undiff(client); 206 // gs = new packet::Gamestate(*gs); 207 // assert(*gs1==*gs2); 208 } 209 else{ 203 packet::Gamestate *diffed1 = gs->diffVariables(base); 204 if( diffed1->getDataSize() == 0 ) 205 { 206 delete diffed1; 207 destgamestate = 0; 208 return; 209 } 210 gs = diffed1; 211 } 212 else 213 { 210 214 gs = new packet::Gamestate(*gs); 211 215 } … … 214 218 bool b = gs->compressData(); 215 219 assert(b); 216 // COUT(4) << "sending gamestate with id " << gs->getID(); 220 clock.capture(); 221 COUT(0) << "diff time: " << clock.getDeltaTime() << endl; 222 // COUT(5) << "sending gamestate with id " << gs->getID(); 217 223 // if(gamestate->isDiffed()) 218 // COUT(4) << " and baseid " << gs->getBaseID() << endl;224 // COUT(5) << " and baseid " << gs->getBaseID() << endl; 219 225 // else 220 // COUT(4) << endl;226 // COUT(5) << endl; 221 227 gs->setClientID(clientID); 222 *destgamestate = gs;228 destgamestate = gs; 223 229 } 224 230 -
code/branches/presentation3/src/libraries/network/GamestateManager.h
r5781 r7153 76 76 void sendGamestates(); 77 77 // packet::Gamestate *popGameState(unsigned int clientID); 78 void finishGamestate( unsigned int clientID, packet::Gamestate* *destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );78 void finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ); 79 79 80 80 bool getSnapshot(); -
code/branches/presentation3/src/libraries/network/Host.h
r6928 r7153 36 36 37 37 const unsigned int CLIENTID_SERVER = 0; 38 const unsigned int NETWORK_FREQUENCY = 30;38 const unsigned int NETWORK_FREQUENCY = 25; 39 39 const float NETWORK_PERIOD = 1.0f/NETWORK_FREQUENCY; 40 40 -
code/branches/presentation3/src/libraries/network/packet/Gamestate.cc
r6417 r7153 45 45 #define PACKET_FLAG_GAMESTATE PacketFlag::Reliable 46 46 47 48 Gamestate::Gamestate() 47 inline bool memzero( uint8_t* data, uint32_t datalength) 48 { 49 uint64_t* d = (uint64_t*)data; 50 51 for( unsigned int i=0; i<datalength/8; i++ ) 52 { 53 if( *(d+i) != 0 ) 54 return false; 55 } 56 // now process the rest (when datalength isn't a multiple of 4) 57 for( unsigned int j = 8*(datalength/8); j<datalength; j++ ) 58 { 59 if( *(data+j) != 0 ) 60 return false; 61 } 62 return true; 63 } 64 65 66 Gamestate::Gamestate(): 67 header_(0) 49 68 { 50 69 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 51 header_ = 0; 52 } 70 } 71 53 72 54 73 Gamestate::Gamestate(uint8_t *data, unsigned int clientID): 55 74 Packet(data, clientID) 56 75 { 57 76 flags_ = flags_ | PACKET_FLAG_GAMESTATE; … … 59 78 } 60 79 80 61 81 Gamestate::Gamestate(uint8_t *data) 62 82 { 63 83 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 64 data_ =data;84 data_ = data; 65 85 header_ = new GamestateHeader(data_); 66 86 } 67 87 88 68 89 Gamestate::Gamestate(const Gamestate& g) : 69 Packet( *(Packet*)&g ) 90 Packet( *(Packet*)&g ), nrOfVariables_(0) 70 91 { 71 92 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 72 93 header_ = new GamestateHeader(data_); 94 sizes_ = g.sizes_; 73 95 } 74 96 … … 79 101 delete header_; 80 102 } 103 81 104 82 105 bool Gamestate::collectData(int id, uint8_t mode) … … 91 114 return false; 92 115 data_ = new uint8_t[size + GamestateHeader::getSize()]; 93 if(!data_){ 116 if(!data_) 117 { 94 118 COUT(2) << "GameStateManager: could not allocate memory" << std::endl; 95 119 return false; … … 101 125 102 126 //start collect data synchronisable by synchronisable 103 uint8_t *mem =data_;127 uint8_t *mem = data_; // in this stream store all data of the variables and the headers of the synchronisable 104 128 mem += GamestateHeader::getSize(); 105 129 ObjectList<Synchronisable>::iterator it; 106 for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 130 for(it = ObjectList<Synchronisable>::begin(); it; ++it) 131 { 107 132 108 133 // tempsize=it->getSize(id, mode); 109 134 110 tempsize = it->getData(mem, id, mode);135 tempsize = it->getData(mem, this->sizes_, id, mode); 111 136 if ( tempsize != 0 ) 112 137 dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) ); 113 138 114 139 #ifndef NDEBUG 115 if(currentsize+tempsize > size){ 140 if(currentsize+tempsize > size) 141 { 116 142 assert(0); // if we don't use multithreading this part shouldn't be neccessary 117 143 // start allocate additional memory … … 148 174 } 149 175 176 150 177 bool Gamestate::spreadData(uint8_t mode) 151 178 { … … 153 180 assert(data_); 154 181 assert(!header_->isCompressed()); 155 assert(!header_->isDiffed());156 182 uint8_t *mem=data_+GamestateHeader::getSize(); 157 183 Synchronisable *s; 158 184 159 185 // update the data of the objects we received 160 while(mem < data_+GamestateHeader::getSize()+header_->getDataSize()){ 186 while(mem < data_+GamestateHeader::getSize()+header_->getDataSize()) 187 { 161 188 SynchronisableHeader objectheader(mem); 162 189 … … 170 197 else 171 198 { 172 mem += objectheader.getDataSize() ;199 mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() ); 173 200 } 174 201 } … … 181 208 // In debug mode, check first, whether there are no duplicate objectIDs 182 209 #ifndef NDEBUG 183 if(this->getID()%1000==0){ 210 if(this->getID()%1000==1) 211 { 184 212 std::list<uint32_t> v1; 185 213 ObjectList<Synchronisable>::iterator it; 186 for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it) { 187 if (it->getObjectID() == OBJECTID_UNKNOWN) { 188 if (it->objectMode_ != 0x0) { 214 for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it) 215 { 216 if (it->getObjectID() == OBJECTID_UNKNOWN) 217 { 218 if (it->objectMode_ != 0x0) 219 { 189 220 COUT(0) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << std::endl; 190 221 COUT(0) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl; … … 193 224 } 194 225 } 195 else { 226 else 227 { 196 228 std::list<uint32_t>::iterator it2; 197 for (it2 = v1.begin(); it2 != v1.end(); ++it2) { 198 if (it->getObjectID() == *it2) { 229 for (it2 = v1.begin(); it2 != v1.end(); ++it2) 230 { 231 if (it->getObjectID() == *it2) 232 { 199 233 COUT(0) << "Found duplicate objectIDs on the client!" << std::endl 200 234 << "Are you sure you don't create a Sychnronisable objcect with 'new' \ … … 211 245 } 212 246 247 213 248 uint32_t Gamestate::getSize() const 214 249 { … … 222 257 } 223 258 224 bool Gamestate::operator==(packet::Gamestate gs){ 259 260 bool Gamestate::operator==(packet::Gamestate gs) 261 { 225 262 uint8_t *d1 = data_+GamestateHeader::getSize(); 226 263 uint8_t *d2 = gs.data_+GamestateHeader::getSize(); … … 233 270 } 234 271 272 235 273 bool Gamestate::process() 236 274 { 237 275 return GamestateHandler::addGamestate(this, getClientID()); 238 276 } 239 240 277 241 278 … … 253 290 int retval; 254 291 retval = compress( dest, &buffer, source, (uLong)(header_->getDataSize()) ); 255 switch ( retval ) { 292 switch ( retval ) 293 { 256 294 case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break; 257 295 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; return false; … … 270 308 header_->setCompSize( buffer ); 271 309 header_->setCompressed( true ); 272 COUT( 5) << "gamestate compress datasize: " << header_->getDataSize() << " compsize: " << header_->getCompSize() << std::endl;310 COUT(0) << "gamestate compress datasize: " << header_->getDataSize() << " compsize: " << header_->getCompSize() << std::endl; 273 311 return true; 274 312 } 313 314 275 315 bool Gamestate::decompressData() 276 316 { … … 289 329 uLongf length=bufsize; 290 330 retval = uncompress( dest, &length, source, (uLong)compsize ); 291 switch ( retval ) { 331 switch ( retval ) 332 { 292 333 case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break; 293 334 case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return false; … … 301 342 delete temp; 302 343 303 if (this->bDataENetAllocated_){ 344 if (this->bDataENetAllocated_) 345 { 304 346 // Memory was allocated by ENet. --> We let it be since enet_packet_destroy will 305 347 // deallocated it anyway. So data and packet stay together. 306 348 this->bDataENetAllocated_ = false; 307 349 } 308 else{ 350 else 351 { 309 352 // We allocated the memory in the first place (unlikely). So we destroy the old data 310 353 // and overwrite it with the new decompressed data. … … 320 363 } 321 364 322 /*Gamestate *Gamestate::diff(Gamestate *base) 323 { 324 assert(data_); 325 assert(!header_->isCompressed()); 365 366 Gamestate* Gamestate::diffVariables(Gamestate *base) 367 { 368 assert(this && base); assert(data_ && base->data_); 369 assert(!header_->isCompressed() && !base->header_->isCompressed()); 326 370 assert(!header_->isDiffed()); 327 GamestateHeader diffHeader(base->data_); 328 uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_); 329 uint32_t of=0; // pointers offset 330 uint32_t dest_length=0; 331 dest_length=header_->getDataSize(); 332 if(dest_length==0) 333 return NULL; 334 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 335 uint8_t *dest = ndata + GamestateHeader::getSize(); 336 while(of < diffHeader.getDataSize() && of < header_->getDataSize()){ 337 *(dest+of)=*(basep+of)^*(gs+of); // do the xor 338 ++of; 339 } 340 if(diffHeader.getDataSize()!=header_->getDataSize()){ 341 uint8_t n=0; 342 if(diffHeader.getDataSize() < header_->getDataSize()){ 343 while(of<dest_length){ 344 *(dest+of)=n^*(gs+of); 345 of++; 346 } 347 } 348 } 349 350 Gamestate *g = new Gamestate(ndata, getClientID()); 371 372 373 // *** first do a raw diff of the two gamestates 374 375 uint8_t *baseData = GAMESTATE_START(base->data_); 376 uint8_t *origData = GAMESTATE_START(this->data_); 377 uint32_t origLength = header_->getDataSize(); 378 uint32_t baseLength = base->header_->getDataSize(); 379 380 assert( origLength && baseLength ); 381 382 uint8_t *nData = new uint8_t[origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_]; // this is the maximum size needed in the worst case 383 uint8_t *dest = GAMESTATE_START(nData); 384 385 uint32_t baseOffset = 0; //offset in the diffed stream 386 uint32_t origOffset = 0; //offset in the new stream with removed 0's 387 std::vector<uint32_t>::iterator sizes = this->sizes_.begin(); 388 389 while( origOffset < origLength ) 390 { 391 //iterate through all objects 392 393 SynchronisableHeader h(origData+origOffset); 394 395 // Find (if possible) the current object in the datastream of the old gamestate 396 // Start at the current offset position 397 if(baseOffset >= baseLength) 398 baseOffset = 0; 399 uint8_t* temp = baseData + baseOffset; 400 uint32_t objectID = h.getObjectID(); 401 assert(temp < baseData+baseLength); 402 assert(dest < nData + origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_); 403 assert(sizes != this->sizes_.end()); 404 while ( temp < baseData+baseLength ) 405 { 406 SynchronisableHeader htemp(temp); 407 if ( htemp.getObjectID() == objectID ) 408 { 409 assert( h.getClassID() == htemp.getClassID() ); 410 goto DODIFF; 411 } 412 temp += htemp.getDataSize()+SynchronisableHeader::getSize(); 413 } 414 // If not found start looking at the beginning 415 temp = baseData; 416 while ( temp < baseData+baseOffset ) 417 { 418 SynchronisableHeader htemp(temp); 419 if ( htemp.getObjectID() == objectID ) 420 { 421 assert( h.getClassID() == htemp.getClassID() ); 422 goto DODIFF; 423 } 424 temp += htemp.getDataSize()+SynchronisableHeader::getSize(); 425 } 426 // Object is new, thus never transmitted -> just copy over 427 goto DOCOPY; 428 429 430 DODIFF: 431 { 432 // if(baseOffset==0) 433 // { 434 // assert(origOffset==0); 435 // } 436 uint32_t objectOffset = SynchronisableHeader::getSize(); // offset inside the object in the origData and baseData 437 // Check whether the whole object stayed the same 438 if( memcmp( origData+origOffset+objectOffset, temp+objectOffset, h.getDataSize()) == 0 ) 439 { 440 origOffset += objectOffset+ h.getDataSize(); // skip the whole object 441 baseOffset = temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData; 442 sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables(); 443 } 444 else 445 { 446 // COUT(4) << "diff " << h.getObjectID() << ":"; 447 // Now start to diff the Object 448 SynchronisableHeaderLight h2(dest); 449 h2 = h; // copy over the objectheader 450 VariableID variableID = 0; 451 uint32_t newObjectOffset = SynchronisableHeaderLight::getSize(); 452 // iterate through all variables 453 while( objectOffset < h.getDataSize()+SynchronisableHeader::getSize() ) 454 { 455 // check whether variable changed and write id and copy over variable to the new stream 456 // otherwise skip variable 457 assert(sizes != this->sizes_.end()); 458 uint32_t varSize = *sizes; 459 assert( varSize == Synchronisable::getSynchronisable(h.getObjectID())->getVarSize(variableID) ); 460 if ( varSize != 0 ) 461 { 462 if ( memcmp(origData+origOffset+objectOffset, temp+objectOffset, varSize) != 0 ) 463 { 464 // COUT(4) << " c" << varSize; 465 *(VariableID*)(dest+newObjectOffset) = variableID; // copy over the variableID 466 newObjectOffset += sizeof(VariableID); 467 memcpy( dest+newObjectOffset, origData+origOffset+objectOffset, varSize ); 468 newObjectOffset += varSize; 469 objectOffset += varSize; 470 } 471 else 472 { 473 // COUT(4) << " s" << varSize; 474 objectOffset += varSize; 475 } 476 } 477 478 ++variableID; 479 ++sizes; 480 } 481 if( Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() != variableID ) 482 sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() - variableID; 483 // COUT(4) << endl; 484 h2.setDiffed(true); 485 h2.setDataSize(newObjectOffset-SynchronisableHeaderLight::getSize()); 486 assert(objectOffset == h.getDataSize()+SynchronisableHeader::getSize()); 487 origOffset += objectOffset; 488 baseOffset += temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData; 489 dest += newObjectOffset; 490 } 491 492 continue; 493 } 494 495 DOCOPY: 496 { 497 // Just copy over the whole Object 498 memcpy( dest, origData+origOffset, h.getDataSize()+SynchronisableHeader::getSize() ); 499 dest += h.getDataSize()+SynchronisableHeader::getSize(); 500 origOffset += h.getDataSize()+SynchronisableHeader::getSize(); 501 assert( Synchronisable::getSynchronisable(h.getObjectID()) ); 502 // COUT(4) << "copy " << h.getObjectID() << endl; 503 // COUT(4) << "copy " << h.getObjectID() << ":"; 504 //sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables(); 505 for( unsigned int i = 0; i < Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables(); ++i ) 506 { 507 // COUT(4) << " " << *sizes; 508 ++sizes; 509 } 510 // COUT(4) << endl; 511 assert(sizes != this->sizes_.end() || origOffset>=origLength); 512 continue; 513 } 514 } 515 516 517 Gamestate *g = new Gamestate(nData, getClientID()); 518 assert(g->header_); 351 519 *(g->header_) = *header_; 352 g->header_->setDiffed( true );353 520 g->header_->setBaseID( base->getID() ); 521 g->header_->setDataSize(dest - nData - GamestateHeader::getSize()); 354 522 g->flags_=flags_; 355 523 g->packetDirection_ = packetDirection_; 524 assert(!g->isCompressed()); 356 525 return g; 357 }*/ 358 359 Gamestate *Gamestate::diff(Gamestate *base) 526 } 527 528 529 Gamestate* Gamestate::diffData(Gamestate *base) 360 530 { 361 531 assert(this && base); assert(data_ && base->data_); … … 393 563 } 394 564 395 Gamestate *Gamestate::undiff(Gamestate *base) 565 566 Gamestate* Gamestate::undiff(Gamestate *base) 396 567 { 397 568 assert(this && base); assert(data_ && base->data_); … … 423 594 424 595 425 // Gamestate *Gamestate::diff(Gamestate *base)426 // {427 // assert(data_);428 // assert(!header_->isCompressed());429 // assert(!header_->isDiffed());430 // GamestateHeader diffHeader(base->data_);431 // uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);432 // uint32_t of=0; // pointers offset433 // uint32_t dest_length=0;434 // dest_length=header_->getDataSize();435 // if(dest_length==0)436 // return NULL;437 // uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];438 // uint8_t *dest = ndata + GamestateHeader::getSize();439 //440 //441 // // LOOP-UNROLLED DIFFING442 // uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs;443 // // diff in 4-byte steps444 // while( of < (uint32_t)(header_->getDataSize())/4 ){445 // if( of < (uint32_t)(diffHeader.getDataSize())/4 )446 // {447 // *(dest32+of)=*(base32+of) ^ *(gs32+of); // do the xor448 // ++of;449 // }450 // else451 // {452 // *(dest32+of)=*(gs32+of); // same as 0 ^ *(gs32+of)453 // ++of;454 // }455 // }456 // for( unsigned int of2 = 0; of2 < header_->getDataSize()%4; ++of2 )457 // {458 // if( of*4+of2 < diffHeader.getDataSize() )459 // {460 // *(dest+4*of+of2)=*(basep+4*of+of2) ^ *(gs+4*of+of2); // do the xor461 // }462 // else463 // {464 // *(dest+4*of+of2)=*(gs+4*of+of2); // same as 0 ^ *(gs32+of)465 // }466 // }467 //468 // Gamestate *g = new Gamestate(ndata, getClientID());469 // *(g->header_) = *header_;470 // g->header_->setDiffed( true );471 // g->header_->setBaseID( base->getID() );472 // g->flags_=flags_;473 // g->packetDirection_ = packetDirection_;474 // return g;475 // }476 477 478 596 void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength) 479 597 { … … 501 619 assert(j==datalength); 502 620 } 621 503 622 504 623 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){ … … 529 648 // COUT(0) << "myvector contains:"; 530 649 // for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ ) 531 // COUT(0) << ' '<< (*itt).objID;650 // COUT(0) << " " << (*itt).objID; 532 651 // COUT(0) << endl; 533 652 for(it=dataVector_.begin(); it!=dataVector_.end();){ 534 653 SynchronisableHeader oldobjectheader(origdata); 535 654 SynchronisableHeader newobjectheader(newdata); 536 if ( it->objSize == 0 )655 if ( (*it).objSize == 0 ) 537 656 { 538 657 ++it; 539 658 continue; 540 659 } 541 objectsize = oldobjectheader.getDataSize() ;660 objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize(); 542 661 objectOffset=SynchronisableHeader::getSize(); //skip the size and the availableData variables in the objectheader 543 if ( it->objID == oldobjectheader.getObjectID() ){662 if ( (*it).objID == oldobjectheader.getObjectID() ){ 544 663 memcpy(newdata, origdata, objectsize); 545 assert(newobjectheader.isDataAvailable()==true);546 664 ++it; 547 665 }else{ 548 666 newobjectheader = oldobjectheader; 549 newobjectheader.setDataAvailable(false);550 667 memset(newdata+objectOffset, 0, objectsize-objectOffset); 551 668 } … … 559 676 { 560 677 SynchronisableHeader oldobjectheader(origdata); 561 objectsize = oldobjectheader.getDataSize() ;678 objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize(); 562 679 origdata += objectsize; 563 680 origsize += objectsize; … … 571 688 572 689 573 /*Gamestate *Gamestate::undiff(Gamestate *base)574 {575 assert(this && base);assert(data_);576 assert(header_->isDiffed());577 assert(!header_->isCompressed() && !base->header_->isCompressed());578 uint8_t *basep = GAMESTATE_START(base->data_);579 uint8_t *gs = GAMESTATE_START(this->data_);580 uint32_t of=0; // pointers offset581 uint32_t dest_length=0;582 dest_length=header_->getDataSize();583 if(dest_length==0)584 return NULL;585 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];586 uint8_t *dest = ndata + GamestateHeader::getSize();587 while(of < base->header_->getDataSize() && of < header_->getDataSize()){588 *(dest+of)=*(basep+of)^*(gs+of); // do the xor589 ++of;590 }591 if(base->header_->getDataSize()!=header_->getDataSize()){592 uint8_t n=0;593 if(base->header_->getDataSize() < header_->getDataSize()){594 while(of < dest_length){595 *(dest+of)=n^*(gs+of);596 of++;597 }598 }599 }600 Gamestate *g = new Gamestate(ndata, getClientID());601 assert(g->header_);602 *(g->header_) = *header_;603 g->header_->setDiffed( false );604 g->flags_=flags_;605 g->packetDirection_ = packetDirection_;606 assert(!g->isDiffed());607 assert(!g->isCompressed());608 return g;609 }*/610 611 690 uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode) 612 691 { 613 uint32_t size=0; 692 uint32_t size = 0; 693 uint32_t nrOfVariables = 0; 614 694 // get the start of the Synchronisable list 615 695 ObjectList<Synchronisable>::iterator it; 616 696 // get total size of gamestate 617 for(it = ObjectList<Synchronisable>::begin(); it; ++it) 697 for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 618 698 size+=it->getSize(id, mode); // size of the actual data of the synchronisable 699 nrOfVariables += it->getNrOfVariables(); 700 } 701 // COUT(0) << "allocating " << nrOfVariables << " ints" << endl; 702 this->sizes_.reserve(nrOfVariables); 619 703 return size; 620 704 } 705 621 706 622 707 } //namespace packet -
code/branches/presentation3/src/libraries/network/packet/Gamestate.h
r6073 r7153 36 36 #include <cstring> 37 37 #include <list> 38 #include <vector> 38 39 39 40 #include "util/CRC32.h" … … 113 114 inline bool isCompressed() const { return header_->isCompressed(); } 114 115 inline int32_t getBaseID() const { return header_->getBaseID(); } 115 Gamestate *diff(Gamestate *base); 116 inline uint32_t getDataSize() const { return header_->getDataSize(); } 117 Gamestate* diffVariables(Gamestate *base); 118 Gamestate* diffData(Gamestate *base); 116 119 Gamestate *undiff(Gamestate *base); 117 120 Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); … … 123 126 private: 124 127 void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength); 128 inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 ); 125 129 virtual uint32_t getSize() const; 126 130 virtual inline bool process(); 127 128 private:129 131 uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0); 130 std::list<obj> dataVector_; 131 GamestateHeader* header_; 132 133 std::list<obj> dataVector_; 134 GamestateHeader* header_; 135 std::vector<uint32_t> sizes_; 136 uint32_t nrOfVariables_; 132 137 }; 133 138 -
code/branches/presentation3/src/libraries/network/packet/Packet.cc
r6417 r7153 69 69 enetPacket_=0; 70 70 bDataENetAllocated_ = false; 71 }72 73 void blub(ENetPacket *packet){74 COUT(4) << "blubb" << std::endl;75 71 } 76 72 -
code/branches/presentation3/src/libraries/network/synchronisable/Serialise.h
r6964 r7153 74 74 return *(uint32_t*)(mem) == variable->getObjectID(); 75 75 else 76 return *(uint32_t*)(mem) == OBJECTID_UNKNOWN;76 return variable == variable->getSynchronisable(*(uint32_t*)(mem)); 77 77 } 78 78 -
code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.cc
r6961 r7153 49 49 * Initializes all Variables and sets the right objectID_ 50 50 */ 51 Synchronisable::Synchronisable(BaseObject* creator ){ 51 Synchronisable::Synchronisable(BaseObject* creator ) 52 { 52 53 RegisterRootObject(Synchronisable); 53 54 static uint32_t idCounter=0; … … 73 74 else 74 75 this->creatorID_ = OBJECTID_UNKNOWN; 75 76 /*searchcreatorID:77 if (creator)78 {79 Synchronisable* synchronisable_creator = orxonox_cast<Synchronisable*>(creator);80 if (synchronisable_creator && synchronisable_creator->objectMode_)81 {82 this->creatorID = synchronisable_creator->getScene()->getObjectID();83 }84 else if (creator != creator->getCreator())85 {86 creator = creator->getCreator();87 goto searchcreatorID;88 }89 }*/90 76 } 91 77 … … 94 80 * Delete all callback objects and remove objectID_ from the objectMap_ 95 81 */ 96 Synchronisable::~Synchronisable(){ 82 Synchronisable::~Synchronisable() 83 { 97 84 // delete callback function objects 98 85 if(!Identifier::isCreatingHierarchy()){ … … 101 88 deletedObjects_.push(objectID_); 102 89 } 103 // delete all Synchronisable Variables from syncList ( which are also in stringList)104 for(std::vector<SynchronisableVariableBase*>::iterator it = syncList .begin(); it!=syncList.end(); it++)90 // delete all Synchronisable Variables from syncList_ ( which are also in stringList_ ) 91 for(std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); it!=syncList_.end(); it++) 105 92 delete (*it); 106 syncList .clear();107 stringList .clear();93 syncList_.clear(); 94 stringList_.clear(); 108 95 std::map<uint32_t, Synchronisable*>::iterator it; 109 96 it = objectMap_.find(objectID_); … … 118 105 * @param b true if this object is located on a client or on a server 119 106 */ 120 void Synchronisable::setClient(bool b){ 107 void Synchronisable::setClient(bool b) 108 { 121 109 if(b) // client 122 110 state_=0x2; … … 135 123 { 136 124 SynchronisableHeader header(mem); 137 138 if(!header.isDataAvailable()) 139 { 140 mem += header.getDataSize(); 141 return 0; 142 } 125 assert( !header.isDiffed() ); 143 126 144 127 COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl; … … 160 143 if (!synchronisable_creator) 161 144 { 162 mem += header.getDataSize() ; //.TODO: this suckz.... remove size from header145 mem += header.getDataSize()+SynchronisableHeader::getSize(); //.TODO: this suckz.... remove size from header 163 146 assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^ 164 147 return 0; … … 198 181 * @return true/false 199 182 */ 200 bool Synchronisable::deleteObject(uint32_t objectID_){ 183 bool Synchronisable::deleteObject(uint32_t objectID_) 184 { 201 185 if(!getSynchronisable(objectID_)) 202 186 return false; … … 215 199 * @return pointer to the Synchronisable with the objectID_ 216 200 */ 217 Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_){ 201 Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_) 202 { 218 203 std::map<uint32_t, Synchronisable*>::iterator it1; 219 204 it1 = objectMap_.find(objectID_); 220 205 if (it1 != objectMap_.end()) 221 206 return it1->second; 222 223 // ObjectList<Synchronisable>::iterator it;224 // for(it = ObjectList<Synchronisable>::begin(); it; ++it){225 // if( it->getObjectID()==objectID_ ){226 // objectMap_[objectID_] = *it;227 // return *it;228 // }229 // }230 207 // if the objects not in the map it should'nt exist at all anymore 231 208 return NULL; … … 247 224 * @return true: if !doSync or if everything was successfully saved 248 225 */ 249 uint32_t Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){ 226 uint32_t Synchronisable::getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode) 227 { 228 unsigned int test = 0; 250 229 if(mode==0x0) 251 230 mode=state_; … … 255 234 uint32_t tempsize = 0; 256 235 #ifndef NDEBUG 236 uint8_t* oldmem = mem; 257 237 if (this->classID_==0) 258 238 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; … … 272 252 // end copy header 273 253 274 275 COUT(5) << "Synchronisable getting data from objectID_: " << objectID_ << " classID_: " << classID_ << std::endl;254 CCOUT(5) << "getting data from objectID_: " << objectID_ << ", classID_: " << classID_ << std::endl; 255 // COUT(4) << "objectid: " << this->objectID_ << ":"; 276 256 // copy to location 277 for(i=syncList.begin(); i!=syncList.end(); ++i){ 278 tempsize += (*i)->getData( mem, mode ); 257 for(i=syncList_.begin(); i!=syncList_.end(); ++i) 258 { 259 uint32_t varsize = (*i)->getData( mem, mode ); 260 // COUT(4) << " " << varsize; 261 tempsize += varsize; 262 sizes.push_back(varsize); 263 ++test; 279 264 //tempsize += (*i)->getSize( mode ); 280 265 } 281 282 tempsize += SynchronisableHeader::getSize(); 266 // COUT(4) << endl; 267 283 268 header.setObjectID( this->objectID_ ); 284 269 header.setCreatorID( this->creatorID_ ); 285 270 header.setClassID( this->classID_ ); 286 header.setDataAvailable( true );287 271 header.setDataSize( tempsize ); 272 assert( tempsize == mem-oldmem-SynchronisableHeader::getSize() ); 273 assert( test == this->getNrOfVariables() ); 274 header.setDiffed(false); 275 tempsize += SynchronisableHeader::getSize(); 288 276 289 277 #ifndef NDEBUG … … 302 290 * @return true/false 303 291 */ 304 bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback){ 292 bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback) 293 { 305 294 if(mode==0x0) 306 295 mode=state_; 307 std::vector<SynchronisableVariableBase *>::iterator i;308 if(syncList.empty()){296 if(syncList_.empty()) 297 { 309 298 assert(0); 310 COUT( 4) << "Synchronisable::updateData syncListis empty" << std::endl;299 COUT(2) << "Synchronisable::updateData syncList_ is empty" << std::endl; 311 300 return false; 312 301 } … … 314 303 uint8_t* data=mem; 315 304 // start extract header 316 SynchronisableHeader syncHeader(mem); 317 assert(syncHeader.getObjectID()==this->objectID_); 318 assert(syncHeader.getCreatorID()==this->creatorID_); 319 assert(syncHeader.getClassID()==this->classID_); 320 if(syncHeader.isDataAvailable()==false){ 321 mem += syncHeader.getDataSize(); 322 return true; 323 } 324 325 mem += SynchronisableHeader::getSize(); 326 // stop extract header 305 SynchronisableHeaderLight syncHeaderLight(mem); 306 assert(syncHeaderLight.getObjectID()==this->getObjectID()); 327 307 328 308 //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl; 329 for(i=syncList.begin(); i!=syncList.end(); i++) 330 { 331 assert( mem <= data+syncHeader.getDataSize() ); // always make sure we don't exceed the datasize in our stream 332 (*i)->putData( mem, mode, forceCallback ); 333 } 334 assert(mem == data+syncHeader.getDataSize()); 309 if( !syncHeaderLight.isDiffed() ) 310 { 311 SynchronisableHeader syncHeader2(mem); 312 assert( this->getClassID() == syncHeader2.getClassID() ); 313 assert( this->getCreatorID() == syncHeader2.getCreatorID() ); 314 mem += SynchronisableHeader::getSize(); 315 std::vector<SynchronisableVariableBase *>::iterator i; 316 for(i=syncList_.begin(); i!=syncList_.end(); i++) 317 { 318 assert( mem <= data+syncHeader2.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream 319 (*i)->putData( mem, mode, forceCallback ); 320 } 321 assert(mem == data+syncHeaderLight.getDataSize()+SynchronisableHeader::getSize() ); 322 } 323 else 324 { 325 mem += SynchronisableHeaderLight::getSize(); 326 // COUT(0) << "objectID: " << this->objectID_ << endl; 327 while( mem < data+syncHeaderLight.getDataSize()+SynchronisableHeaderLight::getSize() ) 328 { 329 VariableID varID = *(VariableID*)mem; 330 // COUT(0) << "varID: " << varID << endl; 331 assert( varID < syncList_.size() ); 332 mem += sizeof(VariableID); 333 syncList_[varID]->putData( mem, mode, forceCallback ); 334 } 335 assert(mem == data+syncHeaderLight.getDataSize()+SynchronisableHeaderLight::getSize() ); 336 } 335 337 return true; 336 338 } … … 342 344 * @return amount of bytes 343 345 */ 344 uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){ 345 int tsize=SynchronisableHeader::getSize(); 346 uint32_t Synchronisable::getSize(int32_t id, uint8_t mode) 347 { 348 uint32_t tsize=SynchronisableHeader::getSize(); 346 349 if (mode==0x0) 347 350 mode=state_; … … 351 354 tsize += this->dataSize_; 352 355 std::vector<SynchronisableVariableBase*>::iterator i; 353 for(i=stringList.begin(); i!=stringList.end(); ++i){ 356 for(i=stringList_.begin(); i!=stringList_.end(); ++i) 357 { 354 358 tsize += (*i)->getSize( mode ); 355 359 } … … 362 366 * @return true/false 363 367 */ 364 bool Synchronisable::doSync(int32_t id, uint8_t mode){ 368 bool Synchronisable::doSync(int32_t id, uint8_t mode) 369 { 365 370 if(mode==0x0) 366 371 mode=state_; 367 return ( (this->objectMode_ & mode)!=0 && (!syncList.empty() ) ); 368 } 369 370 /** 371 * This function looks at the header located in the bytestream and checks wheter objectID_ and classID_ match with the Synchronisables ones 372 * @param mem pointer to the bytestream 373 */ 374 bool Synchronisable::isMyData(uint8_t* mem) 375 { 376 SynchronisableHeader header(mem); 377 assert(header.getObjectID()==this->objectID_); 378 return header.isDataAvailable(); 372 return ( (this->objectMode_ & mode)!=0 && (!syncList_.empty() ) ); 379 373 } 380 374 … … 387 381 * @param mode same as in registerVar 388 382 */ 389 void Synchronisable::setSyncMode(uint8_t mode){ 383 void Synchronisable::setSyncMode(uint8_t mode) 384 { 390 385 assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3); 391 386 this->objectMode_=mode; … … 399 394 else 400 395 sv = new SynchronisableVariable<std::string>(variable, mode, cb); 401 syncList.push_back(sv); 402 stringList.push_back(sv); 396 syncList_.push_back(sv); 397 stringList_.push_back(sv); 398 } 399 400 template <> void Synchronisable::unregisterVariable( std::string& variable ) 401 { 402 bool unregistered_nonexistent_variable = true; 403 std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); 404 while(it!=syncList_.end()) 405 { 406 if( ((*it)->getReference()) == &variable ) 407 { 408 delete (*it); 409 syncList_.erase(it); 410 unregistered_nonexistent_variable = false; 411 break; 412 } 413 else 414 ++it; 415 } 416 assert(unregistered_nonexistent_variable == false); 417 418 it = stringList_.begin(); 419 while(it!=stringList_.end()) 420 { 421 if( ((*it)->getReference()) == &variable ) 422 { 423 delete (*it); 424 stringList_.erase(it); 425 return; 426 } 427 else 428 ++it; 429 } 430 unregistered_nonexistent_variable = true; 431 assert(unregistered_nonexistent_variable == false); //if we reach this point something went wrong: 432 // the variable has not been registered before 403 433 } 404 434 -
code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.h
r7127 r7153 65 65 }; 66 66 } 67 68 typedef uint8_t VariableID; 67 69 68 70 /** … … 72 74 * in an emulated bitset. 73 75 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 74 * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 076 * Bit 32 is a bool and defines whether the variables are stored in diff mode 75 77 * Byte 5 to 8: objectID_ 76 78 * Byte 9 to 12: classID_ … … 78 80 */ 79 81 class _NetworkExport SynchronisableHeader{ 82 friend class SynchronisableHeaderLight; 80 83 private: 81 uint8_t *data_;84 uint8_t* data_; 82 85 public: 83 86 SynchronisableHeader(uint8_t* data) 84 87 { data_ = data; } 85 88 inline static uint32_t getSize() 86 { return 1 6; }87 inline uint 32_t getDataSize() const88 { return (*(uint 32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits89 inline void setDataSize(uint 32_t size)90 { *(uint 32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); }91 inline bool isD ataAvailable() const92 { return ( (*(uint 32_t*)data_) & 0x80000000 ) == 0x80000000; }93 inline void setD ataAvailable( bool b)94 { *(uint 32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }89 { return 14; } 90 inline uint16_t getDataSize() const 91 { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 31 bits 92 inline void setDataSize(uint16_t size) 93 { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); } 94 inline bool isDiffed() const 95 { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; } 96 inline void setDiffed( bool b) 97 { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); } 95 98 inline uint32_t getObjectID() const 96 { return *(uint32_t*)(data_+ 4); }99 { return *(uint32_t*)(data_+2); } 97 100 inline void setObjectID(uint32_t objectID_) 98 { *(uint32_t*)(data_+ 4) = objectID_; }101 { *(uint32_t*)(data_+2) = objectID_; } 99 102 inline uint32_t getClassID() const 100 { return *(uint32_t*)(data_+ 8); }103 { return *(uint32_t*)(data_+6); } 101 104 inline void setClassID(uint32_t classID_) 102 { *(uint32_t*)(data_+ 8) = classID_; }105 { *(uint32_t*)(data_+6) = classID_; } 103 106 inline uint32_t getCreatorID() const 104 { return *(uint32_t*)(data_+1 2); }107 { return *(uint32_t*)(data_+10); } 105 108 inline void setCreatorID(uint32_t creatorID_) 106 { *(uint32_t*)(data_+1 2) = creatorID_; }109 { *(uint32_t*)(data_+10) = creatorID_; } 107 110 inline void operator=(SynchronisableHeader& h) 108 111 { memcpy(data_, h.data_, getSize()); } 109 112 }; 110 113 114 /** 115 * @brief: stores information about a Synchronisable (light version) 116 * 117 * This class stores the information about a Synchronisable (objectID_, dataSize) 118 * in an emulated bitset. 119 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 120 * Bit 32 is a bool and defines whether the variables are stored in diff mode 121 * Byte 5 to 8: objectID_ 122 */ 123 class _NetworkExport SynchronisableHeaderLight{ 124 private: 125 uint8_t* data_; 126 public: 127 SynchronisableHeaderLight(uint8_t* data) 128 { data_ = data; } 129 inline static uint32_t getSize() 130 { return 6; } 131 inline uint16_t getDataSize() const 132 { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 31 bits 133 inline void setDataSize(uint16_t size) 134 { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); } 135 inline bool isDiffed() const 136 { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; } 137 inline void setDiffed( bool b) 138 { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); } 139 inline uint32_t getObjectID() const 140 { return *(uint32_t*)(data_+2); } 141 inline void setObjectID(uint32_t objectID_) 142 { *(uint32_t*)(data_+2) = objectID_; } 143 inline void operator=(SynchronisableHeader& h) 144 { memcpy(data_, h.data_, getSize()); } 145 }; 111 146 112 147 /** … … 135 170 136 171 void setSyncMode(uint8_t mode); 172 173 inline uint32_t getNrOfVariables(){ return this->syncList_.size(); } 174 inline uint32_t getVarSize( VariableID ID ) 175 { return this->syncList_[ID]->getSize(state_); } 137 176 138 177 protected: … … 140 179 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false); 141 180 template <class T> void registerVariable(std::set<T>& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false); 181 template <class T> void unregisterVariable(T& var); 142 182 143 183 void setPriority(unsigned int freq){ objectFrequency_ = freq; } … … 145 185 146 186 private: 147 uint32_t getData(uint8_t*& me n, int32_t id, uint8_t mode=0x0);187 uint32_t getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode); 148 188 uint32_t getSize(int32_t id, uint8_t mode=0x0); 149 189 bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false); 150 bool isMyData(uint8_t* mem);151 190 bool doSync(int32_t id, uint8_t mode=0x0); 152 191 … … 158 197 uint32_t classID_; 159 198 160 std::vector<SynchronisableVariableBase*> syncList ;161 std::vector<SynchronisableVariableBase*> stringList ;199 std::vector<SynchronisableVariableBase*> syncList_; 200 std::vector<SynchronisableVariableBase*> stringList_; 162 201 uint32_t dataSize_; //size of all variables except strings 163 202 static uint8_t state_; // detemines wheter we are server (default) or client … … 173 212 if (bidirectional) 174 213 { 175 syncList .push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb));176 this->dataSize_ += syncList .back()->getSize(state_);214 syncList_.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb)); 215 this->dataSize_ += syncList_.back()->getSize(state_); 177 216 } 178 217 else 179 218 { 180 syncList .push_back(new SynchronisableVariable<T>(variable, mode, cb));219 syncList_.push_back(new SynchronisableVariable<T>(variable, mode, cb)); 181 220 if ( this->state_ == mode ) 182 this->dataSize_ += syncList .back()->getSize(state_);221 this->dataSize_ += syncList_.back()->getSize(state_); 183 222 } 223 } 224 225 template <class T> void Synchronisable::unregisterVariable(T& variable){ 226 std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); 227 while(it!=syncList_.end()){ 228 if( ((*it)->getReference()) == &variable ){ 229 this->dataSize_ -= (*it)->getSize(Synchronisable::state_); 230 delete (*it); 231 syncList_.erase(it); 232 return; 233 } 234 else 235 it++; 236 } 237 bool unregistered_nonexistent_variable = false; 238 assert(unregistered_nonexistent_variable); //if we reach this point something went wrong: 239 // the variable has not been registered before 184 240 } 185 241 … … 191 247 else 192 248 sv = new SynchronisableVariable<std::set<T> >(variable, mode, cb); 193 syncList .push_back(sv);194 stringList .push_back(sv);249 syncList_.push_back(sv); 250 stringList_.push_back(sv); 195 251 } 196 252 197 253 template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 198 254 // template <class T> _NetworkExport void Synchronisable::registerVariable<std::set<T> >( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 255 template <> _NetworkExport void Synchronisable::unregisterVariable( std::string& variable ); 199 256 200 257 -
code/branches/presentation3/src/modules/objects/Planet.h
r6501 r7153 94 94 95 95 protected: 96 void registerVariables();97 96 98 97 private: 98 void registerVariables(); 99 99 100 100 void changedMesh(); -
code/branches/presentation3/src/modules/objects/collisionshapes/BoxCollisionShape.h
r5781 r7153 43 43 virtual ~BoxCollisionShape(); 44 44 45 void registerVariables();46 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 46 … … 67 66 68 67 private: 68 void registerVariables(); 69 69 70 btCollisionShape* createNewShape() const; 70 71 -
code/branches/presentation3/src/modules/objects/collisionshapes/ConeCollisionShape.h
r5781 r7153 41 41 virtual ~ConeCollisionShape(); 42 42 43 void registerVariables();44 43 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 45 44 … … 55 54 56 55 private: 56 void registerVariables(); 57 57 58 btCollisionShape* createNewShape() const; 58 59 -
code/branches/presentation3/src/modules/objects/collisionshapes/PlaneCollisionShape.h
r5781 r7153 43 43 virtual ~PlaneCollisionShape(); 44 44 45 void registerVariables();46 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 46 … … 57 56 58 57 private: 58 void registerVariables(); 59 59 60 btCollisionShape* createNewShape()const; 60 61 -
code/branches/presentation3/src/modules/objects/collisionshapes/SphereCollisionShape.h
r5781 r7153 41 41 virtual ~SphereCollisionShape(); 42 42 43 void registerVariables();44 43 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 45 44 … … 50 49 51 50 private: 51 void registerVariables(); 52 52 53 btCollisionShape* createNewShape() const; 53 54 -
code/branches/presentation3/src/modules/pong/PongBall.h
r5929 r7153 45 45 virtual void tick(float dt); 46 46 47 void registerVariables();48 49 47 void setFieldDimension(float width, float height) 50 48 { this->fieldWidth_ = width; this->fieldHeight_ = height; } … … 74 72 75 73 private: 74 void registerVariables(); 75 76 76 float fieldWidth_; 77 77 float fieldHeight_; -
code/branches/presentation3/src/modules/pong/PongBat.h
r5781 r7153 41 41 virtual ~PongBat() {} 42 42 43 void registerVariables();44 43 virtual void tick(float dt); 45 44 … … 65 64 66 65 private: 66 void registerVariables(); 67 67 68 float movement_; 68 69 bool bMoveLocal_; -
code/branches/presentation3/src/modules/weapons/weaponmodes/RocketFire.cc
r6732 r7153 66 66 rocket->setOrientation(this->getMuzzleOrientation()); 67 67 rocket->setPosition(this->getMuzzlePosition()); 68 rocket->setVelocity(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getVelocity() + this->getMuzzleDirection() * this->speed_); 68 // rocket->setVelocity(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getVelocity() + this->getMuzzleDirection() * this->speed_); 69 rocket->setVelocity(Vector3(1,0,0)); 69 70 rocket->scale(2); 70 71 -
code/branches/presentation3/src/orxonox/CMakeLists.txt
r7152 r7153 34 34 ChatHistory.cc 35 35 ChatInputHandler.cc 36 # Test.cc 36 37 COMPILATION_BEGIN SceneCompilation.cc 37 38 CameraManager.cc -
code/branches/presentation3/src/orxonox/Level.h
r7105 r7153 48 48 49 49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 void registerVariables();51 50 52 51 inline void setDescription(const std::string& description) … … 62 61 63 62 private: 63 void registerVariables(); 64 64 void addObject(BaseObject* object); 65 65 BaseObject* getObject(unsigned int index) const; -
code/branches/presentation3/src/orxonox/Test.h
r7105 r7153 50 50 51 51 void setConfigValues(); 52 void registerVariables();53 52 54 53 static void call(unsigned int clientID); … … 87 86 88 87 private: 88 void registerVariables(); 89 89 90 UTYPE u1; 90 91 UTYPE u2; -
code/branches/presentation3/src/orxonox/collisionshapes/CollisionShape.h
r5781 r7153 45 45 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 void registerVariables();48 47 49 48 inline void setPosition(const Vector3& position) … … 88 87 89 88 private: 89 void registerVariables(); 90 90 91 Vector3 position_; 91 92 Quaternion orientation_; -
code/branches/presentation3/src/orxonox/graphics/Backlight.h
r5781 r7153 45 45 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 void registerVariables();48 47 49 48 virtual void tick(float dt); … … 81 80 82 81 private: 82 void registerVariables(); 83 83 virtual void startturnonoff(); 84 84 virtual void stopturnonoff(); -
code/branches/presentation3/src/orxonox/graphics/Billboard.h
r5781 r7153 46 46 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 void registerVariables();49 48 50 49 virtual void changedVisibility(); … … 78 77 79 78 private: 79 void registerVariables(); 80 80 void changedMaterial(); 81 81 // void changedRotation(); -
code/branches/presentation3/src/orxonox/graphics/BlinkingBillboard.cc
r6417 r7153 66 66 void BlinkingBillboard::registerVariables() 67 67 { 68 // registerVariable(this->amplitude_, VariableDirection::ToClient); 69 // registerVariable(this->frequency_, VariableDirection::ToClient); 70 // registerVariable(this->phase_, VariableDirection::ToClient); 68 unregisterVariable(this->getScale3D()); 69 registerVariable(this->amplitude_, VariableDirection::ToClient); 70 registerVariable(this->frequency_, VariableDirection::ToClient); 71 registerVariable(this->phase_, VariableDirection::ToClient); 72 registerVariable(this->bQuadratic_, VariableDirection::ToClient); 71 73 } 72 74 … … 75 77 SUPER(BlinkingBillboard, tick, dt); 76 78 77 if ( GameMode::isMaster() &&this->isActive())79 if (this->isActive()) 78 80 { 79 81 this->time_ += dt; -
code/branches/presentation3/src/orxonox/graphics/BlinkingBillboard.h
r5781 r7153 45 45 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 void registerVariables();48 47 49 48 virtual void tick(float dt); … … 70 69 71 70 private: 71 void registerVariables(); 72 72 73 float amplitude_; 73 74 float frequency_; -
code/branches/presentation3/src/orxonox/graphics/FadingBillboard.h
r5929 r7153 46 46 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 void registerVariables();49 48 50 49 virtual void tick(float dt); … … 66 65 67 66 protected: 67 void registerVariables(); 68 68 virtual void startturnonoff(); 69 69 virtual void stopturnonoff(); -
code/branches/presentation3/src/orxonox/graphics/GlobalShader.h
r5781 r7153 45 45 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 void registerVariables();48 47 49 48 virtual void changedVisibility(); … … 53 52 54 53 private: 54 void registerVariables(); 55 55 void changedCompositor(); 56 56 -
code/branches/presentation3/src/orxonox/graphics/Light.h
r5781 r7153 57 57 58 58 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 59 void registerVariables();60 59 61 60 virtual void changedVisibility(); … … 132 131 133 132 private: 133 void registerVariables(); 134 134 void setTypeString(const std::string& type); 135 135 std::string getTypeString() const; -
code/branches/presentation3/src/orxonox/graphics/Model.h
r7127 r7153 45 45 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 void registerVariables();48 47 49 48 virtual void changedVisibility(); … … 63 62 64 63 protected: 64 void registerVariables(); 65 65 void changedMesh(); 66 66 void changedShadows(); -
code/branches/presentation3/src/orxonox/graphics/ParticleEmitter.h
r5781 r7153 44 44 45 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 void registerVariables();47 46 48 47 virtual void changedVisibility(); … … 74 73 std::string source_; 75 74 LODParticle::Value LOD_; 75 76 private: 77 void registerVariables(); 76 78 }; 77 79 } -
code/branches/presentation3/src/orxonox/infos/GametypeInfo.h
r7062 r7153 45 45 virtual ~GametypeInfo(); 46 46 47 void registerVariables();48 49 47 inline bool hasStarted() const 50 48 { return this->bStarted_; } … … 74 72 75 73 private: 74 void registerVariables(); 75 76 76 bool bStarted_; 77 77 bool bEnded_; -
code/branches/presentation3/src/orxonox/infos/HumanPlayer.h
r5781 r7153 43 43 virtual ~HumanPlayer(); 44 44 45 void registerVariables();46 45 void setConfigValues(); 47 46 … … 101 100 std::string gametypeHudTemplate_; 102 101 OverlayGroup* gametypeHud_; 102 private: 103 void registerVariables(); 103 104 }; 104 105 } -
code/branches/presentation3/src/orxonox/infos/PlayerInfo.h
r7072 r7153 43 43 PlayerInfo(BaseObject* creator); 44 44 virtual ~PlayerInfo(); 45 46 void registerVariables();47 45 48 46 virtual void changedName(); … … 92 90 93 91 private: 92 void registerVariables(); 94 93 void networkcallback_changedcontrollableentityID(); 95 94 void networkcallback_changedgtinfoID(); -
code/branches/presentation3/src/orxonox/items/Engine.h
r6711 r7153 46 46 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 void registerVariables();49 48 void setConfigValues(); 50 49 … … 127 126 128 127 private: 128 void registerVariables(); 129 129 void networkcallback_shipID(); 130 130 -
code/branches/presentation3/src/orxonox/items/MultiStateEngine.h
r6417 r7153 53 53 54 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 55 void registerVariables();56 55 57 56 virtual void tick(float dt); … … 68 67 69 68 private: 69 void registerVariables(); 70 70 71 int state_; 71 72 int oldState_; -
code/branches/presentation3/src/orxonox/sound/BaseSound.cc
r6502 r7153 248 248 else // No source acquired so far, but might be set to playing or paused 249 249 { 250 State state = this->state_; // save250 State state = static_cast<State>(this->state_); // save 251 251 if (this->isPlaying() || this->isPaused()) 252 252 doPlay(); -
code/branches/presentation3/src/orxonox/sound/BaseSound.h
r6417 r7153 112 112 float volume_; 113 113 bool bLooping_; 114 State state_;114 uint8_t state_; // This Variable is actually of type State 115 115 float pitch_; 116 116 -
code/branches/presentation3/src/orxonox/sound/WorldSound.cc
r6417 r7153 58 58 registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::loopingChanged)); 59 59 registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged)); 60 registerVariable(( int&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));60 registerVariable((uint8_t&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged)); 61 61 } 62 62 -
code/branches/presentation3/src/orxonox/worldentities/BigExplosion.cc
r5929 r7153 101 101 this->debrisEntity3_ = new MovableEntity(this); 102 102 this->debrisEntity4_ = new MovableEntity(this); 103 104 this->debrisEntity1_->setSyncMode(0); 105 this->debrisEntity2_->setSyncMode(0); 106 this->debrisEntity3_->setSyncMode(0); 107 this->debrisEntity4_->setSyncMode(0); 103 108 104 109 this->debris1_ = new Model(this); … … 106 111 this->debris3_ = new Model(this); 107 112 this->debris4_ = new Model(this); 113 114 this->debris1_->setSyncMode(0); 115 this->debris2_->setSyncMode(0); 116 this->debris3_->setSyncMode(0); 117 this->debris4_->setSyncMode(0); 108 118 109 119 this->explosion_ = new StaticEntity(this); 120 this->explosion_->setSyncMode(0); 110 121 111 122 this->debrisSmoke1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); … … 158 169 effect->setSource("Orxonox/explosion2b"); 159 170 effect->setLifetime(4.0f); 171 effect->setSyncMode(0); 160 172 161 173 ParticleSpawner* effect2 = new ParticleSpawner(this->getCreator()); … … 163 175 effect2->setSource("Orxonox/smoke6"); 164 176 effect2->setLifetime(4.0f); 177 effect2->setSyncMode(0); 165 178 166 179 this->explosion_->attach(effect); … … 181 194 MovableEntity* partEntity1 = new MovableEntity(this); 182 195 MovableEntity* partEntity2 = new MovableEntity(this); 196 197 part1->setSyncMode(0); 198 part2->setSyncMode(0); 199 partEntity1->setSyncMode(0); 200 partEntity2->setSyncMode(0); 183 201 184 202 partEntity1->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10,100)); -
code/branches/presentation3/src/orxonox/worldentities/BigExplosion.h
r5929 r7153 45 45 46 46 virtual void tick(float dt); 47 void registerVariables();48 47 49 48 inline void setLOD(LODParticle::Value level) … … 53 52 54 53 private: 54 void registerVariables(); 55 55 56 56 void LODchanged(); -
code/branches/presentation3/src/orxonox/worldentities/ControllableEntity.h
r7073 r7153 49 49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 50 virtual void tick(float dt); 51 void registerVariables();52 51 void setConfigValues(); 53 52 … … 167 166 168 167 private: 168 void registerVariables(); 169 169 void setXMLController(Controller* controller); 170 170 -
code/branches/presentation3/src/orxonox/worldentities/ExplosionChunk.h
r5929 r7153 44 44 45 45 virtual void tick(float dt); 46 void registerVariables();47 46 48 47 inline void setLOD(LODParticle::Value level) … … 52 51 53 52 private: 53 void registerVariables(); 54 54 void LODchanged(); 55 55 void checkStop(); -
code/branches/presentation3/src/orxonox/worldentities/MobileEntity.cc
r5781 r7153 46 46 this->angularAcceleration_ = Vector3::ZERO; 47 47 this->angularVelocity_ = Vector3::ZERO; 48 49 this->registerVariables();50 48 } 51 49 -
code/branches/presentation3/src/orxonox/worldentities/MovableEntity.h
r6417 r7153 48 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 49 virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint); 50 void registerVariables();51 50 52 51 using WorldEntity::setPosition; … … 79 78 80 79 private: 80 void registerVariables(); 81 81 void clientConnected(unsigned int clientID); 82 82 void clientDisconnected(unsigned int clientID); -
code/branches/presentation3/src/orxonox/worldentities/StaticEntity.h
r5781 r7153 42 42 virtual ~StaticEntity(); 43 43 44 void registerVariables();45 46 44 using WorldEntity::setPosition; 47 45 using WorldEntity::setOrientation; … … 51 49 52 50 private: 51 void registerVariables(); 53 52 bool isCollisionTypeLegal(CollisionType type) const; 54 53 -
code/branches/presentation3/src/orxonox/worldentities/WorldEntity.h
r7127 r7153 94 94 95 95 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 96 void registerVariables();97 96 98 97 inline const Ogre::SceneNode* getNode() const … … 214 213 215 214 private: 215 void registerVariables(); 216 216 217 inline void lookAt_xmlport(const Vector3& target) 217 218 { this->lookAt(target); } -
code/branches/presentation3/src/orxonox/worldentities/pawns/Pawn.cc
r7075 r7153 130 130 registerVariable(this->shieldAbsorption_, VariableDirection::ToClient); 131 131 registerVariable(this->bReload_, VariableDirection::ToServer); 132 registerVariable(this->aimPosition_, Bidirectionality::ServerMaster, 0, true);132 registerVariable(this->aimPosition_, VariableDirection::ToServer); // For the moment this variable gets only transfered to the server 133 133 } 134 134 -
code/branches/presentation3/src/orxonox/worldentities/pawns/Pawn.h
r7075 r7153 50 50 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 51 51 virtual void tick(float dt); 52 void registerVariables();53 52 54 53 inline bool isAlive() const … … 166 165 167 166 private: 167 void registerVariables(); 168 168 inline void setWeaponSystem(WeaponSystem* weaponsystem) 169 169 { this->weaponSystem_ = weaponsystem; } -
code/branches/presentation3/src/orxonox/worldentities/pawns/SpaceShip.h
r6711 r7153 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 48 virtual void tick(float dt); 49 void registerVariables();50 49 void setConfigValues(); 51 50 … … 99 98 100 99 private: 100 void registerVariables(); 101 101 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 102 102 103 private:104 103 void loadEngineTemplate(); 105 104 -
code/branches/presentation3/src/orxonox/worldentities/pawns/Spectator.h
r6417 r7153 44 44 45 45 void setConfigValues(); 46 void registerVariables();47 46 virtual void tick(float dt); 48 47 … … 63 62 64 63 private: 64 void registerVariables(); 65 65 void changedGreeting(); 66 66 void changedFlareVisibility();
Note: See TracChangeset
for help on using the changeset viewer.