feat: ticker is decoupled from stopwatch and added timer and stopwatch tickers

This commit is contained in:
2025-07-25 23:24:08 +03:00
parent ad365dc722
commit df06e8d134
4 changed files with 45 additions and 5 deletions

View File

@@ -0,0 +1,40 @@
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;
}
}