diff --git a/Source/Engine/Networking/NetworkEvent.h b/Source/Engine/Networking/NetworkEvent.h index 1e4dd5870..83caee479 100644 --- a/Source/Engine/Networking/NetworkEvent.h +++ b/Source/Engine/Networking/NetworkEvent.h @@ -28,7 +28,4 @@ public: API_FIELD(); NetworkConnection Sender; - - API_FIELD(); - int32 HostId; }; diff --git a/Source/Engine/Networking/NetworkManager.cpp b/Source/Engine/Networking/NetworkManager.cpp index f6f04dc21..12bac1b0c 100644 --- a/Source/Engine/Networking/NetworkManager.cpp +++ b/Source/Engine/Networking/NetworkManager.cpp @@ -12,6 +12,7 @@ namespace { Array 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* 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 } diff --git a/Source/Engine/Networking/NetworkPeer.cpp b/Source/Engine/Networking/NetworkPeer.cpp index a72201121..e8a5935ef 100644 --- a/Source/Engine/Networking/NetworkPeer.cpp +++ b/Source/Engine/Networking/NetworkPeer.cpp @@ -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); }