chore: updated engine with non-universe-object managers
This commit is contained in:
@@ -15,7 +15,7 @@ public class LiteNetLibClient : LiteNetLibCommunicatorBase, INetworkCommunicator
|
||||
|
||||
public INetworkCommunicatorClient Connect(string address, int port, string? password = null)
|
||||
{
|
||||
if (!IsInUniverse)
|
||||
if (!UniverseObject.IsInUniverse)
|
||||
throw new($"{nameof(LiteNetLibClient)} must be in an universe to connect");
|
||||
|
||||
Manager.Start();
|
||||
@@ -33,17 +33,17 @@ public class LiteNetLibClient : LiteNetLibCommunicatorBase, INetworkCommunicator
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override void OnEnteringUniverse(IUniverse universe)
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
{
|
||||
base.OnEnteringUniverse(universe);
|
||||
base.OnEnteredUniverse(universe);
|
||||
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
PollEvents(cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
protected override void OnExitingUniverse(IUniverse universe)
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
{
|
||||
base.OnExitingUniverse(universe);
|
||||
base.OnExitedUniverse(universe);
|
||||
cancellationTokenSource?.Cancel();
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,7 @@ using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Network;
|
||||
|
||||
public abstract class LiteNetLibCommunicatorBase : UniverseObject, INetworkCommunicator
|
||||
public abstract class LiteNetLibCommunicatorBase : Behaviour, INetworkCommunicator
|
||||
{
|
||||
protected readonly NetPacketProcessor netPacketProcessor = new();
|
||||
|
||||
@@ -25,9 +25,9 @@ public abstract class LiteNetLibCommunicatorBase : UniverseObject, INetworkCommu
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override void OnExitingUniverse(IUniverse universe)
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
{
|
||||
base.OnExitingUniverse(universe);
|
||||
base.OnExitedUniverse(universe);
|
||||
Stop();
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,7 @@ public class LiteNetLibServer : LiteNetLibCommunicatorBase, INetworkCommunicator
|
||||
|
||||
public INetworkCommunicatorServer Start(int port, int maxConnectionCount, string? password = null)
|
||||
{
|
||||
if (!IsInUniverse)
|
||||
if (!UniverseObject.IsInUniverse)
|
||||
throw new($"{nameof(LiteNetLibServer)} must be in an universe to start");
|
||||
|
||||
Password = password ?? string.Empty;
|
||||
@@ -62,15 +62,15 @@ public class LiteNetLibServer : LiteNetLibCommunicatorBase, INetworkCommunicator
|
||||
|
||||
private void PollEvents(IUniverse sender, IUniverse.UpdateArguments args) => Manager.PollEvents();
|
||||
|
||||
protected override void OnEnteringUniverse(IUniverse universe)
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
{
|
||||
base.OnEnteringUniverse(universe);
|
||||
base.OnEnteredUniverse(universe);
|
||||
universe.OnPostUpdate.AddListener(PollEvents);
|
||||
}
|
||||
|
||||
protected override void OnExitingUniverse(IUniverse universe)
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
{
|
||||
base.OnExitingUniverse(universe);
|
||||
base.OnExitedUniverse(universe);
|
||||
universe.OnPostUpdate.RemoveListener(PollEvents);
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ namespace Syntriax.Engine.Network;
|
||||
/// <summary>
|
||||
/// Intermediary manager that looks up in it's hierarchy for a <see cref="INetworkCommunicator"/> to route/broadcast it's received packets to their destinations.
|
||||
/// </summary>
|
||||
public class NetworkManager : UniverseObject, INetworkManager
|
||||
public class NetworkManager : Behaviour, INetworkManager
|
||||
{
|
||||
private readonly Dictionary<Type, Dictionary<Type, List<MethodInfo>>> clientPacketArrivalMethods = [];
|
||||
private readonly Dictionary<Type, Dictionary<Type, List<MethodInfo>>> serverPacketArrivalMethods = [];
|
||||
@@ -231,11 +231,11 @@ public class NetworkManager : UniverseObject, INetworkManager
|
||||
UnregisterPacketRoutersFor(removedBehaviour, serverPacketRouters, serverPacketArrivalMethods);
|
||||
}
|
||||
|
||||
protected override void OnExitingUniverse(IUniverse universe) => _networkEntityCollector.Unassign();
|
||||
protected override void OnEnteringUniverse(IUniverse universe)
|
||||
protected override void OnExitedUniverse(IUniverse universe) => _networkEntityCollector.Unassign();
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
{
|
||||
_networkEntityCollector.Assign(universe);
|
||||
NetworkCommunicator = this.GetRequiredUniverseObjectInParent<INetworkCommunicator>();
|
||||
NetworkCommunicator = BehaviourController.GetRequiredBehaviourInParent<INetworkCommunicator>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
Reference in New Issue
Block a user