浏览代码

update coroutine.

/main
kg 6 年前
当前提交
b28e39de
共有 4 个文件被更改,包括 17 次插入65 次删除
  1. 43
      Runtime/async/coroutine.cs
  2. 23
      Runtime/async/timer.cs
  3. 14
      Runtime/editor/editor_window.cs
  4. 2
      Runtime/ui/window.cs

43
Runtime/async/coroutine.cs


if (isBackground && BackgroundCallbacks.getInstance() != null) {
this._unhook = BackgroundCallbacks.getInstance().addCallback(this._moveNext);
} else {
this._unhook = this._window.onUpdate(this._moveNext);
this._unhook = this._window.run(TimeSpan.Zero, this._moveNext, periodic: true);
}
this._isBackground = isBackground;

public UIWidgetsWaitForSeconds(float time) {
this.waitTime = time;
}
}
internal class WindowCallbacks {
readonly LinkedList<VoidCallback> _callbackList;
readonly Window _window;
public WindowCallbacks() {
this._callbackList = new LinkedList<VoidCallback>();
}
public void update() {
var callbackList = this._callbackList.ToArray();
foreach (var callback in callbackList) {
try {
callback();
}
catch (Exception ex) {
Debug.LogError("Failed to execute callback in WindowCallbacks: " + ex);
}
}
}
public IDisposable onUpdate(VoidCallback callback) {
var node = this._callbackList.AddLast(callback);
return new _CallbackDisposable(this, node);
}
class _CallbackDisposable : IDisposable {
readonly WindowCallbacks _parent;
readonly LinkedListNode<VoidCallback> _node;
public _CallbackDisposable(WindowCallbacks parent, LinkedListNode<VoidCallback> node) {
this._parent = parent;
this._node = node;
}
public void Dispose() {
this._parent._callbackList.Remove(this._node);
}
}
}

23
Runtime/async/timer.cs


#endif
namespace Unity.UIWidgets.async {
public abstract class Timer {
public abstract class Timer : IDisposable {
public void Dispose() {
this.cancel();
}
public static double timeSinceStartup {
get {
#if UNITY_EDITOR

}
public class TimerProvider {
private readonly PriorityQueue<TimerImpl> _queue;
readonly PriorityQueue<TimerImpl> _queue;
public TimerProvider() {
this._queue = new PriorityQueue<TimerImpl>();

return timer;
}
public void update() {
public void update(Action flushMicroTasks = null) {
var now = Timer.timeSinceStartup;
List<TimerImpl> timers = null;

if (timers != null) {
foreach (var timer in timers) {
if (flushMicroTasks != null) {
flushMicroTasks();
}
timer.invoke();
if (timer.periodic && !timer.done) {
if (appendList == null) {

}
if (appendList != null) {
lock (this._queue) {
foreach (var timer in appendList) {
this._queue.enqueue(timer);
}
foreach (var timer in appendList) {
this._queue.enqueue(timer);
private class TimerImpl : Timer, IComparable<TimerImpl> {
public readonly bool periodic;

14
Runtime/editor/editor_window.cs


readonly TimeSpan _epoch = new TimeSpan(Stopwatch.GetTimestamp());
readonly MicrotaskQueue _microtaskQueue = new MicrotaskQueue();
readonly TimerProvider _timerProvider = new TimerProvider();
readonly WindowCallbacks _windowCallbacks = new WindowCallbacks();
readonly TextInput _textInput = new TextInput();
readonly Rasterizer _rasterizer = new Rasterizer();

Timer.update();
using (this.getScope()) {
this._doUpdate();
this._timerProvider.update(this.flushMicrotasks);
this.flushMicrotasks();
}
void _doUpdate() {
this.flushMicrotasks();
this._windowCallbacks.update();
this._timerProvider.update();
}
public override void scheduleFrame(bool regenerateLayerTree = true) {

return periodic
? this._timerProvider.periodic(duration, callback)
: this._timerProvider.run(duration, callback);
}
public override IDisposable onUpdate(VoidCallback callback) {
return this._windowCallbacks.onUpdate(callback);
}
public void attachRootRenderBox(RenderBox root) {

2
Runtime/ui/window.cs


return this.run(TimeSpan.Zero, callback);
}
public abstract IDisposable onUpdate(VoidCallback callback);
public abstract TextInput textInput { get; }
public abstract IDisposable getScope();

正在加载...
取消
保存