Cleanup ENetDriver and use interface properly for scripting

This commit is contained in:
Wojtek Figat
2021-10-04 12:23:01 +02:00
parent c3c0a4ef0d
commit ecf926a537
5 changed files with 52 additions and 51 deletions

View File

@@ -6,43 +6,42 @@
#include "Engine/Networking/INetworkDriver.h"
#include "Engine/Networking/NetworkConnection.h"
#include "Engine/Networking/NetworkConfig.h"
#include "Engine/Core/Collections/Dictionary.h"
#include "Engine/Scripting/ScriptingObject.h"
#include "Engine/Scripting/ScriptingType.h"
/// <summary>
/// Low-level network transport interface implementation based on ENet library.
/// </summary>
API_CLASS(Namespace="FlaxEngine.Networking", Sealed) class FLAXENGINE_API ENetDriver : public INetworkDriver
API_CLASS(Namespace="FlaxEngine.Networking", Sealed) class FLAXENGINE_API ENetDriver : public PersistentScriptingObject, public INetworkDriver
{
DECLARE_SCRIPTING_TYPE_MINIMAL(ENetDriver);
DECLARE_SCRIPTING_TYPE(ENetDriver);
public:
// [INetworkDriver]
void Initialize(NetworkPeer* host, const NetworkConfig& config) override;
void Dispose() override;
bool Listen() override;
bool Connect() override;
void Disconnect() override;
void Disconnect(const NetworkConnection& connection) override;
bool PopEvent(NetworkEvent* eventPtr) override;
void SendMessage(NetworkChannelType channelType, const NetworkMessage& message) override;
void SendMessage(NetworkChannelType channelType, const NetworkMessage& message, NetworkConnection target) override;
void SendMessage(NetworkChannelType channelType, const NetworkMessage& message, const Array<NetworkConnection, HeapAllocation>& targets) override;
private:
bool IsServer() const
{
return _host != nullptr && _peer == nullptr;
}
private:
NetworkConfig _config;
NetworkPeer* _networkHost;
void* _host = nullptr;
void* _peer = nullptr;
Dictionary<uint32, void*> _peerMap;
};