|
@@ -7,7 +7,7 @@ namespace ET
|
|
|
{
|
|
{
|
|
|
using OneTypeSystems = UnOrderMultiMap<Type, object>;
|
|
using OneTypeSystems = UnOrderMultiMap<Type, object>;
|
|
|
|
|
|
|
|
- public class EventSystem: Singleton<EventSystem>
|
|
|
|
|
|
|
+ public class EventSystem: Singleton<EventSystem>, ISingletonUpdate, ISingletonLateUpdate
|
|
|
{
|
|
{
|
|
|
private class TypeSystems
|
|
private class TypeSystems
|
|
|
{
|
|
{
|
|
@@ -64,17 +64,6 @@ namespace ET
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private class TwoQueue
|
|
|
|
|
- {
|
|
|
|
|
- public Queue<long> Queue1 = new();
|
|
|
|
|
- public Queue<long> Queue2 = new();
|
|
|
|
|
-
|
|
|
|
|
- public void Swap()
|
|
|
|
|
- {
|
|
|
|
|
- (this.Queue1, this.Queue2) = (this.Queue2, this.Queue1);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
private readonly Dictionary<long, Entity> allEntities = new();
|
|
private readonly Dictionary<long, Entity> allEntities = new();
|
|
|
|
|
|
|
|
private readonly Dictionary<string, Type> allTypes = new();
|
|
private readonly Dictionary<string, Type> allTypes = new();
|
|
@@ -87,9 +76,9 @@ namespace ET
|
|
|
|
|
|
|
|
private TypeSystems typeSystems = new();
|
|
private TypeSystems typeSystems = new();
|
|
|
|
|
|
|
|
- private readonly TwoQueue[] twoQueues = new TwoQueue[(int)TwoQueueEnum.Max];
|
|
|
|
|
|
|
+ private readonly Queue<long>[] queues = new Queue<long>[(int)QueueEnum.Max];
|
|
|
|
|
|
|
|
- private enum TwoQueueEnum
|
|
|
|
|
|
|
+ private enum QueueEnum
|
|
|
{
|
|
{
|
|
|
Update = 0,
|
|
Update = 0,
|
|
|
LateUpdate = 1,
|
|
LateUpdate = 1,
|
|
@@ -99,9 +88,9 @@ namespace ET
|
|
|
|
|
|
|
|
public EventSystem()
|
|
public EventSystem()
|
|
|
{
|
|
{
|
|
|
- for (int i = 0; i < this.twoQueues.Length; i++)
|
|
|
|
|
|
|
+ for (int i = 0; i < this.queues.Length; i++)
|
|
|
{
|
|
{
|
|
|
- this.twoQueues[i] = new TwoQueue();
|
|
|
|
|
|
|
+ this.queues[i] = new Queue<long>();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -263,27 +252,26 @@ namespace ET
|
|
|
{
|
|
{
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if (component is ILoad)
|
|
if (component is ILoad)
|
|
|
{
|
|
{
|
|
|
if (oneTypeSystems.ContainsKey(typeof (ILoadSystem)))
|
|
if (oneTypeSystems.ContainsKey(typeof (ILoadSystem)))
|
|
|
{
|
|
{
|
|
|
- this.twoQueues[(int)TwoQueueEnum.Load].Queue1.Enqueue(component.InstanceId);
|
|
|
|
|
|
|
+ this.queues[(int)QueueEnum.Load].Enqueue(component.InstanceId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
if (component is IUpdate)
|
|
if (component is IUpdate)
|
|
|
{
|
|
{
|
|
|
if (oneTypeSystems.ContainsKey(typeof (IUpdateSystem)))
|
|
if (oneTypeSystems.ContainsKey(typeof (IUpdateSystem)))
|
|
|
{
|
|
{
|
|
|
- this.twoQueues[(int)TwoQueueEnum.Update].Queue1.Enqueue(component.InstanceId);
|
|
|
|
|
|
|
+ this.queues[(int)QueueEnum.Update].Enqueue(component.InstanceId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
if (component is ILateUpdate)
|
|
if (component is ILateUpdate)
|
|
|
{
|
|
{
|
|
|
if (oneTypeSystems.ContainsKey(typeof (ILateUpdateSystem)))
|
|
if (oneTypeSystems.ContainsKey(typeof (ILateUpdateSystem)))
|
|
|
{
|
|
{
|
|
|
- this.twoQueues[(int)TwoQueueEnum.LateUpdate].Queue1.Enqueue(component.InstanceId);
|
|
|
|
|
|
|
+ this.queues[(int)QueueEnum.LateUpdate].Enqueue(component.InstanceId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -517,10 +505,11 @@ namespace ET
|
|
|
|
|
|
|
|
public void Load()
|
|
public void Load()
|
|
|
{
|
|
{
|
|
|
- TwoQueue twoQueue = this.twoQueues[(int)TwoQueueEnum.Load];
|
|
|
|
|
- while (twoQueue.Queue1.Count > 0)
|
|
|
|
|
|
|
+ Queue<long> queue = this.queues[(int)QueueEnum.Load];
|
|
|
|
|
+ int count = queue.Count;
|
|
|
|
|
+ while (count-- > 0)
|
|
|
{
|
|
{
|
|
|
- long instanceId = twoQueue.Queue1.Dequeue();
|
|
|
|
|
|
|
+ long instanceId = queue.Dequeue();
|
|
|
Entity component;
|
|
Entity component;
|
|
|
if (!this.allEntities.TryGetValue(instanceId, out component))
|
|
if (!this.allEntities.TryGetValue(instanceId, out component))
|
|
|
{
|
|
{
|
|
@@ -538,7 +527,7 @@ namespace ET
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- twoQueue.Queue2.Enqueue(instanceId);
|
|
|
|
|
|
|
+ queue.Enqueue(instanceId);
|
|
|
|
|
|
|
|
foreach (ILoadSystem iLoadSystem in iLoadSystems)
|
|
foreach (ILoadSystem iLoadSystem in iLoadSystems)
|
|
|
{
|
|
{
|
|
@@ -552,8 +541,6 @@ namespace ET
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- twoQueue.Swap();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void Destroy(Entity component)
|
|
public void Destroy(Entity component)
|
|
@@ -584,10 +571,11 @@ namespace ET
|
|
|
|
|
|
|
|
public void Update()
|
|
public void Update()
|
|
|
{
|
|
{
|
|
|
- TwoQueue twoQueue = this.twoQueues[(int)TwoQueueEnum.Update];
|
|
|
|
|
- while (twoQueue.Queue1.Count > 0)
|
|
|
|
|
|
|
+ Queue<long> queue = this.queues[(int)QueueEnum.Update];
|
|
|
|
|
+ int count = queue.Count;
|
|
|
|
|
+ while (count-- > 0)
|
|
|
{
|
|
{
|
|
|
- long instanceId = twoQueue.Queue1.Dequeue();
|
|
|
|
|
|
|
+ long instanceId = queue.Dequeue();
|
|
|
Entity component;
|
|
Entity component;
|
|
|
if (!this.allEntities.TryGetValue(instanceId, out component))
|
|
if (!this.allEntities.TryGetValue(instanceId, out component))
|
|
|
{
|
|
{
|
|
@@ -605,7 +593,7 @@ namespace ET
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- twoQueue.Queue2.Enqueue(instanceId);
|
|
|
|
|
|
|
+ queue.Enqueue(instanceId);
|
|
|
|
|
|
|
|
foreach (IUpdateSystem iUpdateSystem in iUpdateSystems)
|
|
foreach (IUpdateSystem iUpdateSystem in iUpdateSystems)
|
|
|
{
|
|
{
|
|
@@ -619,16 +607,15 @@ namespace ET
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- twoQueue.Swap();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void LateUpdate()
|
|
public void LateUpdate()
|
|
|
{
|
|
{
|
|
|
- TwoQueue twoQueue = this.twoQueues[(int)TwoQueueEnum.LateUpdate];
|
|
|
|
|
- while (twoQueue.Queue1.Count > 0)
|
|
|
|
|
|
|
+ Queue<long> queue = this.queues[(int)QueueEnum.LateUpdate];
|
|
|
|
|
+ int count = queue.Count;
|
|
|
|
|
+ while (count-- > 0)
|
|
|
{
|
|
{
|
|
|
- long instanceId = twoQueue.Queue1.Dequeue();
|
|
|
|
|
|
|
+ long instanceId = queue.Dequeue();
|
|
|
Entity component;
|
|
Entity component;
|
|
|
if (!this.allEntities.TryGetValue(instanceId, out component))
|
|
if (!this.allEntities.TryGetValue(instanceId, out component))
|
|
|
{
|
|
{
|
|
@@ -646,7 +633,7 @@ namespace ET
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- twoQueue.Queue2.Enqueue(instanceId);
|
|
|
|
|
|
|
+ queue.Enqueue(instanceId);
|
|
|
|
|
|
|
|
foreach (ILateUpdateSystem iLateUpdateSystem in iLateUpdateSystems)
|
|
foreach (ILateUpdateSystem iLateUpdateSystem in iLateUpdateSystems)
|
|
|
{
|
|
{
|
|
@@ -660,8 +647,6 @@ namespace ET
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- twoQueue.Swap();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public async ETTask PublishAsync<T>(Scene scene, T a) where T : struct
|
|
public async ETTask PublishAsync<T>(Scene scene, T a) where T : struct
|