feat: time systems added
This commit is contained in:
38
Engine.Systems/Time/TickerBehaviour.cs
Normal file
38
Engine.Systems/Time/TickerBehaviour.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user