Network: Fix ENetPacket
This commit is contained in:
parent
2229dfd6e5
commit
3507ec570f
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Network/NetPacket.hpp>
|
#include <Nazara/Network/NetPacket.hpp>
|
||||||
#include <Nazara/Utils/MemoryPool.hpp>
|
#include <Nazara/Utils/MemoryPool.hpp>
|
||||||
|
#include <Nazara/Utils/MovablePtr.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
|
@ -42,7 +43,8 @@ namespace Nz
|
||||||
{
|
{
|
||||||
ENetPacketRef() = default;
|
ENetPacketRef() = default;
|
||||||
|
|
||||||
ENetPacketRef(ENetPacket* packet)
|
ENetPacketRef(MemoryPool<ENetPacket>* pool, ENetPacket* packet) :
|
||||||
|
m_pool(pool)
|
||||||
{
|
{
|
||||||
Reset(packet);
|
Reset(packet);
|
||||||
}
|
}
|
||||||
|
|
@ -51,13 +53,10 @@ namespace Nz
|
||||||
ENetPacketRef()
|
ENetPacketRef()
|
||||||
{
|
{
|
||||||
Reset(packet);
|
Reset(packet);
|
||||||
|
m_pool = packet.m_pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
ENetPacketRef(ENetPacketRef&& packet) noexcept :
|
ENetPacketRef(ENetPacketRef&&) noexcept = default;
|
||||||
m_packet(packet.m_packet)
|
|
||||||
{
|
|
||||||
packet.m_packet = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
~ENetPacketRef()
|
~ENetPacketRef()
|
||||||
{
|
{
|
||||||
|
|
@ -76,30 +75,17 @@ namespace Nz
|
||||||
return m_packet;
|
return m_packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
ENetPacketRef& operator=(ENetPacket* packet)
|
|
||||||
{
|
|
||||||
Reset(packet);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ENetPacketRef& operator=(const ENetPacketRef& packet)
|
ENetPacketRef& operator=(const ENetPacketRef& packet)
|
||||||
{
|
{
|
||||||
Reset(packet);
|
Reset(packet);
|
||||||
|
m_pool = packet.m_pool;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ENetPacketRef& operator=(ENetPacketRef&& packet) noexcept
|
ENetPacketRef& operator=(ENetPacketRef&&) noexcept = default;
|
||||||
{
|
|
||||||
m_packet = packet.m_packet;
|
|
||||||
packet.m_packet = nullptr;
|
|
||||||
|
|
||||||
return *this;
|
MovablePtr<MemoryPool<ENetPacket>> m_pool;
|
||||||
}
|
MovablePtr<ENetPacket> m_packet;
|
||||||
|
|
||||||
MemoryPool<ENetPacket>* m_pool = nullptr;
|
|
||||||
ENetPacket* m_packet = nullptr;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
event->type = ENetEventType::None;
|
event->type = ENetEventType::None;
|
||||||
event->peer = nullptr;
|
event->peer = nullptr;
|
||||||
event->packet = nullptr;
|
event->packet.Reset();
|
||||||
|
|
||||||
if (DispatchIncomingCommands(event))
|
if (DispatchIncomingCommands(event))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -313,7 +313,10 @@ namespace Nz
|
||||||
ENetPacketRef ENetHost::AllocatePacket(ENetPacketFlags flags)
|
ENetPacketRef ENetHost::AllocatePacket(ENetPacketFlags flags)
|
||||||
{
|
{
|
||||||
std::size_t poolIndex;
|
std::size_t poolIndex;
|
||||||
ENetPacketRef enetPacket = m_packetPool.Allocate(poolIndex);
|
|
||||||
|
ENetPacket* packet = m_packetPool.Allocate(poolIndex);
|
||||||
|
|
||||||
|
ENetPacketRef enetPacket(&m_packetPool, packet);
|
||||||
enetPacket->flags = flags;
|
enetPacket->flags = flags;
|
||||||
enetPacket->poolIndex = poolIndex;
|
enetPacket->poolIndex = poolIndex;
|
||||||
enetPacket.m_pool = &m_packetPool;
|
enetPacket.m_pool = &m_packetPool;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue