This commit is contained in:
2025-05-30 16:05:49 +03:00
committed by Syntriax
parent 846aa75dd5
commit b5140a94de
57 changed files with 437 additions and 462 deletions

View File

@@ -1,17 +1,15 @@
using System;
namespace Syntriax.Engine.Core;
[System.Diagnostics.DebuggerDisplay("{GetType().Name, nq}, Priority: {Priority}, Initialized: {Initialized}")]
public abstract class BehaviourBase : BaseEntity, IBehaviour
{
public Event<IBehaviour, int> OnPriorityChanged { get; private set; } = new();
public Event<IActive, bool> OnActiveChanged { get; private set; } = new();
public Event<IHasBehaviourController> OnBehaviourControllerAssigned { get; private set; } = new();
public Event<IBehaviour, IBehaviour.PriorityChangedArguments> OnPriorityChanged { get; init; } = new();
public Event<IActive, IActive.ActiveChangedArguments> OnActiveChanged { get; init; } = new();
public Event<IHasBehaviourController> OnBehaviourControllerAssigned { get; init; } = new();
private Action<IHasUniverseObject> cachedOnUniverseObjectAssigned = null!;
private Action<IActive, bool> cachedOnUniverseObjectActiveChanged = null!;
private Action<IStateEnable, bool> cachedOnStateEnabledChanged = null!;
private readonly Event<IHasUniverseObject>.EventHandler cachedOnUniverseObjectAssigned = null!;
private readonly Event<IActive, IActive.ActiveChangedArguments>.EventHandler cachedOnUniverseObjectActiveChanged = null!;
private readonly Event<IStateEnable, IStateEnable.EnabledChangedArguments>.EventHandler cachedOnStateEnabledChanged = null!;
private IBehaviourController _behaviourController = null!;
public IBehaviourController BehaviourController => _behaviourController;
@@ -27,7 +25,7 @@ public abstract class BehaviourBase : BaseEntity, IBehaviour
int previousPriority = _priority;
_priority = value;
OnPriorityChanged?.Invoke(this, previousPriority);
OnPriorityChanged?.Invoke(this, new(previousPriority));
}
}
@@ -77,8 +75,8 @@ public abstract class BehaviourBase : BaseEntity, IBehaviour
Debug.Assert.AssertStateEnableAssigned(this);
}
private void OnStateEnabledChanged(IStateEnable sender, bool previousState) => UpdateActive();
private void OnUniverseObjectActiveChanged(IActive sender, bool previousState) => UpdateActive();
private void OnStateEnabledChanged(IStateEnable sender, IStateEnable.EnabledChangedArguments arguments) => UpdateActive();
private void OnUniverseObjectActiveChanged(IActive sender, IActive.ActiveChangedArguments arguments) => UpdateActive();
private void UpdateActive()
{
@@ -86,7 +84,7 @@ public abstract class BehaviourBase : BaseEntity, IBehaviour
_isActive = StateEnable.Enabled && _behaviourController.UniverseObject.IsActive;
if (previousActive != IsActive)
OnActiveChanged?.Invoke(this, previousActive);
OnActiveChanged?.Invoke(this, new(previousActive));
}
protected BehaviourBase()