refactor: got rid of the static Time class and implemented EngineTime on IGameManager
This commit is contained in:
parent
82705ba378
commit
b73c9ed0ae
@ -8,7 +8,7 @@ namespace Syntriax.Engine.Core.Abstract;
|
||||
public interface IGameManager : IEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Event triggered when <see cref="Update(EngineTime)"/> is called on the <see cref="IGameManager"/>.
|
||||
/// Event triggered when <see cref="Update(double)"/> is called on the <see cref="IGameManager"/>.
|
||||
/// </summary>
|
||||
event UpdateEventHandler? OnUpdate;
|
||||
|
||||
@ -27,6 +27,11 @@ public interface IGameManager : IEntity
|
||||
/// </summary>
|
||||
event HierarchyObjectUnRegisteredEventHandler? OnHierarchyObjectUnRegistered;
|
||||
|
||||
/// <summary>
|
||||
/// Contains time data related to this <see cref="IGameManager"/>.
|
||||
/// </summary>
|
||||
EngineTime Time { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only list of <see cref="IHierarchyObject"/>s managed by the <see cref="IGameManager"/>.
|
||||
/// </summary>
|
||||
@ -53,17 +58,17 @@ public interface IGameManager : IEntity
|
||||
void Remove(IHierarchyObject hierarchyObject);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the <see cref="IGameManager"/> with the given engine time data.
|
||||
/// Updates the <see cref="IGameManager"/> with the given delta time.
|
||||
/// </summary>
|
||||
/// <param name="time">The engine time.</param>
|
||||
void Update(EngineTime time);
|
||||
/// <param name="engineTime">Delta time.</param>
|
||||
void Update(EngineTime engineTime);
|
||||
|
||||
/// <summary>
|
||||
/// Performs operations that should be done before the draw calls.
|
||||
/// </summary>
|
||||
void PreDraw();
|
||||
|
||||
delegate void UpdateEventHandler(IGameManager sender, EngineTime time);
|
||||
delegate void UpdateEventHandler(IGameManager sender, EngineTime engineTime);
|
||||
delegate void PreDawEventHandler(IGameManager sender);
|
||||
|
||||
delegate void HierarchyObjectRegisteredEventHandler(IGameManager sender, IHierarchyObject hierarchyObjectRegistered);
|
||||
|
@ -2,10 +2,10 @@ using System;
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public readonly struct EngineTime(TimeSpan Total, TimeSpan Elapsed)
|
||||
public readonly struct EngineTime(TimeSpan TimeSinceStart, TimeSpan TimeDelta)
|
||||
{
|
||||
public readonly TimeSpan Total = Total;
|
||||
public readonly TimeSpan Elapsed = Elapsed;
|
||||
public readonly TimeSpan TimeSinceStart = TimeSinceStart;
|
||||
public readonly TimeSpan DeltaSpan = TimeDelta;
|
||||
|
||||
public readonly float DeltaTimeFrame = (float)Elapsed.TotalMilliseconds * .001f;
|
||||
public readonly float DeltaTime = (float)TimeDelta.TotalSeconds;
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ public class GameManager : BaseEntity, IGameManager
|
||||
private readonly List<IHierarchyObject> _hierarchyObjects = new(Constants.GAME_OBJECTS_SIZE_INITIAL);
|
||||
|
||||
private HierarchyObjectFactory _hierarchyObjectFactory = null!;
|
||||
|
||||
private HierarchyObjectFactory HierarchyObjectFactory
|
||||
{
|
||||
get
|
||||
@ -46,6 +45,8 @@ public class GameManager : BaseEntity, IGameManager
|
||||
}
|
||||
}
|
||||
|
||||
public EngineTime Time { get; private set; } = new();
|
||||
|
||||
public void Register(IHierarchyObject hierarchyObject)
|
||||
{
|
||||
if (_hierarchyObjects.Contains(hierarchyObject))
|
||||
@ -113,13 +114,14 @@ public class GameManager : BaseEntity, IGameManager
|
||||
HierarchyObjects[i].Finalize();
|
||||
}
|
||||
|
||||
public void Update(EngineTime time)
|
||||
public void Update(EngineTime engineTime)
|
||||
{
|
||||
Time.SetTime(time);
|
||||
Time = engineTime;
|
||||
|
||||
for (int i = 0; i < HierarchyObjects.Count; i++)
|
||||
HierarchyObjects[i].BehaviourController.Update();
|
||||
|
||||
OnUpdate?.Invoke(this, time);
|
||||
OnUpdate?.Invoke(this, engineTime);
|
||||
}
|
||||
|
||||
public void PreDraw()
|
||||
@ -130,8 +132,6 @@ public class GameManager : BaseEntity, IGameManager
|
||||
OnPreDraw?.Invoke(this);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
private void OnHierarchyObjectFinalize(IInitializable initializable)
|
||||
{
|
||||
if (initializable is IHierarchyObject hierarchyObject)
|
||||
|
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public static class Time
|
||||
{
|
||||
private static EngineTime _engineTime = new(TimeSpan.Zero, TimeSpan.Zero);
|
||||
|
||||
public static TimeSpan Total => _engineTime.Total;
|
||||
public static TimeSpan Elapsed => _engineTime.Elapsed;
|
||||
|
||||
public static float DeltaTimeFrame => _engineTime.DeltaTimeFrame;
|
||||
|
||||
public static void SetTime(EngineTime engineTime) => _engineTime = engineTime;
|
||||
}
|
@ -51,7 +51,7 @@ public class PhysicsCoroutineManager : HierarchyObject
|
||||
gameManager.OnUpdate -= OnUpdate;
|
||||
}
|
||||
|
||||
private void OnUpdate(IGameManager sender, EngineTime time)
|
||||
private void OnUpdate(IGameManager sender, EngineTime engineTime)
|
||||
{
|
||||
if (GameManager is not IGameManager gameManager)
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user