Remove NetworkManager and move peer creation/shutdown to NetworkPeer class

This commit is contained in:
Damian Korczowski
2021-06-26 21:30:11 +02:00
parent 6aece4e388
commit a6ccbe3876
4 changed files with 52 additions and 76 deletions

View File

@@ -9,6 +9,12 @@
#include "Engine/Core/Math/Math.h"
#include "Engine/Platform/CPUInfo.h"
namespace
{
Array<NetworkPeer*, HeapAllocation> Peers;
uint32_t LastHostId = 0;
}
void NetworkPeer::Initialize(const NetworkConfig& config)
{
Config = config;
@@ -156,3 +162,31 @@ bool NetworkPeer::EndSendMessage(const NetworkChannelType channelType, const Net
RecycleMessage(message);
return false;
}
NetworkPeer* NetworkPeer::CreatePeer(const NetworkConfig& config)
{
// Validate the address for listen/connect
NetworkEndPoint endPoint = {};
const bool isValidEndPoint = NetworkBase::CreateEndPoint(config.Address, String("7777"), NetworkIPVersion::IPv4, endPoint, false);
ASSERT(config.Address == String("any") || isValidEndPoint);
// Alloc new host
Peers.Add(New<NetworkPeer>());
NetworkPeer* host = Peers.Last();
host->HostId = LastHostId++;
// Initialize the host
host->Initialize(config);
return host;
}
void NetworkPeer::ShutdownPeer(NetworkPeer* peer)
{
ASSERT(peer->IsValid());
peer->Shutdown();
peer->HostId = -1;
Peers.Remove(peer);
Delete(peer);
}