using GFramework.Core.Abstractions.Coroutine;
namespace GFramework.Godot.Coroutine;
///
/// Godot时间源实现,用于提供基于Godot引擎的时间信息
///
/// 获取增量时间的函数委托
public class GodotTimeSource(Func getDeltaFunc) : ITimeSource
{
private readonly Func _getDeltaFunc = getDeltaFunc ?? throw new ArgumentNullException(nameof(getDeltaFunc));
///
/// 获取当前累计时间
///
public double CurrentTime { get; private set; }
///
/// 获取上一帧的时间增量
///
public double DeltaTime { get; private set; }
///
/// 更新时间源,计算新的增量时间和累计时间
///
public void Update()
{
// 调用外部提供的函数获取当前帧的时间增量
DeltaTime = _getDeltaFunc();
// 累加到总时间中
CurrentTime += DeltaTime;
}
///
/// 重置时间源到初始状态
///
public void Reset()
{
CurrentTime = 0;
DeltaTime = 0;
}
}