|
@@ -1,75 +1,70 @@
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
-using System.Threading;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
namespace ET
|
|
|
{
|
|
{
|
|
|
- public class Process: IDisposable
|
|
|
|
|
|
|
+ public class VProcess: IDisposable
|
|
|
{
|
|
{
|
|
|
public int Id { get; private set; }
|
|
public int Id { get; private set; }
|
|
|
|
|
|
|
|
public bool IsRuning;
|
|
public bool IsRuning;
|
|
|
|
|
|
|
|
- public ISingletonScheduler Scheduler;
|
|
|
|
|
-
|
|
|
|
|
- public Process(int id)
|
|
|
|
|
|
|
+ public VProcess(int id)
|
|
|
{
|
|
{
|
|
|
this.Id = id;
|
|
this.Id = id;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private readonly Stack<IProcessSingleton> singletons = new();
|
|
|
|
|
|
|
+ private readonly Stack<IVProcessSingleton> singletons = new();
|
|
|
|
|
|
|
|
- private readonly Queue<IProcessSingleton> updates = new();
|
|
|
|
|
|
|
+ private readonly Queue<IVProcessSingleton> updates = new();
|
|
|
|
|
|
|
|
- private readonly Queue<IProcessSingleton> lateUpdates = new();
|
|
|
|
|
|
|
+ private readonly Queue<IVProcessSingleton> lateUpdates = new();
|
|
|
|
|
|
|
|
- private readonly Queue<IProcessSingleton> loads = new();
|
|
|
|
|
|
|
+ private readonly Queue<IVProcessSingleton> loads = new();
|
|
|
|
|
|
|
|
private readonly Queue<ETTask> frameFinishTask = new();
|
|
private readonly Queue<ETTask> frameFinishTask = new();
|
|
|
-
|
|
|
|
|
- private ThreadSynchronizationContext ThreadSynchronizationContext = new();
|
|
|
|
|
|
|
|
|
|
private void Register()
|
|
private void Register()
|
|
|
{
|
|
{
|
|
|
this.IsRuning = true;
|
|
this.IsRuning = true;
|
|
|
|
|
|
|
|
- foreach (IProcessSingleton singleton in this.singletons)
|
|
|
|
|
|
|
+ foreach (IVProcessSingleton singleton in this.singletons)
|
|
|
{
|
|
{
|
|
|
singleton.Register();
|
|
singleton.Register();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public T AddSingleton<T>() where T: ProcessSingleton<T>, new()
|
|
|
|
|
|
|
+ public T AddSingleton<T>() where T: VProcessSingleton<T>, new()
|
|
|
{
|
|
{
|
|
|
T singleton = new T();
|
|
T singleton = new T();
|
|
|
AddSingleton(singleton);
|
|
AddSingleton(singleton);
|
|
|
return singleton;
|
|
return singleton;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void AddSingleton(IProcessSingleton singleton)
|
|
|
|
|
|
|
+ public void AddSingleton(IVProcessSingleton singleton)
|
|
|
{
|
|
{
|
|
|
- singleton.Process = this;
|
|
|
|
|
|
|
+ singleton.VProcess = this;
|
|
|
|
|
|
|
|
singleton.Register();
|
|
singleton.Register();
|
|
|
|
|
|
|
|
singletons.Push(singleton);
|
|
singletons.Push(singleton);
|
|
|
|
|
|
|
|
- if (singleton is IProcessSingletonAwake awake)
|
|
|
|
|
|
|
+ if (singleton is IVProcessSingletonAwake awake)
|
|
|
{
|
|
{
|
|
|
awake.Awake();
|
|
awake.Awake();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (singleton is IProcessSingletonUpdate)
|
|
|
|
|
|
|
+ if (singleton is IVProcessSingletonUpdate)
|
|
|
{
|
|
{
|
|
|
updates.Enqueue(singleton);
|
|
updates.Enqueue(singleton);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (singleton is IProcessSingletonLateUpdate)
|
|
|
|
|
|
|
+ if (singleton is IVProcessSingletonLateUpdate)
|
|
|
{
|
|
{
|
|
|
lateUpdates.Enqueue(singleton);
|
|
lateUpdates.Enqueue(singleton);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (singleton is IProcessSingletonLoad)
|
|
|
|
|
|
|
+ if (singleton is IVProcessSingletonLoad)
|
|
|
{
|
|
{
|
|
|
loads.Enqueue(singleton);
|
|
loads.Enqueue(singleton);
|
|
|
}
|
|
}
|
|
@@ -84,17 +79,19 @@ namespace ET
|
|
|
|
|
|
|
|
public void Update()
|
|
public void Update()
|
|
|
{
|
|
{
|
|
|
|
|
+ this.Register();
|
|
|
|
|
+
|
|
|
int count = updates.Count;
|
|
int count = updates.Count;
|
|
|
while (count-- > 0)
|
|
while (count-- > 0)
|
|
|
{
|
|
{
|
|
|
- IProcessSingleton singleton = updates.Dequeue();
|
|
|
|
|
|
|
+ IVProcessSingleton singleton = updates.Dequeue();
|
|
|
|
|
|
|
|
if (singleton.IsDisposed())
|
|
if (singleton.IsDisposed())
|
|
|
{
|
|
{
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (singleton is not IProcessSingletonUpdate update)
|
|
|
|
|
|
|
+ if (singleton is not IVProcessSingletonUpdate update)
|
|
|
{
|
|
{
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -113,17 +110,19 @@ namespace ET
|
|
|
|
|
|
|
|
public void LateUpdate()
|
|
public void LateUpdate()
|
|
|
{
|
|
{
|
|
|
|
|
+ this.Register();
|
|
|
|
|
+
|
|
|
int count = lateUpdates.Count;
|
|
int count = lateUpdates.Count;
|
|
|
while (count-- > 0)
|
|
while (count-- > 0)
|
|
|
{
|
|
{
|
|
|
- IProcessSingleton singleton = lateUpdates.Dequeue();
|
|
|
|
|
|
|
+ IVProcessSingleton singleton = lateUpdates.Dequeue();
|
|
|
|
|
|
|
|
if (singleton.IsDisposed())
|
|
if (singleton.IsDisposed())
|
|
|
{
|
|
{
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (singleton is not IProcessSingletonLateUpdate lateUpdate)
|
|
|
|
|
|
|
+ if (singleton is not IVProcessSingletonLateUpdate lateUpdate)
|
|
|
{
|
|
{
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -140,27 +139,21 @@ namespace ET
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void LoopOnce()
|
|
|
|
|
- {
|
|
|
|
|
- this.Register();
|
|
|
|
|
- this.Update();
|
|
|
|
|
- this.LateUpdate();
|
|
|
|
|
- this.FrameFinishUpdate();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public void Load()
|
|
public void Load()
|
|
|
{
|
|
{
|
|
|
|
|
+ this.Register();
|
|
|
|
|
+
|
|
|
int count = loads.Count;
|
|
int count = loads.Count;
|
|
|
while (count-- > 0)
|
|
while (count-- > 0)
|
|
|
{
|
|
{
|
|
|
- IProcessSingleton singleton = loads.Dequeue();
|
|
|
|
|
|
|
+ IVProcessSingleton singleton = loads.Dequeue();
|
|
|
|
|
|
|
|
if (singleton.IsDisposed())
|
|
if (singleton.IsDisposed())
|
|
|
{
|
|
{
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (singleton is not IProcessSingletonLoad load)
|
|
|
|
|
|
|
+ if (singleton is not IVProcessSingletonLoad load)
|
|
|
{
|
|
{
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -179,6 +172,8 @@ namespace ET
|
|
|
|
|
|
|
|
public void FrameFinishUpdate()
|
|
public void FrameFinishUpdate()
|
|
|
{
|
|
{
|
|
|
|
|
+ this.Register();
|
|
|
|
|
+
|
|
|
while (frameFinishTask.Count > 0)
|
|
while (frameFinishTask.Count > 0)
|
|
|
{
|
|
{
|
|
|
ETTask task = frameFinishTask.Dequeue();
|
|
ETTask task = frameFinishTask.Dequeue();
|
|
@@ -204,7 +199,7 @@ namespace ET
|
|
|
// 顺序反过来清理
|
|
// 顺序反过来清理
|
|
|
while (singletons.Count > 0)
|
|
while (singletons.Count > 0)
|
|
|
{
|
|
{
|
|
|
- IProcessSingleton iSingleton = singletons.Pop();
|
|
|
|
|
|
|
+ IVProcessSingleton iSingleton = singletons.Pop();
|
|
|
iSingleton.Destroy();
|
|
iSingleton.Destroy();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|