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.
41 lines
808 B
C#
41 lines
808 B
C#
using Engine.Core;
|
|
|
|
namespace Engine.Systems.Time;
|
|
|
|
public class TickerTimer : Timer, ITicker
|
|
{
|
|
public Event<ITicker> OnTick { get; } = new();
|
|
|
|
public double Period { get; set; } = 1f;
|
|
public int TickCounter { get; private set; } = 0;
|
|
|
|
private double nextTick = double.MinValue;
|
|
|
|
public override void Start(double time)
|
|
{
|
|
TickCounter = 0;
|
|
base.Start(time);
|
|
nextTick = Remaining - Period;
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
base.Update();
|
|
|
|
while (Remaining <= nextTick)
|
|
{
|
|
nextTick -= Period;
|
|
TickCounter++;
|
|
OnTick?.Invoke(this);
|
|
}
|
|
}
|
|
|
|
protected override void FinalizeInternal()
|
|
{
|
|
base.FinalizeInternal();
|
|
|
|
TickCounter = 0;
|
|
nextTick = 0f;
|
|
}
|
|
}
|