41 lines
814 B
C#
41 lines
814 B
C#
using Syntriax.Engine.Core;
|
|
|
|
namespace Syntriax.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 OnFinalize()
|
|
{
|
|
base.OnFinalize();
|
|
|
|
TickCounter = 0;
|
|
nextTick = 0f;
|
|
}
|
|
}
|