BREAKING CHANGE: renamed original Behaviour class to BehaviourInternal, and replaced it with BehaviourBase
Original Behaviour was using old methods for detecting entering/exiting universe, they are now all under the same hood and the original is kept for UniverseEntranceManager because it needs to enter the universe without itself. The internal behaviour kept under a subnamespace of "Core.Internal" for the purpose that it might come in handy for other use cases.
This commit is contained in:
@@ -56,17 +56,17 @@ public class LiteNetLibClient : LiteNetLibCommunicatorBase, INetworkCommunicator
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
public override void EnterUniverse(IUniverse universe)
|
||||
{
|
||||
base.OnEnteredUniverse(universe);
|
||||
base.EnterUniverse(universe);
|
||||
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
PollEvents(cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
public override void ExitUniverse(IUniverse universe)
|
||||
{
|
||||
base.OnExitedUniverse(universe);
|
||||
base.ExitUniverse(universe);
|
||||
cancellationTokenSource?.Cancel();
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@ using LiteNetLib.Utils;
|
||||
|
||||
namespace Engine.Systems.Network;
|
||||
|
||||
public abstract class LiteNetLibCommunicatorBase : Behaviour, INetworkCommunicator
|
||||
public abstract class LiteNetLibCommunicatorBase : Behaviour, IEnterUniverse, IExitUniverse, INetworkCommunicator
|
||||
{
|
||||
protected readonly NetPacketProcessor netPacketProcessor = new();
|
||||
|
||||
@@ -33,15 +33,13 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, INetworkCommunicat
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
public virtual void EnterUniverse(IUniverse universe)
|
||||
{
|
||||
base.OnEnteredUniverse(universe);
|
||||
logger = universe.FindBehaviour<ILogger>();
|
||||
}
|
||||
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
public virtual void ExitUniverse(IUniverse universe)
|
||||
{
|
||||
base.OnExitedUniverse(universe);
|
||||
logger = null;
|
||||
Stop();
|
||||
}
|
||||
|
@@ -88,15 +88,15 @@ public class LiteNetLibServer : LiteNetLibCommunicatorBase, INetworkCommunicator
|
||||
|
||||
private void PollEvents(IUniverse sender, IUniverse.UpdateArguments args) => Manager.PollEvents();
|
||||
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
public override void EnterUniverse(IUniverse universe)
|
||||
{
|
||||
base.OnEnteredUniverse(universe);
|
||||
base.EnterUniverse(universe);
|
||||
universe.OnPostUpdate.AddListener(PollEvents);
|
||||
}
|
||||
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
public override void ExitUniverse(IUniverse universe)
|
||||
{
|
||||
base.OnExitedUniverse(universe);
|
||||
base.ExitUniverse(universe);
|
||||
universe.OnPostUpdate.RemoveListener(PollEvents);
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ using Engine.Core;
|
||||
|
||||
namespace Engine.Integration.MonoGame;
|
||||
|
||||
public class LoadContentManager : Behaviour, IFirstFrameUpdate
|
||||
public class LoadContentManager : Behaviour, IEnterUniverse, IExitUniverse, IFirstFrameUpdate
|
||||
{
|
||||
// We use Ascending order because we are using reverse for loop to call them
|
||||
private static Comparer<int> SortByAscendingPriority() => Comparer<int>.Create((x, y) => x.CompareTo(y));
|
||||
@@ -20,14 +20,14 @@ public class LoadContentManager : Behaviour, IFirstFrameUpdate
|
||||
monoGameWindowContainer = Universe.FindRequiredBehaviour<MonoGameWindowContainer>();
|
||||
}
|
||||
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
public void EnterUniverse(IUniverse universe)
|
||||
{
|
||||
loadContents.Assign(universe);
|
||||
|
||||
universe.OnPreUpdate.AddListener(OnPreUpdate);
|
||||
}
|
||||
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
public void ExitUniverse(IUniverse universe)
|
||||
{
|
||||
loadContents.Unassign();
|
||||
|
||||
|
@@ -5,7 +5,7 @@ using Engine.Core;
|
||||
|
||||
namespace Engine.Integration.MonoGame;
|
||||
|
||||
public class MonoGameCamera2D : BehaviourBase, ICamera2D, IFirstFrameUpdate, IPreDraw
|
||||
public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, IPreDraw
|
||||
{
|
||||
public Event<MonoGameCamera2D> OnMatrixTransformChanged { get; } = new();
|
||||
public Event<MonoGameCamera2D> OnViewportChanged { get; } = new();
|
||||
|
@@ -5,7 +5,7 @@ using Engine.Core;
|
||||
|
||||
namespace Engine.Integration.MonoGame;
|
||||
|
||||
public class MonoGameCamera3D : BehaviourBase, ICamera3D, IFirstFrameUpdate, IPreDraw
|
||||
public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, IPreDraw
|
||||
{
|
||||
public Event<MonoGameCamera3D, ViewChangedArguments> OnViewChanged { get; } = new();
|
||||
public Event<MonoGameCamera3D, ProjectionChangedArguments> OnProjectionChanged { get; } = new();
|
||||
|
@@ -4,7 +4,7 @@ using Engine.Core;
|
||||
|
||||
namespace Engine.Integration.MonoGame;
|
||||
|
||||
public class SpriteBatcher : BehaviourBase, IFirstFrameUpdate, IDraw
|
||||
public class SpriteBatcher : Behaviour, IFirstFrameUpdate, IDraw
|
||||
{
|
||||
private static Comparer<int> SortByPriority() => Comparer<int>.Create((x, y) => y.CompareTo(x));
|
||||
private static System.Func<IBehaviour, int> GetPriority() => (b) => b.Priority;
|
||||
|
@@ -6,7 +6,7 @@ using Engine.Core;
|
||||
|
||||
namespace Engine.Integration.MonoGame;
|
||||
|
||||
public class TriangleBatcher : BehaviourBase, ITriangleBatch, IFirstFrameUpdate, IDraw
|
||||
public class TriangleBatcher : Behaviour, ITriangleBatch, IFirstFrameUpdate, IDraw
|
||||
{
|
||||
private static Comparer<int> SortByAscendingPriority() => Comparer<int>.Create((x, y) => x.CompareTo(y));
|
||||
private static System.Func<IBehaviour, int> GetPriority() => (b) => b.Priority;
|
||||
|
@@ -4,7 +4,7 @@ using Engine.Core.Serialization;
|
||||
namespace Engine.Integration.MonoGame;
|
||||
|
||||
[IgnoreSerialization]
|
||||
public class MonoGameWindowContainer(MonoGameWindow GameWindow) : BehaviourBase
|
||||
public class MonoGameWindowContainer(MonoGameWindow GameWindow) : Behaviour
|
||||
{
|
||||
public MonoGameWindow Window { get; } = GameWindow;
|
||||
}
|
||||
|
Reference in New Issue
Block a user