GeWuYou ddbf7af572 feat(coroutine): 添加完整的协程系统实现
- 实现了协程调度器和句柄管理机制
- 添加了多种等待指令包括延时、帧数、条件等待等
- 创建了协程辅助方法和扩展功能
- 集成了Godot引擎的时间源和生命周期管理
- 实现了协程的暂停、恢复、终止等控制功能
- 添加了协程标签管理和按标签批量操作功能
- 提供了与Godot节点生命周期绑定的取消机制
2026-01-21 20:34:10 +08:00

44 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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