Merge branch 'networkdriver-csharp' of git://github.com/Erdroy/FlaxEngine into Erdroy-networkdriver-csharp

This commit is contained in:
Wojtek Figat
2021-10-18 10:37:44 +02:00
4 changed files with 24 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ DECLARE_SCRIPTING_TYPE(ENetDriver);
public:
// [INetworkDriver]
String DriverName() override { return String("ENetDriver"); }
void Initialize(NetworkPeer* host, const NetworkConfig& config) override;
void Dispose() override;
bool Listen() override;

View File

@@ -3,6 +3,7 @@
#pragma once
#include "Types.h"
#include "Engine/Core/Types/String.h"
#include "Engine/Scripting/ScriptingType.h"
/// <summary>
@@ -18,6 +19,14 @@ public:
/// </summary>
virtual ~INetworkDriver() = default;
/// <summary>
/// Return name of this network driver implementation.
/// </summary>
API_FUNCTION() virtual String DriverName()
{
return String("Unknown");
}
/// <summary>
/// Initializes the instance of this network driver using given configuration.
/// </summary>

View File

@@ -4,10 +4,12 @@
#include "Engine/Platform/Network.h"
class PersistentScriptingObject;
/// <summary>
/// Network driver implementations enum.
/// </summary>
API_ENUM(Namespace="FlaxEngine.Networking") enum class NetworkDriverType
API_ENUM(Namespace="FlaxEngine.Networking") enum class DEPRECATED NetworkDriverType
{
/// <summary>
/// Invalid network driver implementation.
@@ -32,8 +34,13 @@ public:
/// To allow two peers to connect, they must use the same host.
/// </summary>
API_FIELD()
NetworkDriverType NetworkDriverType = NetworkDriverType::ENet;
// TODO: Expose INetworkDriver as a ref not enum, when C++/C# interfaces are done.
DEPRECATED NetworkDriverType NetworkDriverType = NetworkDriverType::ENet;
/// <summary>
/// The network driver instance that will be used to create and manage the peer, send and receive messages.
/// </summary>
API_FIELD()
PersistentScriptingObject* NetworkDriver = nullptr;
public:
/// <summary>

View File

@@ -20,10 +20,10 @@ void NetworkPeer::Initialize(const NetworkConfig& config)
Config = config;
ASSERT(NetworkDriver == nullptr);
ASSERT(Config.NetworkDriverType != NetworkDriverType::Undefined);
ASSERT(Config.NetworkDriver != nullptr);
ASSERT(Config.ConnectionsLimit > 0);
ASSERT(Config.MessageSize > 32); // TODO: Adjust this, not sure what the lowest limit should be.
ASSERT(Config.MessagePoolSize > 128);
ASSERT(Config.MessagePoolSize > 128);
// TODO: Dynamic message pool allocation
// Setup messages
@@ -35,10 +35,10 @@ void NetworkPeer::Initialize(const NetworkConfig& config)
MessagePool.Push(messageId);
// Setup network driver
NetworkDriver = New<ENetDriver>();
NetworkDriver = ToInterface<INetworkDriver>(Config.NetworkDriver);
NetworkDriver->Initialize(this, Config);
LOG(Info, "NetworkManager initialized using driver = {0}", static_cast<int>(Config.NetworkDriverType));
LOG(Info, "NetworkManager initialized using driver = {0}", NetworkDriver->DriverName());
}
void NetworkPeer::Shutdown()