This commit is contained in:
Damian Korczowski
2021-06-21 20:10:03 +02:00
parent bb75ee81d5
commit 6772d447fa
3 changed files with 3 additions and 10 deletions

View File

@@ -28,7 +28,4 @@ public:
API_FIELD();
NetworkConnection Sender;
API_FIELD();
int32 HostId;
};

View File

@@ -12,6 +12,7 @@
namespace
{
Array<NetworkPeer*, HeapAllocation> Hosts;
uint32_t LastHostId = 0;
}
NetworkPeer* NetworkManager::CreateHost(const NetworkConfig& config)
@@ -22,11 +23,9 @@ NetworkPeer* NetworkManager::CreateHost(const NetworkConfig& config)
ASSERT(config.Address == String("any") || isValidEndPoint);
// Alloc new host
const int hostId = Hosts.Count(); // TODO: Maybe keep the host count under a limit? Maybe some drivers do not support this?
// TODO: Reuse host ids
Hosts.Add(New<NetworkPeer>());
NetworkPeer* host = Hosts.Last();
host->HostId = hostId;
host->HostId = LastHostId++;
// Initialize the host
host->Initialize(config);
@@ -38,8 +37,7 @@ void NetworkManager::ShutdownHost(NetworkPeer* host)
{
ASSERT(host->IsValid());
host->Shutdown();
Hosts[host->HostId] = nullptr;
host->HostId = -1;
Hosts.Remove(host);
// Hosts.Remove(host); // Do not remove hosts, because we need to keep the array unmodified to make the id's work
}

View File

@@ -95,8 +95,6 @@ void NetworkPeer::Disconnect(const NetworkConnection& connection)
bool NetworkPeer::PopEvent(NetworkEvent& eventRef)
{
// Set host id of the event
eventRef.HostId = HostId;
return NetworkDriver->PopEvent(&eventRef);
}