Changeset 2171 for code/trunk/src/network/packet
- Timestamp:
- Nov 10, 2008, 12:05:03 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/objecthierarchy merged: 2111-2115,2123,2132-2134,2143-2144,2153-2158,2160-2169
- Property svn:mergeinfo changed
-
code/trunk/src/network/packet/Acknowledgement.cc
r1907 r2171 33 33 #include "core/CoreIncludes.h" 34 34 35 namespace network{35 namespace orxonox { 36 36 namespace packet { 37 37 38 38 #define PACKET_FLAGS_ACK 0 39 39 #define _PACKETID 0 40 #define _ACKID _PACKETID + sizeof( network::packet::ENUM::Type)40 #define _ACKID _PACKETID + sizeof(packet::ENUM::Type) 41 41 42 42 Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID ) … … 74 74 75 75 } //namespace packet 76 } //namespace network76 } //namespace orxonox -
code/trunk/src/network/packet/Acknowledgement.h
r2087 r2171 33 33 34 34 35 namespace network{35 namespace orxonox { 36 36 namespace packet { 37 37 /** … … 53 53 54 54 } //namespace packet 55 } //namespace network55 } //namespace orxonox 56 56 57 57 #endif -
code/trunk/src/network/packet/Chat.cc
r1907 r2171 31 31 #include "network/Host.h" 32 32 33 namespace network{33 namespace orxonox { 34 34 namespace packet { 35 35 … … 77 77 78 78 } //namespace packet 79 } //namespace network79 } //namespace orxonox -
code/trunk/src/network/packet/Chat.h
r2087 r2171 10 10 #include "Packet.h" 11 11 12 namespace network{12 namespace orxonox { 13 13 namespace packet { 14 14 /** … … 33 33 34 34 } //namespace packet 35 } //namespace network35 } //namespace orxonox 36 36 37 37 #endif -
code/trunk/src/network/packet/ClassID.cc
r1907 r2171 34 34 #include <assert.h> 35 35 36 namespace network{36 namespace orxonox { 37 37 namespace packet { 38 38 … … 68 68 69 69 unsigned int ClassID::getSize() const{ 70 return sizeof( network::packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_;70 return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_; 71 71 } 72 72 73 73 bool ClassID::process(){ 74 74 COUT(3) << "processing classid: " << getClassID() << " name: " << (const char*)(data_+_CLASSNAME) << std::endl; 75 orxonox::Identifier *id=ClassByID( std::string((const char*)(data_+_CLASSNAME) ));75 Identifier *id=ClassByID( std::string((const char*)(data_+_CLASSNAME) )); 76 76 if(id==NULL) 77 77 return false; … … 86 86 87 87 } //namespace packet 88 }//namespace network88 }//namespace orxonox -
code/trunk/src/network/packet/ClassID.h
r2087 r2171 35 35 #include "Packet.h" 36 36 37 namespace network{37 namespace orxonox { 38 38 namespace packet { 39 39 … … 59 59 60 60 } //namespace packet 61 } //namespace network61 } //namespace orxonox 62 62 63 63 #endif -
code/trunk/src/network/packet/DeleteObjects.cc
r1907 r2171 34 34 #include <assert.h> 35 35 36 namespace network{36 namespace orxonox { 37 37 namespace packet { 38 38 … … 95 95 96 96 } //namespace packet 97 } //namespace network97 } //namespace orxonox -
code/trunk/src/network/packet/DeleteObjects.h
r2087 r2171 34 34 35 35 36 namespace network{36 namespace orxonox { 37 37 namespace packet { 38 38 /** … … 55 55 56 56 } //namespace packet 57 } //namespace network57 } //namespace orxonox 58 58 59 59 #endif -
code/trunk/src/network/packet/Gamestate.cc
r2087 r2171 38 38 39 39 40 namespace network{40 namespace orxonox { 41 41 42 42 namespace packet { … … 71 71 } 72 72 73 bool Gamestate::collectData(int id, int mode)74 { 75 int tempsize=0, currentsize=0;73 bool Gamestate::collectData(int id, uint8_t mode) 74 { 75 unsigned int tempsize=0, currentsize=0; 76 76 assert(data_==0); 77 int size = calcGamestateSize(id, mode);77 unsigned int size = calcGamestateSize(id, mode); 78 78 79 79 COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl; … … 86 86 } 87 87 88 #ifndef NDEBUG89 std::list<Synchronisable*> slist;90 std::list<Synchronisable*>::iterator iit;91 #endif92 88 //start collect data synchronisable by synchronisable 93 89 uint8_t *mem=data_; 94 90 mem+=sizeof(GamestateHeader); 95 orxonox::ObjectList<Synchronisable>::iterator it;96 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){91 ObjectList<Synchronisable>::iterator it; 92 for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 97 93 tempsize=it->getSize(id, mode); 98 94 99 95 if(currentsize+tempsize > size){ 96 assert(0); // if we don't use multithreading this part shouldn't be neccessary 100 97 // start allocate additional memory 101 98 COUT(3) << "G.St.Man: need additional memory" << std::endl; 102 orxonox::ObjectList<Synchronisable>::iterator temp = it;99 ObjectList<Synchronisable>::iterator temp = it; 103 100 int addsize=tempsize; 104 101 while(++temp) … … 110 107 }// stop allocate additional memory 111 108 112 #ifndef NDEBUG113 for(iit=slist.begin(); iit!=slist.end(); iit++)114 assert((*iit)!=*it);115 slist.push_back(*it);116 #endif117 109 118 110 //if(it->doSelection(id)) … … 127 119 //start write gamestate header 128 120 HEADER->packetType = ENUM::Gamestate; 129 assert( *(ENUM::Type *)(data_) == ENUM::Gamestate);130 121 HEADER->datasize = currentsize; 131 122 HEADER->id = id; … … 140 131 } 141 132 142 bool Gamestate::spreadData( int mode)133 bool Gamestate::spreadData(uint8_t mode) 143 134 { 144 135 assert(data_); … … 147 138 uint8_t *mem=data_+sizeof(GamestateHeader); 148 139 // get the start of the Synchronisable list 149 // orxonox::ObjectList<Synchronisable>::iterator it=orxonox::ObjectList<Synchronisable>::begin();140 //ObjectList<Synchronisable>::iterator it=ObjectList<Synchronisable>::begin(); 150 141 Synchronisable *s; 151 142 … … 163 154 bool b = s->updateData(mem, mode); 164 155 assert(b); 165 //if(!s->updateData(mem, mode))166 //return false;167 156 } 168 157 } … … 367 356 assert(it->second->objectID==oldobjectheader->objectID); 368 357 *newobjectheader = *oldobjectheader; 369 objectOffset=sizeof( uint8_t)+sizeof(bool); //skip the size and the availableData variables in the objectheader358 objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader 370 359 if(it->second->doSelection(HEADER->id)){ 371 newobjectheader->dataAvailable=true; //TODO: probably not neccessary 372 while(objectOffset<objectsize){ 373 *(newdata + objectOffset)=*(origdata + objectOffset); // copy the data 374 objectOffset++; 375 } 360 assert(newobjectheader->dataAvailable==true); 361 memcpy(newdata+objectOffset, origdata+objectOffset, objectsize-objectOffset); 376 362 }else{ 377 363 newobjectheader->dataAvailable=false; 378 while(objectOffset<objectsize){ 379 *(newdata+objectOffset)=0; // set to 0 380 objectOffset++; 381 } 364 memset(newdata+objectOffset, 0, objectsize-objectOffset); 382 365 assert(objectOffset==objectsize); 383 366 } … … 565 548 566 549 567 unsigned int Gamestate::calcGamestateSize(unsigned int id, int mode)568 { 569 int size=0;550 unsigned int Gamestate::calcGamestateSize(unsigned int id, uint8_t mode) 551 { 552 unsigned int size=0; 570 553 // get the start of the Synchronisable list 571 orxonox::ObjectList<Synchronisable>::iterator it;554 ObjectList<Synchronisable>::iterator it; 572 555 // get total size of gamestate 573 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it)556 for(it = ObjectList<Synchronisable>::begin(); it; ++it) 574 557 size+=it->getSize(id, mode); // size of the actual data of the synchronisable 575 558 // size+=sizeof(GamestateHeader); … … 582 565 * @return iterator pointing to the next object in the list 583 566 */ 584 void Gamestate::removeObject( orxonox::ObjectList<Synchronisable>::iterator &it) {585 orxonox::ObjectList<Synchronisable>::iterator temp=it;567 void Gamestate::removeObject(ObjectList<Synchronisable>::iterator &it) { 568 ObjectList<Synchronisable>::iterator temp=it; 586 569 ++it; 587 570 delete *temp; -
code/trunk/src/network/packet/Gamestate.h
r2087 r2171 40 40 #endif 41 41 42 namespace network{42 namespace orxonox { 43 43 44 44 namespace packet { … … 69 69 ~Gamestate(); 70 70 71 bool collectData(int id, int mode=0x0);72 bool spreadData( int mode=0x0);71 bool collectData(int id, uint8_t mode=0x0); 72 bool spreadData( uint8_t mode=0x0); 73 73 int getID(); 74 74 bool isDiffed(); … … 90 90 bool operator ==(packet::Gamestate gs); 91 91 private: 92 unsigned int calcGamestateSize(unsigned int id, int mode=0x0);93 void removeObject( orxonox::ObjectListIterator<Synchronisable> &it);92 unsigned int calcGamestateSize(unsigned int id, uint8_t mode=0x0); 93 void removeObject(ObjectListIterator<Synchronisable> &it); 94 94 std::map<unsigned int, Synchronisable*> dataMap_; 95 95 }; -
code/trunk/src/network/packet/Packet.cc
r2087 r2171 46 46 #include "core/CoreIncludes.h" 47 47 48 namespace network{48 namespace orxonox{ 49 49 50 50 namespace packet{ … … 53 53 #define _PACKETID 0 54 54 55 std::map<ENetPacket *, Packet *> Packet::packetMap_; 55 std::map<size_t, Packet *> Packet::packetMap_; 56 boost::recursive_mutex Packet::packetMap_mutex; 56 57 57 58 Packet::Packet(){ … … 128 129 return false; 129 130 } 131 // Assures we don't create a packet and destroy it right after in another thread 132 // without having a reference in the packetMap_ 133 boost::recursive_mutex::scoped_lock lock(Packet::packetMap_mutex); 130 134 // We deliver ENet the data address so that it doesn't memcpy everything again. 131 135 // --> We have to delete data_ ourselves! … … 134 138 // Add the packet to a global list so we can access it again once enet calls our 135 139 // deletePacket method. We can of course only give a one argument function to the ENet C library. 136 packetMap_[ enetPacket_] = this;140 packetMap_[(size_t)(void*)enetPacket_] = this; 137 141 } 138 142 #ifndef NDEBUG … … 153 157 // ENetPacket *temp = enetPacket_; 154 158 // enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet 155 network::Host::addPacket( enetPacket_, clientID_);159 Host::addPacket( enetPacket_, clientID_); 156 160 return true; 157 161 } … … 207 211 */ 208 212 void Packet::deletePacket(ENetPacket *enetPacket){ 213 boost::recursive_mutex::scoped_lock lock(Packet::packetMap_mutex); 209 214 // Get our Packet from a gloabal map with all Packets created in the send() method of Packet. 210 std::map< ENetPacket*, Packet*>::iterator it = packetMap_.find(enetPacket);215 std::map<size_t, Packet*>::iterator it = packetMap_.find((size_t)enetPacket); 211 216 assert(it != packetMap_.end()); 212 217 // Make sure we don't delete it again in the destructor 213 218 it->second->enetPacket_ = 0; 214 219 delete it->second; 215 //packetMap_.erase(it);220 packetMap_.erase(it); 216 221 COUT(4) << "PacketMap size: " << packetMap_.size() << std::endl; 217 222 } … … 219 224 } // namespace packet 220 225 221 } // namespace network222 226 } // namespace orxonox 227 -
code/trunk/src/network/packet/Packet.h
r2087 r2171 29 29 #define NETWORKPACKET_H 30 30 31 #include " ../NetworkPrereqs.h"31 #include "network/NetworkPrereqs.h" 32 32 33 33 #include <map> 34 34 #include <enet/enet.h> 35 #include <boost/thread/recursive_mutex.hpp> 35 36 36 37 #include "util/Integers.h" 37 38 38 namespace network{39 namespace orxonox { 39 40 40 41 namespace packet{ … … 92 93 bool bDataENetAllocated_; 93 94 private: 94 static std::map<ENetPacket *, Packet *> packetMap_; 95 static std::map<size_t, Packet *> packetMap_; 96 //! Static mutex for any packetMap_ access 97 static boost::recursive_mutex packetMap_mutex; 95 98 ENetPacket *enetPacket_; 96 99 }; … … 98 101 } //namespace packet 99 102 100 } //namespace network103 } //namespace orxonox 101 104 102 105 #endif -
code/trunk/src/network/packet/Welcome.cc
r1907 r2171 36 36 #include <assert.h> 37 37 38 namespace network{38 namespace orxonox { 39 39 namespace packet { 40 40 … … 70 70 71 71 unsigned int Welcome::getSize() const{ 72 return sizeof( network::packet::ENUM::Type) + 2*sizeof(uint32_t);72 return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t); 73 73 } 74 74 … … 87 87 88 88 } //namespace packet 89 }//namespace network89 }//namespace orxonox -
code/trunk/src/network/packet/Welcome.h
r2087 r2171 33 33 #include "Packet.h" 34 34 35 namespace network{35 namespace orxonox { 36 36 namespace packet { 37 37 … … 54 54 55 55 } //namespace packet 56 } //namespace network56 } //namespace orxonox 57 57 58 58 #endif
Note: See TracChangeset
for help on using the changeset viewer.