|
|
@@ -13,10 +13,11 @@ namespace ET
|
|
|
{
|
|
|
CoroutineLockComponent.Instance = self;
|
|
|
|
|
|
- self.list = new List<CoroutineLockQueueType>(CoroutineLockType.Max);
|
|
|
+ self.list.Clear();
|
|
|
+
|
|
|
for (int i = 0; i < CoroutineLockType.Max; ++i)
|
|
|
{
|
|
|
- CoroutineLockQueueType coroutineLockQueueType = self.AddChildWithId<CoroutineLockQueueType>(++self.idGenerator);
|
|
|
+ CoroutineLockQueueType coroutineLockQueueType = self.AddChildWithId<CoroutineLockQueueType>(i);
|
|
|
self.list.Add(coroutineLockQueueType);
|
|
|
}
|
|
|
}
|
|
|
@@ -68,7 +69,7 @@ namespace ET
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- foreach (KeyValuePair<long, List<CoroutineLockTimer>> kv in self.timers)
|
|
|
+ foreach (KeyValuePair<long, List<long>> kv in self.timers)
|
|
|
{
|
|
|
long k = kv.Key;
|
|
|
if (k > timeNow)
|
|
|
@@ -88,8 +89,7 @@ namespace ET
|
|
|
var list = self.timers[time];
|
|
|
for (int i = 0; i < list.Count; ++i)
|
|
|
{
|
|
|
- CoroutineLockTimer coroutineLockTimer = list[i];
|
|
|
- self.timerOutTimer.Enqueue(coroutineLockTimer);
|
|
|
+ self.timerOutTimer.Enqueue(list[i]);
|
|
|
}
|
|
|
|
|
|
self.timers.Remove(time);
|
|
|
@@ -97,13 +97,14 @@ namespace ET
|
|
|
|
|
|
while (self.timerOutTimer.Count > 0)
|
|
|
{
|
|
|
- CoroutineLockTimer coroutineLockTimer = self.timerOutTimer.Dequeue();
|
|
|
- if (coroutineLockTimer.CoroutineLockInstanceId != coroutineLockTimer.CoroutineLock.InstanceId)
|
|
|
+ long CoroutineLockInstanceId = self.timerOutTimer.Dequeue();
|
|
|
+ CoroutineLock coroutineLock = Game.EventSystem.Get(CoroutineLockInstanceId) as CoroutineLock;
|
|
|
+
|
|
|
+ if (coroutineLock == null)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- CoroutineLock coroutineLock = coroutineLockTimer.CoroutineLock;
|
|
|
+
|
|
|
// 超时直接调用下一个锁
|
|
|
self.RunNextCoroutine(coroutineLock.coroutineLockType, coroutineLock.key, coroutineLock.level + 1);
|
|
|
coroutineLock.coroutineLockType = CoroutineLockType.None; // 上面调用了下一个, dispose不再调用
|
|
|
@@ -123,7 +124,7 @@ namespace ET
|
|
|
|
|
|
private static void AddTimer(this CoroutineLockComponent self, long tillTime, CoroutineLock coroutineLock)
|
|
|
{
|
|
|
- self.timers.Add(tillTime, new CoroutineLockTimer(coroutineLock));
|
|
|
+ self.timers.Add(tillTime, coroutineLock.InstanceId);
|
|
|
if (tillTime < self.minTime)
|
|
|
{
|
|
|
self.minTime = tillTime;
|
|
|
@@ -133,20 +134,22 @@ namespace ET
|
|
|
public static async ETTask<CoroutineLock> Wait(this CoroutineLockComponent self, int coroutineLockType, long key, int time = 60000)
|
|
|
{
|
|
|
CoroutineLockQueueType coroutineLockQueueType = self.list[coroutineLockType];
|
|
|
-
|
|
|
- if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
|
|
|
+
|
|
|
+ CoroutineLockQueue queue = coroutineLockQueueType.GetChild<CoroutineLockQueue>(key);
|
|
|
+
|
|
|
+ if (queue == null)
|
|
|
{
|
|
|
- coroutineLockQueueType.Add(key, self.AddChildWithId<CoroutineLockQueue>(++self.idGenerator, true));
|
|
|
- return self.CreateCoroutineLock(coroutineLockType, key, time, 1);
|
|
|
+ CoroutineLockQueue coroutineLockQueue = coroutineLockQueueType.AddChildWithId<CoroutineLockQueue>(key, true);
|
|
|
+ return self.CreateCoroutineLock(coroutineLockQueue, coroutineLockType, key, time, 1);
|
|
|
}
|
|
|
ETTask<CoroutineLock> tcs = ETTask<CoroutineLock>.Create(true);
|
|
|
queue.Add(tcs, time);
|
|
|
return await tcs;
|
|
|
}
|
|
|
|
|
|
- private static CoroutineLock CreateCoroutineLock(this CoroutineLockComponent self, int coroutineLockType, long key, int time, int level)
|
|
|
+ private static CoroutineLock CreateCoroutineLock(this CoroutineLockComponent self, CoroutineLockQueue coroutineLockQueue, int coroutineLockType, long key, int time, int level)
|
|
|
{
|
|
|
- CoroutineLock coroutineLock = self.AddChildWithId<CoroutineLock, int, long, int>(++self.idGenerator, coroutineLockType, key, level, true);
|
|
|
+ CoroutineLock coroutineLock = coroutineLockQueue.AddChildWithId<CoroutineLock, int, long, int>(++self.idGenerator, coroutineLockType, key, level, true);
|
|
|
if (time > 0)
|
|
|
{
|
|
|
self.AddTimer(TimeHelper.ClientFrameTime() + time, coroutineLock);
|
|
|
@@ -157,32 +160,35 @@ namespace ET
|
|
|
private static void Notify(this CoroutineLockComponent self, int coroutineLockType, long key, int level)
|
|
|
{
|
|
|
CoroutineLockQueueType coroutineLockQueueType = self.list[coroutineLockType];
|
|
|
- if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
|
|
|
+
|
|
|
+ CoroutineLockQueue queue = coroutineLockQueueType.GetChild<CoroutineLockQueue>(key);
|
|
|
+ if (queue == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (queue.Count == 0)
|
|
|
{
|
|
|
- coroutineLockQueueType.Remove(key);
|
|
|
+ coroutineLockQueueType.RemoveChild(key);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
CoroutineLockInfo coroutineLockInfo = queue.Dequeue();
|
|
|
- coroutineLockInfo.Tcs.SetResult(self.CreateCoroutineLock(coroutineLockType, key, coroutineLockInfo.Time, level));
|
|
|
+ coroutineLockInfo.Tcs.SetResult(self.CreateCoroutineLock(queue, coroutineLockType, key, coroutineLockInfo.Time, level));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
[ComponentOf(typeof(Scene))]
|
|
|
+ [ChildType(typeof(CoroutineLockQueueType))]
|
|
|
public class CoroutineLockComponent: Entity, IAwake, IUpdate, IDestroy
|
|
|
{
|
|
|
public static CoroutineLockComponent Instance;
|
|
|
|
|
|
- public List<CoroutineLockQueueType> list;
|
|
|
+ public List<CoroutineLockQueueType> list = new List<CoroutineLockQueueType>(CoroutineLockType.Max);
|
|
|
public Queue<(int, long, int)> nextFrameRun = new Queue<(int, long, int)>();
|
|
|
- public MultiMap<long, CoroutineLockTimer> timers = new MultiMap<long, CoroutineLockTimer>();
|
|
|
+ public MultiMap<long, long> timers = new MultiMap<long, long>();
|
|
|
public Queue<long> timeOutIds = new Queue<long>();
|
|
|
- public Queue<CoroutineLockTimer> timerOutTimer = new Queue<CoroutineLockTimer>();
|
|
|
+ public Queue<long> timerOutTimer = new Queue<long>();
|
|
|
public long idGenerator;
|
|
|
public long minTime;
|
|
|
}
|