Rename NetworkHost to NetworkPeer as it seems more appropriate
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include "Engine/Networking/NetworkConfig.h"
|
||||
#include "Engine/Networking/NetworkChannelType.h"
|
||||
#include "Engine/Networking/NetworkEvent.h"
|
||||
#include "Engine/Networking/NetworkHost.h"
|
||||
#include "Engine/Networking/NetworkPeer.h"
|
||||
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
@@ -53,7 +53,7 @@ void SendPacketToPeer(ENetPeer* peer, const NetworkChannelType channelType, cons
|
||||
// TODO: To reduce latency, we can use `enet_host_flush` to flush all packets. Maybe some API, like NetworkManager::FlushQueues()?
|
||||
}
|
||||
|
||||
void ENetDriver::Initialize(NetworkHost* host, const NetworkConfig& config)
|
||||
void ENetDriver::Initialize(NetworkPeer* host, const NetworkConfig& config)
|
||||
{
|
||||
_networkHost = host;
|
||||
_config = config;
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
#include "Engine/Core/Collections/Dictionary.h"
|
||||
#include "Engine/Scripting/ScriptingType.h"
|
||||
|
||||
class NetworkHost;
|
||||
class NetworkPeer;
|
||||
|
||||
API_CLASS(Namespace="FlaxEngine.Networking", Sealed) class FLAXENGINE_API ENetDriver : public INetworkDriver
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_MINIMAL(ENetDriver);
|
||||
public:
|
||||
void Initialize(NetworkHost* host, const NetworkConfig& config) override;
|
||||
void Initialize(NetworkPeer* host, const NetworkConfig& config) override;
|
||||
void Dispose() override;
|
||||
|
||||
bool Listen() override;
|
||||
@@ -38,7 +38,7 @@ private:
|
||||
|
||||
private:
|
||||
NetworkConfig _config;
|
||||
NetworkHost* _networkHost;
|
||||
NetworkPeer* _networkHost;
|
||||
void* _host = nullptr;
|
||||
void* _peer = nullptr;
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
#include "Engine/Scripting/ScriptingType.h"
|
||||
|
||||
class NetworkHost;
|
||||
class NetworkPeer;
|
||||
|
||||
API_INTERFACE(Namespace="FlaxEngine.Networking") class FLAXENGINE_API INetworkDriver
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_MINIMAL(INetworkDriver);
|
||||
public:
|
||||
virtual void Initialize(NetworkHost* host, const NetworkConfig& config) = 0;
|
||||
virtual void Initialize(NetworkPeer* host, const NetworkConfig& config) = 0;
|
||||
virtual void Dispose() = 0;
|
||||
|
||||
virtual bool Listen() = 0;
|
||||
|
||||
@@ -4,17 +4,17 @@
|
||||
|
||||
#include "NetworkMessage.h"
|
||||
#include "NetworkConfig.h"
|
||||
#include "NetworkHost.h"
|
||||
#include "NetworkPeer.h"
|
||||
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
Array<NetworkHost*, HeapAllocation> Hosts;
|
||||
Array<NetworkPeer*, HeapAllocation> Hosts;
|
||||
}
|
||||
|
||||
NetworkHost* NetworkManager::CreateHost(const NetworkConfig& config)
|
||||
NetworkPeer* NetworkManager::CreateHost(const NetworkConfig& config)
|
||||
{
|
||||
// Validate the address for listen/connect
|
||||
NetworkEndPoint endPoint = {};
|
||||
@@ -24,8 +24,8 @@ NetworkHost* NetworkManager::CreateHost(const NetworkConfig& config)
|
||||
// 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<NetworkHost>());
|
||||
NetworkHost* host = Hosts.Last();
|
||||
Hosts.Add(New<NetworkPeer>());
|
||||
NetworkPeer* host = Hosts.Last();
|
||||
host->HostId = hostId;
|
||||
|
||||
// Initialize the host
|
||||
@@ -34,7 +34,7 @@ NetworkHost* NetworkManager::CreateHost(const NetworkConfig& config)
|
||||
return host;
|
||||
}
|
||||
|
||||
void NetworkManager::ShutdownHost(NetworkHost* host)
|
||||
void NetworkManager::ShutdownHost(NetworkPeer* host)
|
||||
{
|
||||
ASSERT(host->IsValid());
|
||||
host->Shutdown();
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
#include "Engine/Scripting/ScriptingType.h"
|
||||
#include "Types.h"
|
||||
|
||||
class NetworkHost;
|
||||
class NetworkPeer;
|
||||
|
||||
API_CLASS(Namespace="FlaxEngine.Networking", Static) class FLAXENGINE_API NetworkManager
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(NetworkManager);
|
||||
public:
|
||||
|
||||
API_FUNCTION() static NetworkHost* CreateHost(const NetworkConfig& config);
|
||||
API_FUNCTION() static void ShutdownHost(NetworkHost* host);
|
||||
API_FUNCTION() static NetworkPeer* CreateHost(const NetworkConfig& config);
|
||||
API_FUNCTION() static void ShutdownHost(NetworkPeer* host);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "NetworkHost.h"
|
||||
#include "NetworkPeer.h"
|
||||
#include "NetworkEvent.h"
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "Engine/Core/Math/Math.h"
|
||||
#include "Engine/Platform/CPUInfo.h"
|
||||
|
||||
void NetworkHost::Initialize(const NetworkConfig& config)
|
||||
void NetworkPeer::Initialize(const NetworkConfig& config)
|
||||
{
|
||||
Config = config;
|
||||
|
||||
@@ -36,7 +36,7 @@ void NetworkHost::Initialize(const NetworkConfig& config)
|
||||
LOG(Info, "NetworkManager initialized using driver = {0}", static_cast<int>(Config.NetworkDriverType));
|
||||
}
|
||||
|
||||
void NetworkHost::Shutdown()
|
||||
void NetworkPeer::Shutdown()
|
||||
{
|
||||
NetworkDriver->Dispose();
|
||||
Delete(NetworkDriver);
|
||||
@@ -45,7 +45,7 @@ void NetworkHost::Shutdown()
|
||||
NetworkDriver = nullptr;
|
||||
}
|
||||
|
||||
void NetworkHost::CreateMessageBuffers()
|
||||
void NetworkPeer::CreateMessageBuffers()
|
||||
{
|
||||
ASSERT(MessageBuffer == nullptr);
|
||||
|
||||
@@ -61,7 +61,7 @@ void NetworkHost::CreateMessageBuffers()
|
||||
Platform::MemorySet(MessageBuffer, 0, numPages * pageSize);
|
||||
}
|
||||
|
||||
void NetworkHost::DisposeMessageBuffers()
|
||||
void NetworkPeer::DisposeMessageBuffers()
|
||||
{
|
||||
ASSERT(MessageBuffer != nullptr);
|
||||
|
||||
@@ -69,38 +69,38 @@ void NetworkHost::DisposeMessageBuffers()
|
||||
MessageBuffer = nullptr;
|
||||
}
|
||||
|
||||
bool NetworkHost::Listen()
|
||||
bool NetworkPeer::Listen()
|
||||
{
|
||||
LOG(Info, "NetworkManager starting to listen on address = {0}:{1}", Config.Address, Config.Port);
|
||||
return NetworkDriver->Listen();
|
||||
}
|
||||
|
||||
bool NetworkHost::Connect()
|
||||
bool NetworkPeer::Connect()
|
||||
{
|
||||
LOG(Info, "Connecting to {0}:{1}...", Config.Address, Config.Port);
|
||||
return NetworkDriver->Connect();
|
||||
}
|
||||
|
||||
void NetworkHost::Disconnect()
|
||||
void NetworkPeer::Disconnect()
|
||||
{
|
||||
LOG(Info, "Disconnecting...");
|
||||
NetworkDriver->Disconnect();
|
||||
}
|
||||
|
||||
void NetworkHost::Disconnect(const NetworkConnection& connection)
|
||||
void NetworkPeer::Disconnect(const NetworkConnection& connection)
|
||||
{
|
||||
LOG(Info, "Disconnecting connection with id = {0}...", connection.ConnectionId);
|
||||
NetworkDriver->Disconnect(connection);
|
||||
}
|
||||
|
||||
bool NetworkHost::PopEvent(NetworkEvent& eventRef)
|
||||
bool NetworkPeer::PopEvent(NetworkEvent& eventRef)
|
||||
{
|
||||
// Set host id of the event
|
||||
eventRef.HostId = HostId;
|
||||
return NetworkDriver->PopEvent(&eventRef);
|
||||
}
|
||||
|
||||
NetworkMessage NetworkHost::CreateMessage()
|
||||
NetworkMessage NetworkPeer::CreateMessage()
|
||||
{
|
||||
const uint32 messageId = MessagePool.Pop();
|
||||
uint8* messageBuffer = GetMessageBuffer(messageId);
|
||||
@@ -108,7 +108,7 @@ NetworkMessage NetworkHost::CreateMessage()
|
||||
return NetworkMessage(messageBuffer, messageId, Config.MessageSize, 0, 0);
|
||||
}
|
||||
|
||||
void NetworkHost::RecycleMessage(const NetworkMessage& message)
|
||||
void NetworkPeer::RecycleMessage(const NetworkMessage& message)
|
||||
{
|
||||
ASSERT(message.IsValid());
|
||||
#ifdef BUILD_DEBUG
|
||||
@@ -119,18 +119,18 @@ void NetworkHost::RecycleMessage(const NetworkMessage& message)
|
||||
MessagePool.Push(message.MessageId);
|
||||
}
|
||||
|
||||
NetworkMessage NetworkHost::BeginSendMessage()
|
||||
NetworkMessage NetworkPeer::BeginSendMessage()
|
||||
{
|
||||
return CreateMessage();
|
||||
}
|
||||
|
||||
void NetworkHost::AbortSendMessage(const NetworkMessage& message)
|
||||
void NetworkPeer::AbortSendMessage(const NetworkMessage& message)
|
||||
{
|
||||
ASSERT(message.IsValid());
|
||||
RecycleMessage(message);
|
||||
}
|
||||
|
||||
bool NetworkHost::EndSendMessage(const NetworkChannelType channelType, const NetworkMessage& message)
|
||||
bool NetworkPeer::EndSendMessage(const NetworkChannelType channelType, const NetworkMessage& message)
|
||||
{
|
||||
ASSERT(message.IsValid());
|
||||
|
||||
@@ -140,7 +140,7 @@ bool NetworkHost::EndSendMessage(const NetworkChannelType channelType, const Net
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetworkHost::EndSendMessage(const NetworkChannelType channelType, const NetworkMessage& message, const NetworkConnection& target)
|
||||
bool NetworkPeer::EndSendMessage(const NetworkChannelType channelType, const NetworkMessage& message, const NetworkConnection& target)
|
||||
{
|
||||
ASSERT(message.IsValid());
|
||||
|
||||
@@ -150,7 +150,7 @@ bool NetworkHost::EndSendMessage(const NetworkChannelType channelType, const Net
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetworkHost::EndSendMessage(const NetworkChannelType channelType, const NetworkMessage& message, Array<NetworkConnection> targets)
|
||||
bool NetworkPeer::EndSendMessage(const NetworkChannelType channelType, const NetworkMessage& message, Array<NetworkConnection> targets)
|
||||
{
|
||||
ASSERT(message.IsValid());
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
|
||||
API_CLASS(sealed, NoSpawn, Namespace="FlaxEngine.Networking") class FLAXENGINE_API NetworkHost final : public PersistentScriptingObject
|
||||
API_CLASS(sealed, NoSpawn, Namespace="FlaxEngine.Networking") class FLAXENGINE_API NetworkPeer final : public PersistentScriptingObject
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(NetworkHost);
|
||||
friend class NetworkManager;
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
Array<uint32, HeapAllocation> MessagePool;
|
||||
|
||||
public:
|
||||
NetworkHost() : PersistentScriptingObject(SpawnParams(Guid::New(), TypeInitializer))
|
||||
NetworkPeer() : PersistentScriptingObject(SpawnParams(Guid::New(), TypeInitializer))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -84,12 +84,12 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
FORCE_INLINE bool operator==(const NetworkHost& other) const
|
||||
FORCE_INLINE bool operator==(const NetworkPeer& other) const
|
||||
{
|
||||
return HostId == other.HostId;
|
||||
}
|
||||
|
||||
FORCE_INLINE bool operator!=(const NetworkHost& other) const
|
||||
FORCE_INLINE bool operator!=(const NetworkPeer& other) const
|
||||
{
|
||||
return HostId != other.HostId;
|
||||
}
|
||||
Reference in New Issue
Block a user