feat: time systems added

This commit is contained in:
2025-03-30 20:29:26 +03:00
parent b73c9ed0ae
commit 7a1dd7eb1a
10 changed files with 346 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
namespace Syntriax.Engine.Systems.Time;
public class TickerBehaviour : StopwatchBehaviour, ITicker
{
public event ITicker.TickerTickEventHandler? OnTick = null;
public double TickPeriod { get; set; } = 1f;
public int TickCounter { get; private set; } = 0;
private double nextTick = 0f;
public override void StopwatchStart()
{
TickCounter = 0;
base.StopwatchStart();
nextTick = Time + TickPeriod;
}
protected override void OnUpdate()
{
base.OnUpdate();
if (Time < nextTick)
return;
nextTick += TickPeriod;
TickCounter++;
OnTick?.Invoke(this);
}
protected override void OnFinalize()
{
base.OnFinalize();
TickCounter = 0;
nextTick = 0f;
}
}