From 23794c88753b0b952277d14216349938e1cc681f Mon Sep 17 00:00:00 2001 From: Damian Korczowski Date: Sat, 29 May 2021 20:19:09 +0200 Subject: [PATCH] Add NetworkHost id and comparison operator --- Source/Engine/Networking/Drivers/ENetDriver.cpp | 2 ++ Source/Engine/Networking/NetworkHost.h | 12 ++++++++++++ Source/Engine/Networking/NetworkManager.cpp | 2 ++ 3 files changed, 16 insertions(+) diff --git a/Source/Engine/Networking/Drivers/ENetDriver.cpp b/Source/Engine/Networking/Drivers/ENetDriver.cpp index 37beaccc7..c5c79f69e 100644 --- a/Source/Engine/Networking/Drivers/ENetDriver.cpp +++ b/Source/Engine/Networking/Drivers/ENetDriver.cpp @@ -77,6 +77,8 @@ void ENetDriver::Dispose() _peer = nullptr; _host = nullptr; + + LOG(Info, "ENet driver stopped!"); } bool ENetDriver::Listen() diff --git a/Source/Engine/Networking/NetworkHost.h b/Source/Engine/Networking/NetworkHost.h index 7def414d4..dae0f99fd 100644 --- a/Source/Engine/Networking/NetworkHost.h +++ b/Source/Engine/Networking/NetworkHost.h @@ -10,6 +10,7 @@ struct FLAXENGINE_API NetworkHost { public: + int HostId; NetworkConfig Config; INetworkDriver* NetworkDriver = nullptr; @@ -32,5 +33,16 @@ public: // Calculate and return the buffer slice using previously calculated slice. return MessageBuffer + Config.MessageSize * messageId; } + +public: + FORCE_INLINE bool operator==(const NetworkHost& other) const + { + return HostId == other.HostId; + } + + FORCE_INLINE bool operator!=(const NetworkHost& other) const + { + return HostId != other.HostId; + } }; diff --git a/Source/Engine/Networking/NetworkManager.cpp b/Source/Engine/Networking/NetworkManager.cpp index 2088af372..1ab75b54c 100644 --- a/Source/Engine/Networking/NetworkManager.cpp +++ b/Source/Engine/Networking/NetworkManager.cpp @@ -29,6 +29,7 @@ int NetworkManager::Initialize(const NetworkConfig& config) const int hostId = Hosts.Count(); Hosts.Add(NetworkHost()); NetworkHost& host = Hosts.Last(); + host.HostId = hostId; // Initialize the host host.Initialize(config); @@ -41,6 +42,7 @@ void NetworkManager::Shutdown(const int hostId) ASSERT(Hosts[hostId].IsValid()); NetworkHost& host = Hosts[hostId]; host.Shutdown(); + Hosts.Remove(host); } bool NetworkManager::Listen(const int hostId)