refactor: Actions to Delegates
This commit is contained in:
parent
2cf6135063
commit
ef21cdf213
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,7 +8,7 @@ public interface IAssignable
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="IAssignable"/>'s fields are unassigned and completely ready to recycle.
|
||||
/// </summary>
|
||||
Action<IAssignable>? OnUnassigned { get; set; }
|
||||
event OnUnassignedDelegate? OnUnassigned;
|
||||
|
||||
/// <summary>
|
||||
/// Unassign <see cref="IAssignable"/>'s all fields and make it ready to recycle.
|
||||
@ -19,4 +17,6 @@ public interface IAssignable
|
||||
/// <see cref="true"/>, if the fields are unsigned successfully, <see cref="false"/> if not.
|
||||
/// </returns>
|
||||
bool Unassign();
|
||||
|
||||
delegate void OnUnassignedDelegate(IAssignable sender);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,7 +8,7 @@ public interface IAssignableBehaviourController : IAssignable
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="IBehaviourController"/> value has has been assigned a new value.
|
||||
/// </summary>
|
||||
Action<IAssignableBehaviourController>? OnBehaviourControllerAssigned { get; set; }
|
||||
event OnBehaviourControllerAssignedDelegate? OnBehaviourControllerAssigned;
|
||||
|
||||
/// <inheritdoc cref="IBehaviourController" />
|
||||
IBehaviourController BehaviourController { get; }
|
||||
@ -23,4 +21,6 @@ public interface IAssignableBehaviourController : IAssignable
|
||||
/// <see cref="true"/>, if the value given assigned successfully assigned, <see cref="false"/> if not.
|
||||
/// </returns>
|
||||
bool Assign(IBehaviourController behaviourController);
|
||||
|
||||
delegate void OnBehaviourControllerAssignedDelegate(IAssignableBehaviourController sender);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,7 +8,7 @@ public interface IAssignableEntity : IAssignable
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="IEntity"/> value has has been assigned a new value.
|
||||
/// </summary>
|
||||
Action<IAssignableEntity>? OnEntityAssigned { get; set; }
|
||||
event OnEntityAssignedDelegate? OnEntityAssigned;
|
||||
|
||||
/// <inheritdoc cref="IEntity" />
|
||||
IEntity Entity { get; }
|
||||
@ -23,4 +21,6 @@ public interface IAssignableEntity : IAssignable
|
||||
/// <see cref="true"/>, if the value given assigned successfully assigned, <see cref="false"/> if not.
|
||||
/// </returns>
|
||||
bool Assign(IEntity entity);
|
||||
|
||||
delegate void OnEntityAssignedDelegate(IAssignableEntity sender);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,7 +8,7 @@ public interface IAssignableGameManager : IAssignable
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="IGameManager"/> value has has been assigned a new value.
|
||||
/// </summary>
|
||||
Action<IAssignableGameManager>? OnGameManagerAssigned { get; set; }
|
||||
event OnGameManagerAssignedDelegate? OnGameManagerAssigned;
|
||||
|
||||
/// <inheritdoc cref="IGameManager" />
|
||||
IGameManager GameManager { get; }
|
||||
@ -23,4 +21,6 @@ public interface IAssignableGameManager : IAssignable
|
||||
/// <see cref="true"/>, if the value given assigned successfully assigned, <see cref="false"/> if not.
|
||||
/// </returns>
|
||||
bool Assign(IGameManager gameManager);
|
||||
|
||||
delegate void OnGameManagerAssignedDelegate(IAssignableGameManager sender);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,7 +8,7 @@ public interface IAssignableGameObject : IAssignable
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="IGameObject"/> value has has been assigned a new value.
|
||||
/// </summary>
|
||||
Action<IAssignableGameObject>? OnGameObjectAssigned { get; set; }
|
||||
event OnGameObjectAssignedDelegate? OnGameObjectAssigned;
|
||||
|
||||
/// <inheritdoc cref="IGameObject" />
|
||||
IGameObject GameObject { get; }
|
||||
@ -23,4 +21,6 @@ public interface IAssignableGameObject : IAssignable
|
||||
/// <see cref="true"/>, if the value given assigned successfully assigned, <see cref="false"/> if not.
|
||||
/// </returns>
|
||||
bool Assign(IGameObject gameObject);
|
||||
|
||||
delegate void OnGameObjectAssignedDelegate(IAssignableGameObject sender);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,7 +8,7 @@ public interface IAssignableStateEnable : IAssignable
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="IStateEnable"/> value has has been assigned a new value.
|
||||
/// </summary>
|
||||
Action<IAssignableStateEnable>? OnStateEnableAssigned { get; set; }
|
||||
event OnStateEnableAssignedDelegate? OnStateEnableAssigned;
|
||||
|
||||
/// <inheritdoc cref="IStateEnable" />
|
||||
IStateEnable StateEnable { get; }
|
||||
@ -23,4 +21,6 @@ public interface IAssignableStateEnable : IAssignable
|
||||
/// <see cref="true"/>, if the value given assigned successfully assigned, <see cref="false"/> if not.
|
||||
/// </returns>
|
||||
bool Assign(IStateEnable stateEnable);
|
||||
|
||||
delegate void OnStateEnableAssignedDelegate(IAssignableStateEnable sender);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,7 +8,7 @@ public interface IAssignableTransform : IAssignable
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="ITransform"/> value has has been assigned a new value.
|
||||
/// </summary>
|
||||
Action<IAssignableTransform>? OnTransformAssigned { get; set; }
|
||||
event OnTransformAssignedDelegate? OnTransformAssigned;
|
||||
|
||||
/// <inheritdoc cref="ITransform" />
|
||||
ITransform Transform { get; }
|
||||
@ -23,4 +21,6 @@ public interface IAssignableTransform : IAssignable
|
||||
/// <see cref="true"/>, if the value given assigned successfully assigned, <see cref="false"/> if not.
|
||||
/// </returns>
|
||||
bool Assign(ITransform transform);
|
||||
|
||||
delegate void OnTransformAssignedDelegate(IAssignableTransform sender);
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
public abstract class BaseEntity : IEntity
|
||||
{
|
||||
public Action<IEntity, string>? OnIdChanged { get; set; } = null;
|
||||
public event IEntity.OnIdChangedDelegate? OnIdChanged = null;
|
||||
|
||||
public Action<IAssignable>? OnUnassigned { get; set; } = null;
|
||||
public Action<IAssignableStateEnable>? OnStateEnableAssigned { get; set; } = null;
|
||||
public event IInitialize.OnInitializedDelegate? OnInitialized = null;
|
||||
public event IInitialize.OnFinalizedDelegate? OnFinalized = null;
|
||||
|
||||
public Action<IInitialize>? OnInitialized { get; set; } = null;
|
||||
public Action<IInitialize>? OnFinalized { get; set; } = null;
|
||||
public event IAssignableStateEnable.OnStateEnableAssignedDelegate? OnStateEnableAssigned = null;
|
||||
public event IAssignable.OnUnassignedDelegate? OnUnassigned = null;
|
||||
|
||||
|
||||
private IStateEnable _stateEnable = null!;
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,7 +8,7 @@ public interface IBehaviour : IEntity, IAssignableBehaviourController, IAssignab
|
||||
/// <summary>
|
||||
/// Event triggered when the priority of the <see cref="IBehaviour"/> changes.
|
||||
/// </summary>
|
||||
Action<IBehaviour>? OnPriorityChanged { get; set; }
|
||||
event OnPriorityChangedDelegate? OnPriorityChanged;
|
||||
|
||||
/// <summary>
|
||||
/// The priority of the <see cref="IBehaviour"/>.
|
||||
@ -21,4 +19,6 @@ public interface IBehaviour : IEntity, IAssignableBehaviourController, IAssignab
|
||||
/// The value indicating whether the <see cref="IBehaviour"/> is active.
|
||||
/// </summary>
|
||||
bool IsActive { get; }
|
||||
|
||||
delegate void OnPriorityChangedDelegate(IBehaviour sender, int previousPriority);
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
@ -12,27 +11,27 @@ public interface IBehaviourController : IAssignableGameObject, IEnumerable<IBeha
|
||||
/// <summary>
|
||||
/// Event triggered before the update of <see cref="IBehaviour"/>s.
|
||||
/// </summary>
|
||||
Action<IBehaviourController>? OnPreUpdate { get; set; }
|
||||
event OnPreUpdateDelegate? OnPreUpdate;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered during the update of <see cref="IBehaviour"/>s.
|
||||
/// </summary>
|
||||
Action<IBehaviourController>? OnUpdate { get; set; }
|
||||
event OnUpdateDelegate? OnUpdate;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered before the drawing phase.
|
||||
/// </summary>
|
||||
Action<IBehaviourController>? OnPreDraw { get; set; }
|
||||
event OnPreDrawDelegate? OnPreDraw;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when a <see cref="IBehaviour"/> is added to the <see cref="IBehaviourController"/>.
|
||||
/// </summary>
|
||||
Action<IBehaviourController, IBehaviour>? OnBehaviourAdded { get; set; }
|
||||
event OnBehaviourAddedDelegate? OnBehaviourAdded;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when a <see cref="IBehaviour"/> is removed from the <see cref="IBehaviourController"/>.
|
||||
/// </summary>
|
||||
Action<IBehaviourController, IBehaviour>? OnBehaviourRemoved { get; set; }
|
||||
event OnBehaviourRemovedDelegate? OnBehaviourRemoved;
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="IBehaviour"/> to the <see cref="IBehaviourController"/>.
|
||||
@ -102,4 +101,11 @@ public interface IBehaviourController : IAssignableGameObject, IEnumerable<IBeha
|
||||
/// Performs pre-draw operations.
|
||||
/// </summary>
|
||||
void UpdatePreDraw();
|
||||
|
||||
delegate void OnPreUpdateDelegate(IBehaviourController sender);
|
||||
delegate void OnUpdateDelegate(IBehaviourController sender);
|
||||
delegate void OnPreDrawDelegate(IBehaviourController sender);
|
||||
delegate void OnBehaviourAddedDelegate(IBehaviourController sender, IBehaviour behaviourAdded);
|
||||
delegate void OnBehaviourRemovedDelegate(IBehaviourController sender, IBehaviour behaviourRemoved);
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -11,10 +9,12 @@ public interface IEntity : IInitialize, IAssignableStateEnable
|
||||
/// Event triggered when the <see cref="Id"/> of the <see cref="IEntity"/> changes.
|
||||
/// The string action parameter is the previous <see cref="Id"/> of the <see cref="IEntity"/>.
|
||||
/// </summary>
|
||||
Action<IEntity, string>? OnIdChanged { get; set; }
|
||||
event OnIdChangedDelegate? OnIdChanged;
|
||||
|
||||
/// <summary>
|
||||
/// The ID of the <see cref="IEntity"/>.
|
||||
/// </summary>
|
||||
string Id { get; set; }
|
||||
|
||||
delegate void OnIdChangedDelegate(IEntity sender, string previousId);
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
@ -11,12 +10,12 @@ public interface IGameManager : IEntity, IEnumerable<IGameObject>
|
||||
/// <summary>
|
||||
/// Event triggered when a <see cref="IGameObject"/> is registered to the <see cref="IGameManager"/>.
|
||||
/// </summary>
|
||||
Action<IGameManager, IGameObject>? OnGameObjectRegistered { get; set; }
|
||||
event OnGameObjectRegisteredDelegate? OnGameObjectRegistered;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when a <see cref="IGameObject"/> is unregistered from the <see cref="IGameManager"/>.
|
||||
/// </summary>
|
||||
Action<IGameManager, IGameObject>? OnGameObjectUnRegistered { get; set; }
|
||||
event OnGameObjectUnRegisteredDelegate? OnGameObjectUnRegistered;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only list of <see cref="IGameObject"/>s managed by the <see cref="IGameManager"/>.
|
||||
@ -54,4 +53,7 @@ public interface IGameManager : IEntity, IEnumerable<IGameObject>
|
||||
/// Performs operations that should be done before the draw calls.
|
||||
/// </summary>
|
||||
void PreDraw();
|
||||
|
||||
delegate void OnGameObjectRegisteredDelegate(IGameManager sender, IGameObject gameObjectRegistered);
|
||||
delegate void OnGameObjectUnRegisteredDelegate(IGameManager sender, IGameObject gameObjectUnregistered);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,10 +8,12 @@ public interface IGameObject : IEntity, IAssignableGameManager, IAssignableTrans
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="Update"/> method is called.
|
||||
/// </summary>
|
||||
Action<IGameObject>? OnUpdated { get; set; }
|
||||
event OnUpdatedDelegate? OnUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// Updates the game object.
|
||||
/// </summary>
|
||||
void Update();
|
||||
|
||||
delegate void OnUpdatedDelegate(IGameObject sender);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,12 +8,12 @@ public interface IInitialize
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="Initialize"/> method is called successfully.
|
||||
/// </summary>
|
||||
Action<IInitialize>? OnInitialized { get; set; }
|
||||
event OnInitializedDelegate? OnInitialized;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="Finalize"/> method is called successfully.
|
||||
/// </summary>
|
||||
Action<IInitialize>? OnFinalized { get; set; }
|
||||
event OnFinalizedDelegate? OnFinalized;
|
||||
|
||||
/// <summary>
|
||||
/// The value indicating whether the entity has been initialized.
|
||||
@ -33,4 +31,7 @@ public interface IInitialize
|
||||
/// </summary>
|
||||
/// <returns><see cref="true"/> if finalization is successful, otherwise <see cref="false"/>.</returns>
|
||||
bool Finalize();
|
||||
|
||||
delegate void OnInitializedDelegate(IInitialize sender);
|
||||
delegate void OnFinalizedDelegate(IInitialize sender);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,10 +8,12 @@ public interface INameable
|
||||
/// <summary>
|
||||
/// Event triggered when the name of the entity changes.
|
||||
/// </summary>
|
||||
Action<IEntity>? OnNameChanged { get; set; }
|
||||
event OnNameChangedDelegate? OnNameChanged;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the entity.
|
||||
/// </summary>
|
||||
string Name { get; set; }
|
||||
|
||||
delegate void OnNameChangedDelegate(INameable sender, string previousName);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@ -10,10 +8,12 @@ public interface IStateEnable : IAssignableEntity
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="Enabled"/> state of the <see cref="IStateEnable"/> changes.
|
||||
/// </summary>
|
||||
Action<IStateEnable>? OnEnabledChanged { get; set; }
|
||||
event OnNameChangedDelegate? OnEnabledChanged;
|
||||
|
||||
/// <summary>
|
||||
/// The value indicating whether the <see cref="IStateEnable"/> is enabled.
|
||||
/// </summary>
|
||||
bool Enabled { get; set; }
|
||||
|
||||
delegate void OnNameChangedDelegate(IStateEnable sender, bool previousState);
|
||||
}
|
||||
|
@ -11,32 +11,32 @@ public interface ITransform : IAssignableGameObject, IEnumerable<ITransform>
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="Position"/> of the <see cref="ITransform"/> changes.
|
||||
/// </summary>
|
||||
Action<ITransform>? OnPositionChanged { get; set; }
|
||||
event OnPositionChangedDelegate? OnPositionChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="Scale"/> of the <see cref="ITransform"/> changes.
|
||||
/// </summary>
|
||||
Action<ITransform>? OnScaleChanged { get; set; }
|
||||
event OnScaleChangedDelegate? OnScaleChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="Rotation"/> of the <see cref="ITransform"/> changes.
|
||||
/// </summary>
|
||||
Action<ITransform>? OnRotationChanged { get; set; }
|
||||
event OnRotationChangedDelegate? OnRotationChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="Parent"/> of the <see cref="ITransform"/> changes. The second parameter is the old <see cref="ITransform"/>.
|
||||
/// </summary>
|
||||
Action<ITransform, ITransform?>? OnParentChanged { get; set; }
|
||||
event OnParentChangedDelegate? OnParentChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when a new <see cref="ITransform"/> is added to the <see cref="Children"/>.
|
||||
/// </summary>
|
||||
Action<ITransform, ITransform>? OnChildrenAdded { get; set; }
|
||||
event OnChildrenAddedDelegate? OnChildrenAdded;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when an <see cref="ITransform"/> is removed from the <see cref="Children"/>.
|
||||
/// </summary>
|
||||
Action<ITransform, ITransform>? OnChildrenRemoved { get; set; }
|
||||
event OnChildrenRemovedDelegate? OnChildrenRemoved;
|
||||
|
||||
/// <summary>
|
||||
/// The world position of the <see cref="ITransform"/> in 2D space.
|
||||
@ -95,4 +95,11 @@ public interface ITransform : IAssignableGameObject, IEnumerable<ITransform>
|
||||
/// </summary>
|
||||
/// <param name="transform">The child <see cref="ITransform"/> to remove.</param>
|
||||
void RemoveChild(ITransform transform);
|
||||
|
||||
delegate void OnPositionChangedDelegate(ITransform sender);
|
||||
delegate void OnScaleChangedDelegate(ITransform sender);
|
||||
delegate void OnRotationChangedDelegate(ITransform sender);
|
||||
delegate void OnParentChangedDelegate(ITransform sender, ITransform? newParent);
|
||||
delegate void OnChildrenAddedDelegate(ITransform sender, ITransform childrenAdded);
|
||||
delegate void OnChildrenRemovedDelegate(ITransform sender, ITransform childrenRemoved);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Core.Exceptions;
|
||||
|
||||
@ -8,15 +6,16 @@ namespace Syntriax.Engine.Core;
|
||||
[System.Diagnostics.DebuggerDisplay("{GetType().Name, nq}, Priority: {Priority}, Initialized: {Initialized}")]
|
||||
public abstract class Behaviour : BaseEntity, IBehaviour
|
||||
{
|
||||
public Action<IAssignableBehaviourController>? OnBehaviourControllerAssigned { get; set; } = null;
|
||||
public event IAssignableBehaviourController.OnBehaviourControllerAssignedDelegate? OnBehaviourControllerAssigned = null;
|
||||
|
||||
public Action<IBehaviour>? OnPriorityChanged { get; set; } = null;
|
||||
public event IBehaviour.OnPriorityChangedDelegate? OnPriorityChanged = null;
|
||||
|
||||
|
||||
private IBehaviourController _behaviourController = null!;
|
||||
|
||||
private int _priority = 0;
|
||||
|
||||
|
||||
public IBehaviourController BehaviourController => _behaviourController;
|
||||
|
||||
public override bool IsActive => base.IsActive && BehaviourController.GameObject.StateEnable.Enabled;
|
||||
@ -29,8 +28,9 @@ public abstract class Behaviour : BaseEntity, IBehaviour
|
||||
if (value == _priority)
|
||||
return;
|
||||
|
||||
int previousPriority = _priority;
|
||||
_priority = value;
|
||||
OnPriorityChanged?.Invoke(this);
|
||||
OnPriorityChanged?.Invoke(this, previousPriority);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,11 +8,11 @@ namespace Syntriax.Engine.Core;
|
||||
|
||||
public class BehaviourCollector<T> : IAssignableGameManager, IEnumerable<T>
|
||||
{
|
||||
public Action<IAssignable>? OnUnassigned { get; set; } = null;
|
||||
public Action<IAssignableGameManager>? OnGameManagerAssigned { get; set; } = null;
|
||||
public event IAssignable.OnUnassignedDelegate? OnUnassigned = null;
|
||||
public event IAssignableGameManager.OnGameManagerAssignedDelegate? OnGameManagerAssigned = null;
|
||||
|
||||
public Action<BehaviourCollector<T>, T>? OnCollected { get; set; } = null;
|
||||
public Action<BehaviourCollector<T>, T>? OnRemoved { get; set; } = null;
|
||||
public event OnCollectedDelegate? OnCollected = null;
|
||||
public event OnRemovedDelegate? OnRemoved = null;
|
||||
|
||||
private readonly List<T> _behaviours = new(32);
|
||||
|
||||
@ -99,4 +99,8 @@ public class BehaviourCollector<T> : IAssignableGameManager, IEnumerable<T>
|
||||
|
||||
public IEnumerator<T> GetEnumerator() => _behaviours.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => _behaviours.GetEnumerator();
|
||||
|
||||
|
||||
public delegate void OnCollectedDelegate(BehaviourCollector<T> sender, T behaviourCollected);
|
||||
public delegate void OnRemovedDelegate(BehaviourCollector<T> sender, T behaviourRemoved);
|
||||
}
|
||||
|
@ -11,14 +11,14 @@ namespace Syntriax.Engine.Core;
|
||||
[System.Diagnostics.DebuggerDisplay("Behaviour Count: {behaviours.Count}")]
|
||||
public class BehaviourController : IBehaviourController
|
||||
{
|
||||
public Action<IBehaviourController>? OnPreUpdate { get; set; }
|
||||
public Action<IBehaviourController>? OnUpdate { get; set; } = null;
|
||||
public Action<IBehaviourController>? OnPreDraw { get; set; } = null;
|
||||
public event IBehaviourController.OnPreUpdateDelegate? OnPreUpdate = null;
|
||||
public event IBehaviourController.OnUpdateDelegate? OnUpdate = null;
|
||||
public event IBehaviourController.OnPreDrawDelegate? OnPreDraw = null;
|
||||
|
||||
public Action<IBehaviourController, IBehaviour>? OnBehaviourAdded { get; set; } = null;
|
||||
public Action<IBehaviourController, IBehaviour>? OnBehaviourRemoved { get; set; } = null;
|
||||
public Action<IAssignable>? OnUnassigned { get; set; } = null;
|
||||
public Action<IAssignableGameObject>? OnGameObjectAssigned { get; set; } = null;
|
||||
public event IBehaviourController.OnBehaviourAddedDelegate? OnBehaviourAdded = null;
|
||||
public event IBehaviourController.OnBehaviourRemovedDelegate? OnBehaviourRemoved = null;
|
||||
public event IAssignable.OnUnassignedDelegate? OnUnassigned;
|
||||
public event IAssignableGameObject.OnGameObjectAssignedDelegate? OnGameObjectAssigned = null;
|
||||
|
||||
|
||||
private readonly IList<IBehaviour> behaviours = new List<IBehaviour>(Constants.BEHAVIOURS_SIZE_INITIAL);
|
||||
@ -165,10 +165,11 @@ public class BehaviourController : IBehaviourController
|
||||
behaviours.Add(behaviour);
|
||||
}
|
||||
|
||||
private void OnPriorityChange(IBehaviour behaviour)
|
||||
|
||||
private void OnPriorityChange(IBehaviour sender, int previousPriority)
|
||||
{
|
||||
behaviours.Remove(behaviour);
|
||||
InsertBehaviourByPriority(behaviour);
|
||||
behaviours.Remove(sender);
|
||||
InsertBehaviourByPriority(sender);
|
||||
}
|
||||
|
||||
public IEnumerator<IBehaviour> GetEnumerator() => behaviours.GetEnumerator();
|
||||
|
@ -11,8 +11,8 @@ namespace Syntriax.Engine.Core;
|
||||
[System.Diagnostics.DebuggerDisplay("GameObject Count: {_gameObjects.Count}")]
|
||||
public class GameManager : BaseEntity, IGameManager
|
||||
{
|
||||
public Action<IGameManager, IGameObject>? OnGameObjectRegistered { get; set; } = null;
|
||||
public Action<IGameManager, IGameObject>? OnGameObjectUnRegistered { get; set; } = null;
|
||||
public event IGameManager.OnGameObjectRegisteredDelegate? OnGameObjectRegistered = null;
|
||||
public event IGameManager.OnGameObjectUnRegisteredDelegate? OnGameObjectUnRegistered = null;
|
||||
|
||||
|
||||
private readonly List<IGameObject> _gameObjects = new(Constants.GAME_OBJECTS_SIZE_INITIAL);
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Core.Exceptions;
|
||||
|
||||
@ -8,13 +6,13 @@ namespace Syntriax.Engine.Core;
|
||||
[System.Diagnostics.DebuggerDisplay("Name: {Name}, Initialized: {Initialized}")]
|
||||
public class GameObject : BaseEntity, IGameObject
|
||||
{
|
||||
public Action<IAssignableTransform>? OnTransformAssigned { get; set; } = null;
|
||||
public Action<IAssignableBehaviourController>? OnBehaviourControllerAssigned { get; set; } = null;
|
||||
public Action<IAssignableGameManager>? OnGameManagerAssigned { get; set; } = null;
|
||||
public event IAssignableTransform.OnTransformAssignedDelegate? OnTransformAssigned = null;
|
||||
public event IAssignableGameManager.OnGameManagerAssignedDelegate? OnGameManagerAssigned = null;
|
||||
public event IAssignableBehaviourController.OnBehaviourControllerAssignedDelegate? OnBehaviourControllerAssigned = null;
|
||||
|
||||
public Action<IEntity>? OnNameChanged { get; set; } = null;
|
||||
public event INameable.OnNameChangedDelegate? OnNameChanged = null;
|
||||
|
||||
public Action<IGameObject>? OnUpdated { get; set; } = null;
|
||||
public event IGameObject.OnUpdatedDelegate? OnUpdated = null;
|
||||
|
||||
|
||||
private ITransform _transform = null!;
|
||||
@ -35,8 +33,9 @@ public class GameObject : BaseEntity, IGameObject
|
||||
{
|
||||
if (value == _name) return;
|
||||
|
||||
string previousName = _name;
|
||||
_name = value;
|
||||
OnNameChanged?.Invoke(this);
|
||||
OnNameChanged?.Invoke(this, previousName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,6 +106,7 @@ public class GameObject : BaseEntity, IGameObject
|
||||
}
|
||||
|
||||
public GameObject() { OnBehaviourControllerAssigned += ConnectBehaviourController; }
|
||||
|
||||
private void ConnectBehaviourController(IAssignableBehaviourController controller)
|
||||
{
|
||||
controller.BehaviourController.OnBehaviourAdded += OnBehaviourAdded;
|
||||
|
@ -1,14 +1,12 @@
|
||||
using System;
|
||||
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public class StateEnable : IStateEnable
|
||||
{
|
||||
public Action<IAssignable>? OnUnassigned { get; set; } = null;
|
||||
public Action<IAssignableEntity>? OnEntityAssigned { get; set; } = null;
|
||||
public Action<IStateEnable>? OnEnabledChanged { get; set; } = null;
|
||||
public event IAssignable.OnUnassignedDelegate? OnUnassigned = null;
|
||||
public event IAssignableEntity.OnEntityAssignedDelegate? OnEntityAssigned = null;
|
||||
public event IStateEnable.OnNameChangedDelegate? OnEnabledChanged = null;
|
||||
|
||||
private bool _enabled = true;
|
||||
private IEntity _entity = null!;
|
||||
@ -23,8 +21,9 @@ public class StateEnable : IStateEnable
|
||||
if (value == _enabled)
|
||||
return;
|
||||
|
||||
bool previousState = _enabled;
|
||||
_enabled = value;
|
||||
OnEnabledChanged?.Invoke(this);
|
||||
OnEnabledChanged?.Invoke(this, previousState);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@ -9,17 +8,17 @@ namespace Syntriax.Engine.Core;
|
||||
[System.Diagnostics.DebuggerDisplay("Name: {GameObject.Name, nq} Position: {Position.ToString(), nq}, Scale: {Scale.ToString(), nq}, Rotation: {Rotation}")]
|
||||
public class Transform : ITransform
|
||||
{
|
||||
public Action<IAssignableGameObject>? OnGameObjectAssigned { get; set; } = null;
|
||||
public event IAssignableGameObject.OnGameObjectAssignedDelegate? OnGameObjectAssigned = null;
|
||||
|
||||
public Action<IAssignable>? OnUnassigned { get; set; } = null;
|
||||
public event IAssignable.OnUnassignedDelegate? OnUnassigned = null;
|
||||
|
||||
public Action<ITransform>? OnPositionChanged { get; set; } = null;
|
||||
public Action<ITransform>? OnScaleChanged { get; set; } = null;
|
||||
public Action<ITransform>? OnRotationChanged { get; set; } = null;
|
||||
public event ITransform.OnPositionChangedDelegate? OnPositionChanged = null;
|
||||
public event ITransform.OnScaleChangedDelegate? OnScaleChanged = null;
|
||||
public event ITransform.OnRotationChangedDelegate? OnRotationChanged = null;
|
||||
|
||||
public Action<ITransform, ITransform?>? OnParentChanged { get; set; } = null;
|
||||
public Action<ITransform, ITransform>? OnChildrenAdded { get; set; } = null;
|
||||
public Action<ITransform, ITransform>? OnChildrenRemoved { get; set; } = null;
|
||||
public event ITransform.OnParentChangedDelegate? OnParentChanged = null;
|
||||
public event ITransform.OnChildrenAddedDelegate? OnChildrenAdded = null;
|
||||
public event ITransform.OnChildrenRemovedDelegate? OnChildrenRemoved = null;
|
||||
|
||||
|
||||
private Vector2D _position = Vector2D.Zero;
|
||||
@ -180,8 +179,8 @@ public class Transform : ITransform
|
||||
{
|
||||
// TODO No idea how logical this is to propagate this to the children the way I'm doing right now.
|
||||
// I was originally gonna just call `child.OnParentChanged?.Invoke(child, child.Parent);` but seems an unnecessary call too?
|
||||
foreach (var child in Children)
|
||||
child.OnParentChanged?.Invoke(transform, previousParent);
|
||||
foreach (var child in Children) // TODO CHECK ERRORS
|
||||
child.SetParent(this);
|
||||
}
|
||||
|
||||
private void RecalculatePosition(ITransform _)
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D.Abstract;
|
||||
@ -12,17 +10,17 @@ public interface ICollider2D : IBehaviour, IAssignableTransform
|
||||
/// <summary>
|
||||
/// Event triggered when a collision is detected.
|
||||
/// </summary>
|
||||
Action<ICollider2D, CollisionDetectionInformation>? OnCollisionDetected { get; set; }
|
||||
event OnCollisionDetectedDelegate? OnCollisionDetected;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when a collision is resolved.
|
||||
/// </summary>
|
||||
Action<ICollider2D, CollisionDetectionInformation>? OnCollisionResolved { get; set; }
|
||||
event OnCollisionResolvedDelegate? OnCollisionResolved;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when another <see cref="ICollider2D"/> triggers this <see cref="ICollider2D"/>.
|
||||
/// </summary>
|
||||
Action<ICollider2D, ICollider2D>? OnTriggered { get; set; }
|
||||
event OnTriggeredDelegate? OnTriggered;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IRigidBody2D"/> associated with the <see cref="ICollider2D"/>.
|
||||
@ -38,4 +36,12 @@ public interface ICollider2D : IBehaviour, IAssignableTransform
|
||||
/// Recalculates <see cref="ICollider2D"/> properties.
|
||||
/// </summary>
|
||||
void Recalculate();
|
||||
|
||||
void Detect(CollisionDetectionInformation collisionDetectionInformation);
|
||||
void Resolve(CollisionDetectionInformation collisionDetectionInformation);
|
||||
void Trigger(ICollider2D initiator);
|
||||
|
||||
delegate void OnCollisionDetectedDelegate(ICollider2D sender, CollisionDetectionInformation collisionDetectionInformation);
|
||||
delegate void OnCollisionResolvedDelegate(ICollider2D sender, CollisionDetectionInformation collisionDetectionInformation);
|
||||
delegate void OnTriggeredDelegate(ICollider2D sender, ICollider2D initiatorCollider);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Physics2D.Abstract;
|
||||
@ -8,9 +6,9 @@ namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public abstract class Collider2DBehaviourBase : BehaviourOverride, ICollider2D
|
||||
{
|
||||
public Action<ICollider2D, CollisionDetectionInformation>? OnCollisionDetected { get; set; } = null;
|
||||
public Action<ICollider2D, CollisionDetectionInformation>? OnCollisionResolved { get; set; } = null;
|
||||
public Action<ICollider2D, ICollider2D>? OnTriggered { get; set; } = null;
|
||||
public event ICollider2D.OnCollisionDetectedDelegate? OnCollisionDetected = null;
|
||||
public event ICollider2D.OnCollisionResolvedDelegate? OnCollisionResolved = null;
|
||||
public event ICollider2D.OnTriggeredDelegate? OnTriggered = null;
|
||||
|
||||
|
||||
protected bool NeedsRecalculation { get; private set; } = true;
|
||||
@ -20,7 +18,7 @@ public abstract class Collider2DBehaviourBase : BehaviourOverride, ICollider2D
|
||||
public bool IsTrigger { get; set; } = false;
|
||||
|
||||
ITransform IAssignableTransform.Transform => Transform;
|
||||
Action<IAssignableTransform>? IAssignableTransform.OnTransformAssigned { get => GameObject.OnTransformAssigned; set => GameObject.OnTransformAssigned = value; }
|
||||
public event IAssignableTransform.OnTransformAssignedDelegate? OnTransformAssigned { add => GameObject.OnTransformAssigned += value; remove => GameObject.OnTransformAssigned -= value; }
|
||||
|
||||
bool IAssignableTransform.Assign(ITransform transform) => GameObject.Assign(transform);
|
||||
|
||||
@ -76,4 +74,8 @@ public abstract class Collider2DBehaviourBase : BehaviourOverride, ICollider2D
|
||||
Transform.OnPositionChanged -= SetNeedsRecalculation;
|
||||
Transform.OnRotationChanged -= SetNeedsRecalculation;
|
||||
}
|
||||
|
||||
public void Detect(CollisionDetectionInformation collisionDetectionInformation) => OnCollisionDetected?.Invoke(this, collisionDetectionInformation);
|
||||
public void Resolve(CollisionDetectionInformation collisionDetectionInformation) => OnCollisionResolved?.Invoke(this, collisionDetectionInformation);
|
||||
public void Trigger(ICollider2D initiator) => OnTriggered?.Invoke(this, initiator);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class CollisionResolver2D : ICollisionResolver2D
|
||||
left.Recalculate();
|
||||
right.Recalculate();
|
||||
|
||||
left.OnCollisionResolved?.Invoke(collisionInformation.Left, collisionInformation);
|
||||
right.OnCollisionResolved?.Invoke(right, collisionInformation);
|
||||
left.Resolve(collisionInformation);
|
||||
right.Resolve(collisionInformation);
|
||||
}
|
||||
}
|
||||
|
@ -80,17 +80,17 @@ public class PhysicsEngine2D : IPhysicsEngine2D
|
||||
{
|
||||
if (colliderX.IsTrigger)
|
||||
{
|
||||
colliderX.OnTriggered?.Invoke(colliderX, colliderY);
|
||||
colliderX.Trigger(colliderY);
|
||||
continue;
|
||||
}
|
||||
else if (colliderY.IsTrigger)
|
||||
{
|
||||
colliderY.OnTriggered?.Invoke(colliderY, colliderY);
|
||||
colliderY.Trigger(colliderY);
|
||||
continue;
|
||||
}
|
||||
|
||||
colliderX.OnCollisionDetected?.Invoke(colliderX, information);
|
||||
colliderY.OnCollisionDetected?.Invoke(colliderY, information);
|
||||
colliderX.Detect(information);
|
||||
colliderY.Detect(information);
|
||||
|
||||
collisionResolver?.Resolve(information);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Physics2D.Abstract;
|
||||
@ -8,8 +6,8 @@ namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public class PhysicsEngine2DCollector : IPhysicsEngine2D, IAssignableGameManager
|
||||
{
|
||||
public Action<IAssignable>? OnUnassigned { get; set; } = null;
|
||||
public Action<IAssignableGameManager>? OnGameManagerAssigned { get; set; } = null;
|
||||
public event IAssignable.OnUnassignedDelegate? OnUnassigned = null;
|
||||
public event IAssignableGameManager.OnGameManagerAssignedDelegate? OnGameManagerAssigned = null;
|
||||
|
||||
|
||||
private int _iterationPerStep = 1;
|
||||
@ -67,17 +65,17 @@ public class PhysicsEngine2DCollector : IPhysicsEngine2D, IAssignableGameManager
|
||||
{
|
||||
if (colliderX.IsTrigger)
|
||||
{
|
||||
colliderX.OnTriggered?.Invoke(colliderX, colliderY);
|
||||
colliderX.Trigger(colliderY);
|
||||
continue;
|
||||
}
|
||||
else if (colliderY.IsTrigger)
|
||||
{
|
||||
colliderY.OnTriggered?.Invoke(colliderY, colliderY);
|
||||
colliderY.Trigger(colliderY);
|
||||
continue;
|
||||
}
|
||||
|
||||
colliderX.OnCollisionDetected?.Invoke(colliderX, information);
|
||||
colliderY.OnCollisionDetected?.Invoke(colliderY, information);
|
||||
colliderX.Detect(information);
|
||||
colliderY.Detect(information);
|
||||
|
||||
collisionResolver?.Resolve(information);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Physics2D.Abstract;
|
||||
@ -8,7 +6,7 @@ namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public class RigidBody2D : BehaviourOverride, IRigidBody2D
|
||||
{
|
||||
public Action<IAssignableTransform>? OnTransformAssigned { get => GameObject.OnTransformAssigned; set => GameObject.OnTransformAssigned = value; }
|
||||
event IAssignableTransform.OnTransformAssignedDelegate? IAssignableTransform.OnTransformAssigned { add => GameObject.OnTransformAssigned += value; remove => GameObject.OnTransformAssigned -= value; }
|
||||
|
||||
private const float LOWEST_ALLOWED_MASS = 0.00001f;
|
||||
private float _mass = 1f;
|
||||
|
Loading…
x
Reference in New Issue
Block a user