Changeset 7759
- Timestamp:
- Dec 14, 2010, 8:54:00 PM (14 years ago)
- Location:
- code/branches/network5/src/libraries/network
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network5/src/libraries/network/Client.cc
r7495 r7759 164 164 COUT(4) << "client tick: sending gs " << gs << std::endl; 165 165 if( !gs->send() ) 166 COUT( 3) << "Problem adding partial gamestate to queue" << std::endl;166 COUT(2) << "Problem adding partial gamestate to queue" << std::endl; 167 167 // gs gets automatically deleted by enet callback 168 168 } -
code/branches/network5/src/libraries/network/FunctionCallManager.cc
r7495 r7759 30 30 #include "packet/FunctionCalls.h" 31 31 #include "core/GameMode.h" 32 #include "GamestateHandler.h" 32 33 33 34 namespace orxonox { 34 35 35 36 std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sClientMap_; 36 std::vector< FunctionCall> FunctionCallManager::sIncomingFunctionCallBuffer_;37 std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > > FunctionCallManager::sIncomingFunctionCallBuffer_; 37 38 38 39 // Static calls … … 164 165 } 165 166 166 void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall )167 void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t clientID) 167 168 { 168 if( !GameMode::isMaster() ) 169 FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( fctCall ); 169 FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, clientID))); 170 170 } 171 171 172 172 void FunctionCallManager::processBufferedFunctionCalls() 173 173 { 174 std::vector< FunctionCall>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();174 std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > >::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin(); 175 175 while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() ) 176 176 { 177 if( it->execute() ) 177 uint32_t minGamestateID = it->second.first; 178 uint32_t clientID = it->second.second; 179 if( minGamestateID <= GamestateHandler::getInstance()->getLastProcessedGamestateID(clientID) && it->first.execute() ) 178 180 FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it); 179 181 else 182 { 180 183 ++it; 184 } 181 185 } 182 186 } -
code/branches/network5/src/libraries/network/FunctionCallManager.h
r7495 r7759 34 34 #include <map> 35 35 #include <vector> 36 #include <utility> 36 37 #include "util/UtilPrereqs.h" 37 38 #include "FunctionCall.h" … … 61 62 static void sendCalls(); 62 63 63 static void bufferIncomingFunctionCall( const FunctionCall& fctCall );64 static void bufferIncomingFunctionCall( const FunctionCall& fctCall, uint32_t minGamestateID, uint32_t clientID ); 64 65 static void processBufferedFunctionCalls(); 65 66 66 static std::map<uint32_t, packet::FunctionCalls*> sClientMap_;67 static std::vector< FunctionCall>sIncomingFunctionCallBuffer_;67 static std::map<uint32_t, packet::FunctionCalls*> sClientMap_; 68 static std::vector<std::pair<FunctionCall,std::pair<uint32_t, uint32_t> > > sIncomingFunctionCallBuffer_; 68 69 protected: 69 70 FunctionCallManager(); -
code/branches/network5/src/libraries/network/GamestateClient.cc
r7401 r7759 39 39 namespace orxonox 40 40 { 41 struct _NetworkExport GameStateItem{ 41 struct _NetworkExport GameStateItem 42 { 42 43 packet::Gamestate *state; 43 44 unsigned int id; 44 45 }; 45 46 46 GamestateClient::GamestateClient() { 47 GamestateClient::GamestateClient() 48 { 47 49 COUT(5) << "this: " << this << std::endl; 48 last _diff_=0;49 last _gamestate_=GAMESTATEID_INITIAL-1;50 lastAckedGamestateID_=GAMESTATEID_INITIAL-1; 51 lastProcessedGamestateID_=GAMESTATEID_INITIAL-1; 50 52 tempGamestate_=NULL; 51 53 } 52 54 53 GamestateClient::~GamestateClient() { 55 GamestateClient::~GamestateClient() 56 { 54 57 std::map<unsigned int, packet::Gamestate *>::iterator it; 55 58 for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it ) … … 59 62 } 60 63 61 bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID){ 64 bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID) 65 { 62 66 return true; 63 67 } 64 68 65 bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID){ 66 if(tempGamestate_!=NULL){ 69 bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID) 70 { 71 if(tempGamestate_!=NULL) 72 { 67 73 //delete the obsolete gamestate 68 74 if(tempGamestate_->getID()>gs->getID()) … … 74 80 } 75 81 76 bool GamestateClient::processGamestates(){ 82 bool GamestateClient::processGamestates() 83 { 77 84 if(tempGamestate_==NULL) 78 85 return false; … … 85 92 NetworkCallbackManager::callCallbacks(); 86 93 87 if (!processed){ 94 if (!processed) 95 { 96 assert(0); 88 97 sendAck(0); 89 98 return false; … … 92 101 tempGamestate_=NULL; 93 102 gamestateMap_[processed->getID()]=processed; 103 lastProcessedGamestateID_ = processed->getID(); 94 104 if(isDiffed) 95 last _diff_ = processed->getBaseID();105 lastAckedGamestateID_ = processed->getBaseID(); 96 106 id = processed->getID(); 97 107 sendAck(id); … … 105 115 * @return iterator pointing to the next object in the list 106 116 */ 107 void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it) { 117 void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it) 118 { 108 119 ObjectListIterator<Synchronisable> temp=it; 109 120 ++it; … … 111 122 } 112 123 113 packet::Gamestate *GamestateClient::getGamestate(){ 124 packet::Gamestate *GamestateClient::getGamestate() 125 { 114 126 packet::Gamestate *gs = new packet::Gamestate(); 115 if(!gs->collectData(0,0x2)){ 127 if(!gs->collectData(this->getLastProcessedGamestateID(NETWORK_PEER_ID_SERVER), 0x2)) 128 { 116 129 delete gs; 117 130 return 0; … … 120 133 } 121 134 122 void GamestateClient::cleanup(){ 135 void GamestateClient::cleanup() 136 { 123 137 std::map<unsigned int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin(); 124 while(it!=gamestateMap_.end()){ 125 if(it->first>=last_diff_) 138 while(it!=gamestateMap_.end()) 139 { 140 if(it->first>=lastAckedGamestateID_) 126 141 break; 127 142 // otherwise delete that stuff … … 133 148 } 134 149 135 void GamestateClient::printGamestateMap(){ 150 void GamestateClient::printGamestateMap() 151 { 136 152 std::map<unsigned int, packet::Gamestate*>::iterator it; 137 153 COUT(4) << "gamestates: "; 138 for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++){ 154 for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++) 155 { 139 156 COUT(4) << it->first << ':' << it->second << '|'; 140 157 } … … 143 160 } 144 161 145 bool GamestateClient::sendAck(unsigned int gamestateID){ 162 bool GamestateClient::sendAck(unsigned int gamestateID) 163 { 146 164 packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, 0); 147 if(!ack->send()){ 165 if(!ack->send()) 166 { 148 167 COUT(3) << "could not ack gamestate: " << gamestateID << std::endl; 149 168 return false; 150 169 } 151 else{ 170 else 171 { 152 172 COUT(5) << "acked a gamestate: " << gamestateID << std::endl; 153 173 return true; … … 155 175 } 156 176 157 packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){ 177 packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs) 178 { 158 179 if(gs->isCompressed()) 159 180 { -
code/branches/network5/src/libraries/network/GamestateClient.h
r5781 r7759 57 57 ~GamestateClient(); 58 58 59 bool add(packet::Gamestate *gs, unsigned int clientID); 60 bool ack(unsigned int gamestateID, unsigned int clientID); 59 virtual bool add(packet::Gamestate *gs, unsigned int clientID); 60 virtual bool ack(unsigned int gamestateID, unsigned int clientID); 61 virtual uint32_t getLastProcessedGamestateID(unsigned int clientID) { return this->lastProcessedGamestateID_; } 62 virtual uint32_t getCurrentGamestateID(){ return this->lastProcessedGamestateID_; } 61 63 62 64 bool processGamestates(); … … 69 71 bool sendAck(unsigned int gamestateID); 70 72 71 unsigned int last _diff_;72 unsigned int last _gamestate_;73 unsigned int lastAckedGamestateID_; 74 unsigned int lastProcessedGamestateID_; 73 75 std::map<unsigned int, packet::Gamestate *> gamestateMap_; 74 76 packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue -
code/branches/network5/src/libraries/network/GamestateHandler.h
r6073 r7759 32 32 #include "NetworkPrereqs.h" 33 33 34 #include <cassert> 35 34 36 namespace orxonox { 35 37 … … 39 41 class _NetworkExport GamestateHandler{ 40 42 private: 41 virtual bool add(packet::Gamestate *gs, unsigned int clientID)=0;42 virtual bool ack(unsigned int gamestateID, unsigned int clientID)=0;43 virtual bool add(packet::Gamestate *gs, unsigned int clientID)=0; 44 virtual bool ack(unsigned int gamestateID, unsigned int clientID)=0; 43 45 44 static GamestateHandler *instance_;46 static GamestateHandler* instance_; 45 47 46 48 … … 50 52 51 53 public: 52 static bool addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); } 53 static bool ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); } 54 static bool addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); } 55 static bool ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); } 56 static GamestateHandler* getInstance(){ assert(instance_); return instance_; } 57 58 virtual uint32_t getLastProcessedGamestateID( unsigned int clientID )=0; 59 virtual uint32_t getCurrentGamestateID()=0; 54 60 }; 55 61 -
code/branches/network5/src/libraries/network/GamestateManager.cc
r7758 r7759 258 258 return true; 259 259 } 260 261 uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int clientID) 262 { 263 assert( this->lastProcessedGamestateID_.find(clientID) != this->lastProcessedGamestateID_.end() ); 264 if( this->lastProcessedGamestateID_.find(clientID) != this->lastProcessedGamestateID_.end() ) 265 return this->lastProcessedGamestateID_[clientID]; 266 else 267 return GAMESTATEID_INITIAL; 268 } 260 269 261 270 void GamestateManager::removeClient(ClientInformation* client){ … … 277 286 } 278 287 assert(!gs->isDiffed()); 279 return gs->spreadData(0x1); 288 if( gs->spreadData(0x1) ) 289 { 290 this->lastProcessedGamestateID_[gs->getClientID()] = gs->getID(); 291 return true; 292 } 293 else 294 return false; 280 295 } 281 296 -
code/branches/network5/src/libraries/network/GamestateManager.h
r7163 r7759 46 46 #include "GamestateHandler.h" 47 47 #include "core/CorePrereqs.h" 48 #include "packet/Gamestate.h" 48 49 49 50 namespace orxonox … … 71 72 ~GamestateManager(); 72 73 73 bool add(packet::Gamestate *gs, unsigned int clientID); 74 virtual bool add(packet::Gamestate *gs, unsigned int clientID); 75 virtual bool ack(unsigned int gamestateID, unsigned int clientID); 76 virtual uint32_t getLastProcessedGamestateID( unsigned int clientID ); 77 virtual uint32_t getCurrentGamestateID(){ return reference->getID(); } 78 74 79 bool processGamestates(); 75 80 bool update(); … … 80 85 bool getSnapshot(); 81 86 82 bool ack(unsigned int gamestateID, unsigned int clientID);83 87 void removeClient(ClientInformation *client); 84 88 private: … … 87 91 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_; 88 92 std::map<unsigned int, packet::Gamestate*> gamestateQueue; 93 std::map<unsigned int, uint32_t> lastProcessedGamestateID_; 89 94 packet::Gamestate *reference; 90 95 TrafficControl *trafficControl_; -
code/branches/network5/src/libraries/network/MasterServerComm.cc
r7756 r7759 89 89 90 90 /* Wait up to 2 seconds for the connection attempt to succeed. */ 91 if (enet_host_service (this->client, this->event, 2000) > 0 &&91 if (enet_host_service (this->client, this->event, 500) > 0 && 92 92 this->event->type == ENET_EVENT_TYPE_CONNECT ) 93 93 COUT(3) << "Connection to master server succeeded.\n"; -
code/branches/network5/src/libraries/network/NetworkPrereqs.h
r7490 r7759 69 69 extern const char* LAN_DISCOVERY_ACK; 70 70 static const unsigned int LAN_DISCOVERY_PORT = 55557; 71 static const unsigned int NETWORK_PEER_ID_SERVER = 0; 71 72 } 72 73 … … 83 84 enum Value 84 85 { 85 Reliable = 1,86 Unsequence = 2,87 NoAllocate = 486 Reliable = 1, 87 Unsequenced = 2, 88 NoAllocate = 4 88 89 }; 89 90 } -
code/branches/network5/src/libraries/network/Server.cc
r7756 r7759 217 217 // process incoming gamestates 218 218 GamestateManager::processGamestates(); 219 FunctionCallManager::processBufferedFunctionCalls(); 219 220 220 221 // send function calls to clients -
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 -
code/branches/network5/src/libraries/network/synchronisable/Synchronisable.h
r7163 r7759 65 65 }; 66 66 } 67 68 typedef uint8_t VariableID;69 70 /**71 * @brief: stores information about a Synchronisable72 *73 * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)74 * in an emulated bitset.75 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream76 * Bit 32 is a bool and defines whether the variables are stored in diff mode77 * Byte 5 to 8: objectID_78 * Byte 9 to 12: classID_79 * Byte 13 to 16: creatorID_80 */81 class _NetworkExport SynchronisableHeader{82 friend class SynchronisableHeaderLight;83 private:84 uint8_t* data_;85 public:86 SynchronisableHeader(uint8_t* data)87 { data_ = data; }88 inline static uint32_t getSize()89 { return 14; }90 inline uint16_t getDataSize() const91 { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 15 bits92 inline void setDataSize(uint16_t size)93 { *(uint16_t*)(data_) = (size & 0x7FFF) | (*(uint16_t*)(data_) & 0x8000 ); }94 inline bool isDiffed() const95 { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }96 inline void setDiffed( bool b)97 { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); }98 inline uint32_t getObjectID() const99 { return *(uint32_t*)(data_+2); }100 inline void setObjectID(uint32_t objectID_)101 { *(uint32_t*)(data_+2) = objectID_; }102 inline uint32_t getClassID() const103 { return *(uint32_t*)(data_+6); }104 inline void setClassID(uint32_t classID_)105 { *(uint32_t*)(data_+6) = classID_; }106 inline uint32_t getCreatorID() const107 { return *(uint32_t*)(data_+10); }108 inline void setCreatorID(uint32_t creatorID_)109 { *(uint32_t*)(data_+10) = creatorID_; }110 inline void operator=(SynchronisableHeader& h)111 { memcpy(data_, h.data_, getSize()); }112 };113 67 114 68 /** … … 121 75 * Byte 5 to 8: objectID_ 122 76 */ 123 class _NetworkExport SynchronisableHeaderLight{ 124 private: 77 class _NetworkExport SynchronisableHeaderLight 78 { 79 protected: 125 80 uint8_t* data_; 126 81 public: … … 141 96 inline void setObjectID(uint32_t objectID_) 142 97 { *(uint32_t*)(data_+2) = objectID_; } 98 inline void operator=(SynchronisableHeaderLight& h) 99 { memcpy(data_, h.data_, SynchronisableHeaderLight::getSize()); } 100 }; 101 102 typedef uint8_t VariableID; 103 104 /** 105 * @brief: stores information about a Synchronisable 106 * 107 * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize) 108 * in an emulated bitset. 109 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 110 * Bit 32 is a bool and defines whether the variables are stored in diff mode 111 * Byte 5 to 8: objectID_ 112 * Byte 9 to 12: classID_ 113 * Byte 13 to 16: creatorID_ 114 */ 115 class _NetworkExport SynchronisableHeader: public SynchronisableHeaderLight 116 { 117 public: 118 SynchronisableHeader(uint8_t* data): SynchronisableHeaderLight(data) 119 {} 120 inline static uint32_t getSize() 121 { return SynchronisableHeaderLight::getSize()+8; } 122 inline uint32_t getClassID() const 123 { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()); } 124 inline void setClassID(uint32_t classID_) 125 { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()) = classID_; } 126 inline uint32_t getCreatorID() const 127 { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4); } 128 inline void setCreatorID(uint32_t creatorID_) 129 { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4) = creatorID_; } 143 130 inline void operator=(SynchronisableHeader& h) 144 131 { memcpy(data_, h.data_, getSize()); } 145 132 }; 133 134 // inline void operator=(SynchronisableHeaderLight& h1, SynchronisableHeader& h2) 135 // { 136 // memcpy(h1.data_, h2.data_, h1.getSize()); 137 // } 146 138 147 139 /**
Note: See TracChangeset
for help on using the changeset viewer.