feat: IGameManager Events

This commit is contained in:
Syntriax 2024-10-25 23:10:20 +03:00
parent 91aa26e15a
commit 9c2b098821
2 changed files with 20 additions and 0 deletions

View File

@ -7,6 +7,16 @@ namespace Syntriax.Engine.Core.Abstract;
/// </summary> /// </summary>
public interface IGameManager : IEntity, IEnumerable<IGameObject> public interface IGameManager : IEntity, IEnumerable<IGameObject>
{ {
/// <summary>
/// Event triggered when <see cref="Update(EngineTime)"/> is called on the <see cref="IGameManager"/>.
/// </summary>
event OnUpdateDelegate? OnUpdate;
/// <summary>
/// Event triggered when <see cref="PreDraw"/> is called on the <see cref="IGameManager"/>.
/// </summary>
event OnPreDawDelegate? OnPreDraw;
/// <summary> /// <summary>
/// Event triggered when a <see cref="IGameObject"/> is registered to the <see cref="IGameManager"/>. /// Event triggered when a <see cref="IGameObject"/> is registered to the <see cref="IGameManager"/>.
/// </summary> /// </summary>
@ -69,6 +79,9 @@ public interface IGameManager : IEntity, IEnumerable<IGameObject>
/// </summary> /// </summary>
void PreDraw(); void PreDraw();
delegate void OnUpdateDelegate(IGameManager sender, EngineTime time);
delegate void OnPreDawDelegate(IGameManager sender);
delegate void OnGameObjectRegisteredDelegate(IGameManager sender, IGameObject gameObjectRegistered); delegate void OnGameObjectRegisteredDelegate(IGameManager sender, IGameObject gameObjectRegistered);
delegate void OnGameObjectUnRegisteredDelegate(IGameManager sender, IGameObject gameObjectUnregistered); delegate void OnGameObjectUnRegisteredDelegate(IGameManager sender, IGameObject gameObjectUnregistered);
delegate void OnHierarchyObjectRegisteredDelegate(IGameManager sender, IHierarchyObject hierarchyObjectRegistered); delegate void OnHierarchyObjectRegisteredDelegate(IGameManager sender, IHierarchyObject hierarchyObjectRegistered);

View File

@ -11,6 +11,9 @@ namespace Syntriax.Engine.Core;
[System.Diagnostics.DebuggerDisplay("GameObject Count: {_gameObjects.Count}")] [System.Diagnostics.DebuggerDisplay("GameObject Count: {_gameObjects.Count}")]
public class GameManager : BaseEntity, IGameManager public class GameManager : BaseEntity, IGameManager
{ {
public event IGameManager.OnUpdateDelegate? OnUpdate = null;
public event IGameManager.OnPreDawDelegate? OnPreDraw = null;
public event IGameManager.OnGameObjectRegisteredDelegate? OnGameObjectRegistered = null; public event IGameManager.OnGameObjectRegisteredDelegate? OnGameObjectRegistered = null;
public event IGameManager.OnGameObjectUnRegisteredDelegate? OnGameObjectUnRegistered = null; public event IGameManager.OnGameObjectUnRegisteredDelegate? OnGameObjectUnRegistered = null;
public event IGameManager.OnHierarchyObjectRegisteredDelegate? OnHierarchyObjectRegistered = null; public event IGameManager.OnHierarchyObjectRegisteredDelegate? OnHierarchyObjectRegistered = null;
@ -94,12 +97,16 @@ public class GameManager : BaseEntity, IGameManager
Time.SetTime(time); Time.SetTime(time);
for (int i = 0; i < GameObjects.Count; i++) for (int i = 0; i < GameObjects.Count; i++)
GameObjects[i].BehaviourController.Update(); GameObjects[i].BehaviourController.Update();
OnUpdate?.Invoke(this, time);
} }
public void PreDraw() public void PreDraw()
{ {
for (int i = 0; i < GameObjects.Count; i++) for (int i = 0; i < GameObjects.Count; i++)
GameObjects[i].BehaviourController.UpdatePreDraw(); GameObjects[i].BehaviourController.UpdatePreDraw();
OnPreDraw?.Invoke(this);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////