Changeset 11006
- Timestamp:
- Dec 30, 2015, 11:34:25 PM (9 years ago)
- Location:
- code/branches/cpp11_v2/src/libraries/network
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/src/libraries/network/Connection.cc
r10919 r11006 81 81 { 82 82 // this->overallMutex_->lock(); 83 outgoingEvent outEvent = { peerID, outgoingEventType::disconnectPeer, nullptr, 0 };83 outgoingEvent outEvent = { peerID, OutgoingEventType::disconnectPeer, nullptr, 0 }; 84 84 85 85 this->outgoingEventsMutex_->lock(); … … 91 91 void Connection::disconnectPeers() 92 92 { 93 outgoingEvent outEvent = { 0, outgoingEventType::disconnectPeers, nullptr, 0 };93 outgoingEvent outEvent = { 0, OutgoingEventType::disconnectPeers, nullptr, 0 }; 94 94 95 95 this->outgoingEventsMutex_->lock(); … … 101 101 { 102 102 // this->overallMutex_->lock(); 103 outgoingEvent outEvent = { peerID, outgoingEventType::sendPacket, packet, channelID };103 outgoingEvent outEvent = { peerID, OutgoingEventType::sendPacket, packet, channelID }; 104 104 105 105 this->outgoingEventsMutex_->lock(); … … 112 112 { 113 113 // this->overallMutex_->lock(); 114 outgoingEvent outEvent = { 0, outgoingEventType::broadcastPacket, packet, channelID };114 outgoingEvent outEvent = { 0, OutgoingEventType::broadcastPacket, packet, channelID }; 115 115 116 116 this->outgoingEventsMutex_->lock(); … … 197 197 switch( event.type ) 198 198 { 199 case outgoingEventType::sendPacket:199 case OutgoingEventType::sendPacket: 200 200 // check whether the peer is still/already in the peer list 201 201 if( this->peerMap_.find(event.peerID) != this->peerMap_.end() ) … … 211 211 } 212 212 break; 213 case outgoingEventType::disconnectPeer:213 case OutgoingEventType::disconnectPeer: 214 214 if( this->peerMap_.find(event.peerID) != this->peerMap_.end() ) 215 215 { … … 223 223 } 224 224 break; 225 case outgoingEventType::disconnectPeers:225 case OutgoingEventType::disconnectPeers: 226 226 disconnectPeersInternal(); 227 227 break; 228 case outgoingEventType::broadcastPacket:228 case OutgoingEventType::broadcastPacket: 229 229 enet_host_broadcast( this->host_, event.channelID, event.packet ); 230 230 break; … … 271 271 switch( inEvent.type ) 272 272 { 273 case incomingEventType::peerConnect:273 case IncomingEventType::peerConnect: 274 274 addPeer(inEvent.peerID); 275 275 break; 276 case incomingEventType::peerDisconnect:276 case IncomingEventType::peerDisconnect: 277 277 removePeer(inEvent.peerID); 278 278 break; 279 case incomingEventType::receivePacket:279 case IncomingEventType::receivePacket: 280 280 processPacket(inEvent.packet); 281 281 break; … … 322 322 323 323 // create new peerEvent and return it 324 incomingEvent inEvent = { peerID, incomingEventType::peerConnect, nullptr };324 incomingEvent inEvent = { peerID, IncomingEventType::peerConnect, nullptr }; 325 325 return inEvent; 326 326 } … … 337 337 338 338 // create new peerEvent and return it 339 incomingEvent inEvent = { peerID, incomingEventType::peerDisconnect, nullptr };339 incomingEvent inEvent = { peerID, IncomingEventType::peerDisconnect, nullptr }; 340 340 return inEvent; 341 341 } … … 351 351 352 352 // create new peerEvent and return it 353 incomingEvent inEvent = { peerID, incomingEventType::receivePacket, p };353 incomingEvent inEvent = { peerID, IncomingEventType::receivePacket, p }; 354 354 return inEvent; 355 355 } -
code/branches/cpp11_v2/src/libraries/network/Connection.h
r10774 r11006 60 60 const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5; 61 61 62 namespace incomingEventType62 enum class IncomingEventType 63 63 { 64 enum Value 65 { 66 receivePacket = 1, // incoming packet 67 peerConnect = 2, // incoming connect request 68 peerDisconnect = 3 // incoming disconnect request 69 }; 70 71 } 64 receivePacket = 1, // incoming packet 65 peerConnect = 2, // incoming connect request 66 peerDisconnect = 3 // incoming disconnect request 67 }; 72 68 73 namespace outgoingEventType69 enum class OutgoingEventType 74 70 { 75 enum Value 76 { 77 sendPacket = 1, // outgoing packet 78 broadcastPacket = 2, // outgoing broadcast packet 79 disconnectPeer = 3, // outgoing disconnect request 80 disconnectPeers = 4 // outgoing disconnect request 81 }; 82 83 } 71 sendPacket = 1, // outgoing packet 72 broadcastPacket = 2, // outgoing broadcast packet 73 disconnectPeer = 3, // outgoing disconnect request 74 disconnectPeers = 4 // outgoing disconnect request 75 }; 84 76 85 77 struct _NetworkExport incomingEvent 86 78 { 87 uint32_t 88 incomingEventType::Valuetype;89 packet::Packet* 79 uint32_t peerID; 80 IncomingEventType type; 81 packet::Packet* packet; 90 82 }; 91 83 92 84 struct _NetworkExport outgoingEvent 93 85 { 94 uint32_t 95 outgoingEventType::Valuetype;96 ENetPacket* 97 ENetChannelID 86 uint32_t peerID; 87 OutgoingEventType type; 88 ENetPacket* packet; 89 ENetChannelID channelID; 98 90 }; 99 91 -
code/branches/cpp11_v2/src/libraries/network/NetworkPrereqs.h
r10994 r11006 89 89 namespace PacketFlag 90 90 { 91 enum Value 92 { 93 Reliable = 1, 94 Unsequenced = 2, 95 NoAllocate = 4 96 }; 91 static constexpr uint32_t Reliable = 1; 92 static constexpr uint32_t Unsequenced = 2; 93 static constexpr uint32_t NoAllocate = 4; 97 94 } 98 95 } … … 101 98 { 102 99 typedef int Type; 103 static const Type NETWORK_FUNCTION = 6;100 static constexpr Type NETWORK_FUNCTION = 6; 104 101 } 105 102 } -
code/branches/cpp11_v2/src/libraries/network/packet/Acknowledgement.cc
r8858 r11006 38 38 #define PACKET_FLAGS_ACK 0 39 39 #define _PACKETID 0 40 #define _ACKID _PACKETID + sizeof(packet::Type ::Value)40 #define _ACKID _PACKETID + sizeof(packet::Type) 41 41 42 42 Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID ) … … 45 45 flags_ = flags_ | PACKET_FLAGS_ACK; 46 46 data_=new uint8_t[ getSize() ]; 47 *(Type ::Value*)(data_ + _PACKETID ) = Type::Acknowledgement;47 *(Type *)(data_ + _PACKETID ) = Type::Acknowledgement; 48 48 *(uint32_t *)(data_ + _ACKID ) = id; 49 49 peerID_=peerID; -
code/branches/cpp11_v2/src/libraries/network/packet/Chat.cc
r8858 r11006 40 40 /* Some lengths */ 41 41 #define _PACKETID 0 42 #define _SOURCEID _PACKETID + sizeof(Type ::Value)42 #define _SOURCEID _PACKETID + sizeof(Type) 43 43 #define _TARGETID _SOURCEID + sizeof(uint32_t) 44 44 #define _MESSAGELENGTH _TARGETID + sizeof(uint32_t) … … 57 57 data_=new unsigned char[ getSize() ]; 58 58 59 *(Type ::Value*)(data_ + _PACKETID ) = Type::Chat;59 *(Type *)(data_ + _PACKETID ) = Type::Chat; 60 60 *(unsigned int *)(data_ + _SOURCEID ) = sourceID; 61 61 *(unsigned int *)(data_ + _TARGETID ) = targetID; -
code/branches/cpp11_v2/src/libraries/network/packet/ClassID.cc
r10919 r11006 70 70 //set the appropriate packet id 71 71 assert(this->data_); 72 *(Type ::Value*)(this->data_ + _PACKETID ) = Type::ClassID;72 *(Type *)(this->data_ + _PACKETID ) = Type::ClassID; 73 73 74 74 uint8_t *temp=data_+sizeof(uint32_t); -
code/branches/cpp11_v2/src/libraries/network/packet/DeleteObjects.cc
r8858 r11006 39 39 #define PACKET_FLAG_DELETE PacketFlag::Reliable 40 40 #define _PACKETID 0 41 #define _QUANTITY _PACKETID + sizeof(Type ::Value)41 #define _QUANTITY _PACKETID + sizeof(Type) 42 42 #define _OBJECTIDS _QUANTITY + sizeof(uint32_t) 43 43 … … 63 63 return false; 64 64 orxout(verbose, context::packets) << "sending DeleteObjects: "; 65 unsigned int size = sizeof(Type ::Value) + sizeof(uint32_t)*(number+1);65 unsigned int size = sizeof(Type) + sizeof(uint32_t)*(number+1); 66 66 data_ = new uint8_t[size]; 67 67 uint8_t *tdata = data_; 68 *reinterpret_cast<Type ::Value*>(tdata) = Type::DeleteObjects;69 tdata += sizeof(Type ::Value);68 *reinterpret_cast<Type*>(tdata) = Type::DeleteObjects; 69 tdata += sizeof(Type); 70 70 *(uint32_t *)tdata = number; 71 71 tdata += sizeof(uint32_t); -
code/branches/cpp11_v2/src/libraries/network/packet/FunctionCalls.cc
r10624 r11006 96 96 assert(this->functionCalls_.size()); 97 97 data_=new uint8_t[ currentSize_ ]; 98 *(Type ::Value*)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID98 *(Type *)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID 99 99 *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls 100 100 *(uint32_t*)(data_+2*sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_ -
code/branches/cpp11_v2/src/libraries/network/packet/FunctionIDs.cc
r10769 r11006 71 71 //set the appropriate packet id 72 72 assert(this->data_); 73 *(Type ::Value*)(this->data_ + _PACKETID ) = Type::FunctionIDs;73 *(Type *)(this->data_ + _PACKETID ) = Type::FunctionIDs; 74 74 75 75 uint8_t *temp=data_+sizeof(uint32_t); -
code/branches/cpp11_v2/src/libraries/network/packet/Gamestate.h
r10994 r11006 56 56 GamestateHeader(){ data_=nullptr; } 57 57 GamestateHeader(uint8_t* data) 58 { assert(data); data_ = data; *( uint32_t*)data_ = Type::Gamestate; }58 { assert(data); data_ = data; *(Type*)data_ = Type::Gamestate; } 59 59 /*GamestateHeader(uint8_t* data, GamestateHeader* h) 60 60 { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/ 61 61 void setData(uint8_t* data) 62 { assert(data); data_ = data; *( uint32_t*)data_ = Type::Gamestate; }62 { assert(data); data_ = data; *(Type*)data_ = Type::Gamestate; } 63 63 static inline uint32_t getSize() 64 64 { return 21; } -
code/branches/cpp11_v2/src/libraries/network/packet/Packet.cc
r10774 r11006 157 157 } 158 158 #ifndef NDEBUG 159 switch( *(Type ::Value*)(data_ + _PACKETID) )159 switch( *(Type *)(data_ + _PACKETID) ) 160 160 { 161 161 case Type::Acknowledgement: … … 191 191 // peerID = NETWORK_PEER_ID_SERVER; 192 192 Packet *p = nullptr; 193 // orxout(verbose_ultra, context::packets) << "packet type: " << *(Type ::Value*)&data[_PACKETID] << endl;194 switch( *(Type ::Value*)(data + _PACKETID) )193 // orxout(verbose_ultra, context::packets) << "packet type: " << *(Type *)&data[_PACKETID] << endl; 194 switch( *(Type *)(data + _PACKETID) ) 195 195 { 196 196 case Type::Acknowledgement: -
code/branches/cpp11_v2/src/libraries/network/packet/Packet.h
r8327 r11006 38 38 { 39 39 40 namespaceDirection40 enum class Direction 41 41 { 42 enum Value 43 { 44 Incoming, 45 Outgoing, 46 Bidirectional 47 }; 48 } 49 namespace Type 42 Incoming, 43 Outgoing, 44 Bidirectional 45 }; 46 enum class Type : uint8_t 50 47 { 51 enum Value 52 { 53 Acknowledgement, 54 Chat, 55 ClassID, 56 DeleteObjects, 57 FunctionIDs, 58 FunctionCalls, 59 Gamestate, 60 Welcome 61 }; 62 } 48 Acknowledgement, 49 Chat, 50 ClassID, 51 DeleteObjects, 52 FunctionIDs, 53 FunctionCalls, 54 Gamestate, 55 Welcome 56 }; 63 57 64 58 /** … … 98 92 unsigned int peerID_; 99 93 uint32_t requiredGamestateID_; 100 Direction ::ValuepacketDirection_;94 Direction packetDirection_; 101 95 /** Pointer to the data. Be careful when deleting it because it might 102 96 point to a location that was allocated by ENet. -
code/branches/cpp11_v2/src/libraries/network/packet/Welcome.cc
r8858 r11006 41 41 #define PACKET_FLAGS_CLASSID PacketFlag::Reliable 42 42 #define _PACKETID 0 43 #define _CLIENTID _PACKETID + sizeof(Type ::Value)43 #define _CLIENTID _PACKETID + sizeof(Type) 44 44 #define _ENDIANTEST _CLIENTID + sizeof(uint32_t) 45 45 … … 51 51 data_=new uint8_t[ getSize() ]; 52 52 assert(data_); 53 *(packet::Type ::Value*)(data_ + _PACKETID ) = packet::Type::Welcome;53 *(packet::Type *)(data_ + _PACKETID ) = packet::Type::Welcome; 54 54 *(uint32_t *)(data_ + _CLIENTID ) = static_cast<uint32_t>(clientID); 55 55 *(uint32_t *)(data_ + _ENDIANTEST ) = 0xFEDC4321; … … 70 70 71 71 unsigned int Welcome::getSize() const{ 72 return sizeof(packet::Type ::Value) + 2*sizeof(uint32_t);72 return sizeof(packet::Type) + 2*sizeof(uint32_t); 73 73 } 74 74
Note: See TracChangeset
for help on using the changeset viewer.