调度器
概述
QfStudio.Godette.ReactiveUI 提供三个调度器,将 Godot 的帧循环桥接到 Rx 调度模型:
| 调度器 | 别名 | 来源 | 用途 |
|---|---|---|---|
GodotMainThreadScheduler | RxSchedulers.MainThreadScheduler | SynchronizationContext | 主线程回调 |
GodotSchedulers.ProcessFrameScheduler | — | _Process | 每帧调度 |
GodotSchedulers.PhysicsFrameScheduler | — | _PhysicsProcess | 物理帧调度 |
Autoload 中的初始化
将下面两个帧调度器作为字段创建,并传给 RxAppBootstrapper 中的 WithGodot——它会基于 SynchronizationContext.Current 创建主线程调度器,并通过 GodotSchedulers 暴露全部三个调度器:
csharp
private readonly GodotFrameScheduler _processFrameScheduler = new();
private readonly GodotFrameScheduler _physicsFrameScheduler = new();
RxAppBuilder.CreateReactiveUIBuilder()
.WithGodot(_processFrameScheduler, _physicsFrameScheduler)
// .WithGodotConverters() // 可选
// .WithGodotViewLocator(...) // 可选
.BuildApp();RxAppBuilder.BuildApp() 会将 .WithMainThreadScheduler(...)(由 WithGodot 内部调用)注册的调度器镜像到 RxSchedulers.MainThreadScheduler,因此 ObserveOn(RxSchedulers.MainThreadScheduler) 解析到同一个 GodotMainThreadScheduler。
帧驱动
csharp
public override void _Process(double delta)
{
_processFrameScheduler.NotifyProcess(delta);
}
public override void _PhysicsProcess(double delta)
{
_physicsFrameScheduler.NotifyProcess(delta);
}每帧调用 NotifyProcess 推动帧调度器执行排队的操作。GodotSchedulers 是这些相同实例在 Godot 侧的别名,供帧运算符和其他 Godot 专用 API 使用。