1- using System . Collections . Generic ;
1+ using OxGKit . LoggingSystem ;
2+ using System . Collections . Generic ;
23
34namespace OxGFrame . AssetLoader . Cacher
45{
@@ -9,29 +10,22 @@ internal abstract class AssetCache<T>
910 /// </summary>
1011 public class RetryCounter
1112 {
12- public byte retryCount ;
13- public byte maxRetryCount ;
13+ public int retryCount ;
14+ public int maxRetryCount ;
1415
15- public RetryCounter ( byte maxRetryCount )
16+ public RetryCounter ( int maxRetryCount )
1617 {
17- this . retryCount = 0 ;
18- this . maxRetryCount = maxRetryCount ;
18+ this . retryCount = this . maxRetryCount = maxRetryCount ;
1919 }
2020
21- public bool IsRetryActive ( )
21+ public bool IsOutOfRetries ( )
2222 {
23- return this . retryCount > 0 ;
23+ return this . retryCount < 0 ;
2424 }
2525
26- public bool IsRetryValid ( )
26+ public void DelRetryCount ( )
2727 {
28- // 嘗試次數先++, 後判斷, 所以需使用 <= 進行判斷
29- return this . retryCount <= maxRetryCount ;
30- }
31-
32- public void AddRetryCount ( )
33- {
34- this . retryCount ++ ;
28+ this . retryCount -- ;
3529 }
3630 }
3731
@@ -41,9 +35,14 @@ public void AddRetryCount()
4135 protected Dictionary < string , T > _cacher ;
4236
4337 /// <summary>
44- /// Blocker 加載標記
38+ /// Blocker 加載標記緩存
4539 /// </summary>
46- protected Dictionary < string , RetryCounter > _loadingFlags ;
40+ protected HashSet < string > _loadingFlags ;
41+
42+ /// <summary>
43+ /// 嘗試計數器緩存
44+ /// </summary>
45+ protected Dictionary < string , RetryCounter > _retryCounters ;
4746
4847 /// <summary>
4948 /// 當前進度數量 (Progress)
@@ -67,40 +66,55 @@ public void AddRetryCount()
6766 public AssetCache ( )
6867 {
6968 this . _cacher = new Dictionary < string , T > ( ) ;
70- this . _loadingFlags = new Dictionary < string , RetryCounter > ( ) ;
69+ this . _loadingFlags = new HashSet < string > ( ) ;
70+ this . _retryCounters = new Dictionary < string , RetryCounter > ( ) ;
7171 }
7272
73- protected bool HasInLoadingFlags ( string assetName )
73+ #region Loading Flag
74+ protected bool HasInLoadingFlag ( string assetName )
7475 {
7576 if ( string . IsNullOrEmpty ( assetName ) )
7677 return false ;
77- return this . _loadingFlags . ContainsKey ( assetName ) ;
78+ return this . _loadingFlags . Contains ( assetName ) ;
7879 }
7980
80- protected void AddLoadingFlags ( string assetName , byte maxRetryCount )
81+ protected void AddLoadingFlag ( string assetName )
8182 {
82- if ( ! this . HasInLoadingFlags ( assetName ) )
83- this . _loadingFlags . Add ( assetName , new RetryCounter ( maxRetryCount ) ) ;
83+ if ( ! this . HasInLoadingFlag ( assetName ) )
84+ {
85+ this . _loadingFlags . Add ( assetName ) ;
86+ Logging . Print < Logger > ( $ "Marked asset as loading: { assetName } .") ;
87+ }
8488 }
8589
86- protected void RemoveLoadingFlags ( string assetName )
90+ protected void RemoveLoadingFlag ( string assetName )
8791 {
88- if ( this . HasInLoadingFlags ( assetName ) )
92+ if ( this . HasInLoadingFlag ( assetName ) )
93+ {
8994 this . _loadingFlags . Remove ( assetName ) ;
95+ Logging . Print < Logger > ( $ "Cleared loading flag: { assetName } .") ;
96+ }
97+ }
98+ #endregion
99+
100+ #region Retry Counter
101+ protected void StartRetryCounter ( string assetName , byte maxRetryCount )
102+ {
103+ if ( ! this . _retryCounters . ContainsKey ( assetName ) )
104+ this . _retryCounters . Add ( assetName , new RetryCounter ( maxRetryCount ) ) ;
90105 }
91106
92107 protected RetryCounter GetRetryCounter ( string assetName )
93108 {
94- this . _loadingFlags . TryGetValue ( assetName , out RetryCounter retryCounter ) ;
109+ this . _retryCounters . TryGetValue ( assetName , out RetryCounter retryCounter ) ;
95110 return retryCounter ;
96111 }
97112
98- ~ AssetCache ( )
113+ protected void StopRetryCounter ( string assetName )
99114 {
100- this . _cacher . Clear ( ) ;
101- this . _cacher = null ;
102- this . _loadingFlags . Clear ( ) ;
103- this . _loadingFlags = null ;
115+ if ( this . _retryCounters . ContainsKey ( assetName ) )
116+ this . _retryCounters . Remove ( assetName ) ;
104117 }
118+ #endregion
105119 }
106120}
0 commit comments