Network/ENet: Move all packet allocation to host

This commit is contained in:
Lynix
2017-02-16 23:26:00 +01:00
parent 8225ad3b41
commit b7ee6d7b29
6 changed files with 37 additions and 29 deletions

View File

@@ -71,6 +71,9 @@ namespace Nz
ENetHost& operator=(ENetHost&&) = default;
private:
ENetPacketRef AllocatePacket(ENetPacketFlags flags);
inline ENetPacketRef AllocatePacket(ENetPacketFlags flags, NetPacket&& data);
bool InitSocket(const IpAddress& address);
void AddToDispatchQueue(ENetPeer* peer);

View File

@@ -56,6 +56,14 @@ namespace Nz
{
return m_serviceTime;
}
inline ENetPacketRef ENetHost::AllocatePacket(ENetPacketFlags flags, NetPacket&& data)
{
ENetPacketRef ref = AllocatePacket(flags);
ref->data = std::move(data);
return ref;
}
}
#include <Nazara/Network/DebugOff.hpp>

View File

@@ -20,7 +20,6 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Core/MemoryPool.hpp>
#include <Nazara/Network/ENetPacket.hpp>
#include <Nazara/Network/ENetProtocol.hpp>
#include <Nazara/Network/IpAddress.hpp>
@@ -40,7 +39,7 @@ namespace Nz
friend struct PacketRef;
public:
ENetPeer(ENetHost* host, UInt16 peerId);
inline ENetPeer(ENetHost* host, UInt16 peerId);
ENetPeer(const ENetPeer&) = delete;
ENetPeer(ENetPeer&&) = default;
~ENetPeer() = default;
@@ -186,7 +185,6 @@ namespace Nz
std::size_t m_totalWaitingData;
std::vector<Acknowledgement> m_acknowledgements;
std::vector<Channel> m_channels;
MemoryPool m_packetPool;
ENetPeerState m_state;
UInt8 m_incomingSessionID;
UInt8 m_outgoingSessionID;

View File

@@ -8,6 +8,15 @@
namespace Nz
{
inline ENetPeer::ENetPeer(ENetHost* host, UInt16 peerId) :
m_host(host),
m_incomingSessionID(0xFF),
m_outgoingSessionID(0xFF),
m_incomingPeerID(peerId)
{
Reset();
}
inline const IpAddress& ENetPeer::GetAddress() const
{
return m_address;