Added UWorld

This commit is contained in:
AeonLucid
2022-01-09 21:21:18 +01:00
parent 29bd62cc9e
commit 49e6e0f6f8
10 changed files with 151 additions and 33 deletions
+56
View File
@@ -0,0 +1,56 @@
using Prospect.Unreal.Core;
using Prospect.Unreal.Net;
using Serilog;
namespace Prospect.Unreal.Runtime;
public abstract class UWorld : IAsyncDisposable
{
private static readonly ILogger Logger = Log.ForContext<UWorld>();
public UWorld(FUrl url)
{
Url = url;
}
public FUrl Url { get; }
public UNetDriver? NetDriver { get; private set; }
public void Tick(float deltaTime)
{
if (NetDriver != null)
{
NetDriver.TickDispatch(deltaTime);
NetDriver.ConnectionlessHandler?.Tick(deltaTime);
}
}
public bool Listen()
{
if (NetDriver != null)
{
Logger.Error("NetDriver already exists");
return false;
}
NetDriver = new UIpNetDriver(Url.Host, Url.Port);
NetDriver.SetWorld(this);
if (!NetDriver.Init())
{
Logger.Error("Failed to listen");
NetDriver = null;
return false;
}
return true;
}
public async ValueTask DisposeAsync()
{
if (NetDriver != null)
{
await NetDriver.DisposeAsync();
}
}
}