Changeset 7759 for code/branches/network5/src/libraries/network/packet
- Timestamp:
- Dec 14, 2010, 8:54:00 PM (14 years ago)
- Location:
- code/branches/network5/src/libraries/network/packet
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network5/src/libraries/network/packet/FunctionCalls.cc
r7495 r7759 32 32 #include "network/FunctionCall.h" 33 33 #include "network/FunctionCallManager.h" 34 #include "network/GamestateHandler.h" 34 35 35 36 namespace orxonox { … … 40 41 const unsigned int FUNCTIONCALLS_MEM_ALLOCATION = 1000; 41 42 42 FunctionCalls::FunctionCalls() 43 : Packet()43 FunctionCalls::FunctionCalls(): 44 Packet(), minGamestateID_(GAMESTATEID_INITIAL) 44 45 { 45 46 flags_ = flags_ | PACKET_FLAGS_FUNCTIONCALLS; 46 currentSize_ = 2*sizeof(uint32_t); // for packetid and nrOfCalls47 currentSize_ = 3*sizeof(uint32_t); // for packetid, nrOfCalls and minGamestateID_ 47 48 } 48 49 49 FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID ) 50 : Packet(data, clientID)50 FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID ): 51 Packet(data, clientID), minGamestateID_(GAMESTATEID_INITIAL) 51 52 { 52 53 } … … 63 64 uint32_t nrOfCalls = *(uint32_t*)temp; 64 65 temp += sizeof(uint32_t); 66 this->minGamestateID_ = *(uint32_t*)temp; 67 temp += sizeof(uint32_t); 65 68 for( unsigned int i = 0; i<nrOfCalls; i++ ) 66 69 { 67 70 FunctionCall fctCall; 68 71 fctCall.loadData(temp); 69 if( !fctCall.execute() ) 70 FunctionCallManager::bufferIncomingFunctionCall( fctCall ); 72 if( this->minGamestateID_ > GamestateHandler::getInstance()->getLastProcessedGamestateID(this->getClientID()) || !fctCall.execute() ) 73 { 74 FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getClientID() ); 75 } 71 76 } 72 77 … … 93 98 bool FunctionCalls::send() 94 99 { 100 this->minGamestateID_ = GamestateHandler::getInstance()->getCurrentGamestateID(); 95 101 assert(this->functionCalls_.size()); 96 102 data_=new uint8_t[ currentSize_ ]; 97 103 *(Type::Value *)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID 98 *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls to 0 99 uint8_t* temp = data_+2*sizeof(uint32_t); 104 *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls 105 *(uint32_t*)(data_+2*sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_ 106 uint8_t* temp = data_+3*sizeof(uint32_t); 100 107 101 108 while( this->functionCalls_.size() ) -
code/branches/network5/src/libraries/network/packet/FunctionCalls.h
r7490 r7759 62 62 std::queue<orxonox::FunctionCall> functionCalls_; 63 63 unsigned int clientID_; 64 uint32_t minGamestateID_; 64 65 uint32_t currentSize_; 65 66 }; -
code/branches/network5/src/libraries/network/packet/Gamestate.cc
r7758 r7759 43 43 #define GAMESTATE_START(data) (data + GamestateHeader::getSize()) 44 44 45 #define PACKET_FLAG_GAMESTATE 0 //PacketFlag::Reliable 45 // #define PACKET_FLAG_GAMESTATE PacketFlag::Unsequenced 46 // #define PACKET_FLAG_GAMESTATE 0 47 #define PACKET_FLAG_GAMESTATE PacketFlag::Reliable 46 48 47 49 inline bool memzero( uint8_t* data, uint32_t datalength) … … 364 366 inline void /*Gamestate::*/diffObject( uint8_t*& newDataPtr, uint8_t*& origDataPtr, uint8_t*& baseDataPtr, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ) 365 367 { 366 // COUT(4) << "dodiff" << endl;367 // if(baseOffset==0)368 // {369 // assert(origOffset==0);370 // }371 368 assert( objectHeader.getDataSize() == SynchronisableHeader(baseDataPtr).getDataSize() ); 372 369 … … 382 379 else 383 380 { 384 // if( Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() == "Bot" )385 // COUT(0) << "blub" << endl;386 // COUT(4) << "object diff: " << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;387 // COUT(4) << "diff " << h.getObjectID() << ":";388 381 // Now start to diff the Object 389 382 SynchronisableHeaderLight newObjectHeader(newDataPtr); … … 396 389 // check whether variable changed and write id and copy over variable to the new stream 397 390 // otherwise skip variable 398 // assert(sizes != this->sizes_.end());399 391 uint32_t varSize = *sizes; 400 392 assert( varSize == Synchronisable::getSynchronisable(objectHeader.getObjectID())->getVarSize(variableID) ); … … 403 395 if ( memcmp(origDataPtr+objectOffset, baseDataPtr+objectOffset, varSize) != 0 ) 404 396 { 405 // COUT(4) << "copy variable" << endl;406 397 *(VariableID*)(newDataPtr+diffedObjectOffset) = variableID; // copy over the variableID 407 398 diffedObjectOffset += sizeof(VariableID); … … 412 403 else 413 404 { 414 // COUT(4) << "skip variable" << endl;415 405 objectOffset += varSize; 416 406 } 417 407 } 418 // else419 // COUT(4) << "varsize 0" << endl;420 408 421 409 ++variableID; 422 410 ++sizes; 423 411 } 424 412 413 // if there are variables from this object with 0 size left in sizes 425 414 if( Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() != variableID ) 426 415 sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() - variableID; 427 // COUT(4) << endl;428 416 429 417 newObjectHeader.setDiffed(true); … … 431 419 assert(objectOffset == objectHeader.getDataSize()+SynchronisableHeader::getSize()); 432 420 assert(newObjectHeader.getDataSize()>0); 421 433 422 origDataPtr += objectOffset; 434 // baseOffset += temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData;435 //baseOffset += objectOffset;436 // SynchronisableHeader htemp(temp);437 // baseOffset += SynchronisableHeader::getSize() + htemp.getDataSize();438 // {439 // SynchronisableHeader htemp2( baseData+(temp-baseData+objectOffset) );440 // if( baseData+(temp-baseData+objectOffset) < baseData+baseLength )441 // {442 // assert(htemp2.getClassID()<500);443 // assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);444 // assert(htemp2.isDiffed()==false);445 // }446 // }447 423 baseDataPtr += objectOffset; 448 424 newDataPtr += diffedObjectOffset; … … 455 431 // Just copy over the whole Object 456 432 memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() ); 433 SynchronisableHeader(newData).setDiffed(false); 434 457 435 newData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); 458 436 origData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); … … 547 525 assert(sizesIt != this->sizes_.end()); 548 526 527 assert(Synchronisable::getSynchronisable(origHeader.getObjectID())); 528 assert(ClassByID(origHeader.getClassID())); 529 assert(origHeader.getDataSize() < 500); 530 549 531 bool diffedObject = false; 550 532 if( findObject(baseDataPtr, baseDataEnd, origHeader) ) 551 533 { 534 SynchronisableHeader baseHeader(baseDataPtr); 535 assert(Synchronisable::getSynchronisable(baseHeader.getObjectID())); 536 assert(ClassByID(baseHeader.getClassID())); 537 assert(baseHeader.getDataSize() < 500); 552 538 if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() ) 553 539 { … … 570 556 if( findObject(baseDataPtr, oldBaseDataPtr, origHeader) ) 571 557 { 558 SynchronisableHeader baseHeader(baseDataPtr); 559 assert(Synchronisable::getSynchronisable(baseHeader.getObjectID())); 560 assert(ClassByID(baseHeader.getClassID())); 561 assert(baseHeader.getDataSize() < 500); 572 562 if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() ) 573 563 { -
code/branches/network5/src/libraries/network/packet/Packet.cc
r7163 r7759 53 53 54 54 // Make sure we assume the right values 55 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable) == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));56 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequence ) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));57 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate) == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));55 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable) == static_cast<int>(ENET_PACKET_FLAG_RELIABLE)); 56 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequenced) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED)); 57 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate) == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE)); 58 58 59 59 #define PACKET_FLAG_DEFAULT PacketFlag::NoAllocate … … 174 174 unsigned int clientID = ClientInformation::findClient(&peer->address)->getID(); 175 175 Packet *p = 0; 176 COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;176 // COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl; 177 177 switch( *(Type::Value *)(data + _PACKETID) ) 178 178 { 179 179 case Type::Acknowledgement: 180 COUT(5) << "ack" << std::endl;180 // COUT(5) << "ack" << std::endl; 181 181 p = new Acknowledgement( data, clientID ); 182 182 break; 183 183 case Type::Chat: 184 COUT(5) << "chat" << std::endl;184 // COUT(5) << "chat" << std::endl; 185 185 p = new Chat( data, clientID ); 186 186 break; 187 187 case Type::ClassID: 188 COUT(5) << "classid" << std::endl;188 // COUT(5) << "classid" << std::endl; 189 189 p = new ClassID( data, clientID ); 190 190 break; 191 191 case Type::Gamestate: 192 COUT(5) << "gamestate" << std::endl; 193 // TODO: remove brackets 192 // COUT(5) << "gamestate" << std::endl; 194 193 p = new Gamestate( data, clientID ); 195 194 break; 196 195 case Type::Welcome: 197 COUT(5) << "welcome" << std::endl;196 // COUT(5) << "welcome" << std::endl; 198 197 p = new Welcome( data, clientID ); 199 198 break; 200 199 case Type::DeleteObjects: 201 COUT(5) << "deleteobjects" << std::endl;200 // COUT(5) << "deleteobjects" << std::endl; 202 201 p = new DeleteObjects( data, clientID ); 203 202 break; 204 203 case Type::FunctionCalls: 205 COUT(5) << "functionCalls" << std::endl;204 // COUT(5) << "functionCalls" << std::endl; 206 205 p = new FunctionCalls( data, clientID ); 207 206 break; 208 207 case Type::FunctionIDs: 209 COUT(5) << "functionIDs" << std::endl;208 // COUT(5) << "functionIDs" << std::endl; 210 209 p = new FunctionIDs( data, clientID ); 211 210 break; 212 211 default: 213 assert(0); //TODO: repair this212 assert(0); 214 213 break; 215 214 } … … 235 234 delete it->second; 236 235 packetMap_.erase(it); 237 COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;236 // COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl; 238 237 } 239 238
Note: See TracChangeset
for help on using the changeset viewer.