Skip to content

Commit 204cecd

Browse files
committed
开始改协程锁提交一个版本
1 parent 2cda89b commit 204cecd

54 files changed

Lines changed: 270 additions & 23 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Assets/BundleMaster/BundleMasterRuntime/Base/LoadBaseRuntimeLoad.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ internal async ETTask LoadAssetBundleAsync(ETTask tcs, string bundlePackageName)
110110
tcs.SetResult();
111111
return;
112112
}
113+
114+
115+
string path = AssetComponent.BundleFileExistPath(bundlePackageName, AssetBundleName, true);
116+
CoroutineLock coroutineLock = await CoroutineLockComponent.Wait(CoroutineLockType.BundleMaster, LoadPathConvertHelper.LoadPathConvert(path));
117+
118+
coroutineLock.Dispose();
119+
120+
113121
if (_loadState == LoadState.Loading)
114122
{
115123
_loadFinishTasks.Add(tcs);

Assets/BundleMaster/CoroutineLock/CoroutineLock.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@ namespace BM
55
{
66
public class CoroutineLock : IDisposable
77
{
8-
private bool isDispose = false;
8+
private bool _isDispose = false;
99
internal long Key;
1010
private CoroutineLockQueue _coroutineLockQueue;
11-
private ETTask waitTask;
11+
private ETTask _waitTask;
1212

1313
internal void Init(long key, CoroutineLockQueue coroutineLockQueue)
1414
{
15-
isDispose = false;
15+
_isDispose = false;
1616
this.Key = key;
1717
this._coroutineLockQueue = coroutineLockQueue;
18-
waitTask = ETTask.Create(true);
18+
_waitTask = ETTask.Create(true);
1919
}
2020

2121
internal void Enable()
2222
{
23-
waitTask.SetResult();
23+
_waitTask.SetResult();
2424
}
2525

2626
internal ETTask Wait()
2727
{
28-
return waitTask;
28+
return _waitTask;
2929
}
3030

3131

3232
public void Dispose()
3333
{
34-
if (isDispose)
34+
if (_isDispose)
3535
{
3636
//Debug.LogError("协程锁重复释放");
3737
return;
3838
}
39-
waitTask = null;
40-
isDispose = true;
39+
_waitTask = null;
40+
_isDispose = true;
4141
_coroutineLockQueue.CoroutineLockDispose(this);
4242
_coroutineLockQueue = null;
4343
CoroutineLockComponent.CoroutineLockQueue.Enqueue(this);

Assets/BundleMaster/CoroutineLock/CoroutineLockComponent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class CoroutineLockComponent
88
/// <summary>
99
/// 协程锁类型以及对应的协程锁队列
1010
/// </summary>
11-
private static readonly Dictionary<int, CoroutineLockQueue> CoroutineLockTypeToQueue = new Dictionary<int, CoroutineLockQueue>();
11+
private static readonly Dictionary<CoroutineLockType, CoroutineLockQueue> CoroutineLockTypeToQueue = new Dictionary<CoroutineLockType, CoroutineLockQueue>();
1212

1313
/// <summary>
1414
/// 没有用到的CoroutineLock池
@@ -20,7 +20,7 @@ public static class CoroutineLockComponent
2020
/// </summary>
2121
internal static readonly Queue<Queue<CoroutineLock>> CoroutineLockQueuePool = new Queue<Queue<CoroutineLock>>();
2222

23-
public static async ETTask<CoroutineLock> Wait(int coroutineLockType, long key)
23+
public static async ETTask<CoroutineLock> Wait(CoroutineLockType coroutineLockType, long key)
2424
{
2525
if (!CoroutineLockTypeToQueue.TryGetValue(coroutineLockType, out CoroutineLockQueue coroutineLockQueue))
2626
{

Assets/BundleMaster/CoroutineLock/CoroutineLockQueue.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ namespace BM
44
{
55
internal class CoroutineLockQueue
66
{
7-
private int coroutineLockType;
8-
private readonly Dictionary<long, Queue<CoroutineLock>> coroutineLockKeyToQueue = new Dictionary<long, Queue<CoroutineLock>>();
7+
private CoroutineLockType _coroutineLockType;
8+
private readonly Dictionary<long, Queue<CoroutineLock>> _coroutineLockKeyToQueue = new Dictionary<long, Queue<CoroutineLock>>();
99

10-
internal CoroutineLockQueue(int coroutineLockType)
10+
internal CoroutineLockQueue(CoroutineLockType coroutineLockType)
1111
{
12-
this.coroutineLockType = coroutineLockType;
12+
this._coroutineLockType = coroutineLockType;
1313
}
1414

1515
internal void CoroutineLockDispose(CoroutineLock coroutineLock)
1616
{
17-
Queue<CoroutineLock> keyToQueue = coroutineLockKeyToQueue[coroutineLock.Key];
17+
Queue<CoroutineLock> keyToQueue = _coroutineLockKeyToQueue[coroutineLock.Key];
1818
if (keyToQueue.Count > 0)
1919
{
2020
CoroutineLock nextCoroutineLock = keyToQueue.Dequeue();
@@ -23,7 +23,7 @@ internal void CoroutineLockDispose(CoroutineLock coroutineLock)
2323
}
2424
keyToQueue.Clear();
2525
CoroutineLockComponent.CoroutineLockQueuePool.Enqueue(keyToQueue);
26-
coroutineLockKeyToQueue.Remove(coroutineLock.Key);
26+
_coroutineLockKeyToQueue.Remove(coroutineLock.Key);
2727
}
2828

2929
internal CoroutineLock GetCoroutineLock(long key)
@@ -38,7 +38,7 @@ internal CoroutineLock GetCoroutineLock(long key)
3838
coroutineLock = new CoroutineLock();
3939
}
4040
coroutineLock.Init(key, this);
41-
if (!coroutineLockKeyToQueue.ContainsKey(key))
41+
if (!_coroutineLockKeyToQueue.ContainsKey(key))
4242
{
4343
Queue<CoroutineLock> coroutineLockQueue;
4444
if (CoroutineLockComponent.CoroutineLockQueuePool.Count > 0)
@@ -49,12 +49,12 @@ internal CoroutineLock GetCoroutineLock(long key)
4949
{
5050
coroutineLockQueue = new Queue<CoroutineLock>();
5151
}
52-
coroutineLockKeyToQueue.Add(key, coroutineLockQueue);
52+
_coroutineLockKeyToQueue.Add(key, coroutineLockQueue);
5353
coroutineLock.Enable();
5454
}
5555
else
5656
{
57-
coroutineLockKeyToQueue[key].Enqueue(coroutineLock);
57+
_coroutineLockKeyToQueue[key].Enqueue(coroutineLock);
5858
}
5959
return coroutineLock;
6060
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
namespace BM
22
{
3-
public static class CoroutineLockType
3+
public enum CoroutineLockType
44
{
5-
public const int BundleMaster = 0;
5+
BundleMaster = 0,
6+
67
}
78
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Collections.Generic;
2+
3+
namespace BM
4+
{
5+
/// <summary>
6+
/// 负责将加载路径转化为唯一的long key
7+
/// </summary>
8+
public class LoadPathConvertHelper
9+
{
10+
/// <summary>
11+
/// 初始值
12+
/// </summary>
13+
private static long _originKey = 0;
14+
15+
private static readonly Dictionary<string, long> LoadPathToKey = new Dictionary<string, long>();
16+
17+
public static long LoadPathConvert(string loadPath)
18+
{
19+
if (LoadPathToKey.TryGetValue(loadPath, out long key))
20+
{
21+
return key;
22+
}
23+
_originKey++;
24+
key = _originKey;
25+
LoadPathToKey.Add(loadPath, key);
26+
return key;
27+
}
28+
}
29+
}

Assets/BundleMaster/CoroutineLock/LoadPathConvertHelper.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Resources/BMConfig.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ MonoBehaviour:
1212
m_Script: {fileID: 11500000, guid: 7d36208e8b0045f7ab3a61f1ab8f60c6, type: 3}
1313
m_Name: BMConfig
1414
m_EditorClassIdentifier:
15-
AssetLoadMode: 2
15+
AssetLoadMode: 1
1616
MaxDownLoadCount: 8
1717
ReDownLoadCount: 4

Assets/StreamingAssets/AllBundle.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)