Add NetworkHost id and comparison operator

This commit is contained in:
2021-05-29 20:19:09 +02:00
parent 97a5daf7e6
commit 23794c8875
3 changed files with 16 additions and 0 deletions
@@ -77,6 +77,8 @@ void ENetDriver::Dispose()
_peer = nullptr;
_host = nullptr;
LOG(Info, "ENet driver stopped!");
}
bool ENetDriver::Listen()
+12
View File
@@ -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;
}
};
@@ -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)