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