Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ LoadAssetWithPotentialAsync< T >()

async Task ReLogic.Content.AssetRepository.LoadAssetWithPotentialAsync< T > ( Asset< T > asset,
AssetRequestMode mode )
inlineprivate
Type Constraints
T :class 

Definition at line 242 of file AssetRepository.cs.

242 : class
243 {
244 _ = 3;
245 try
246 {
248 {
249 throw new Exception("Asset load started without holding _requestLock");
250 }
251 TotalAssets++;
252 asset.SetToLoadingState();
254 new List<string>();
255 MainThreadCreationContext mainThreadCtx = new MainThreadCreationContext(new ContinuationScheduler(asset, this));
257 foreach (IContentSource source in sources)
258 {
259 if (source.Rejections.IsRejected(asset.Name))
260 {
261 continue;
262 }
263 string extension = source.GetExtension(asset.Name);
264 if (extension == null)
265 {
266 continue;
267 }
268 if (!_readers.TryGetReader(extension, out var reader))
269 {
270 source.Rejections.Reject(asset.Name, new ContentRejectionNoCompatibleReader(extension, _readers.GetSupportedExtensions()));
271 continue;
272 }
273 if (mode == AssetRequestMode.AsyncLoad)
274 {
275 await Task.Yield();
276 }
278 {
279 await Task.Yield();
280 }
281 T resultAsset;
282 using (Stream stream = source.OpenStream(asset.Name + extension))
283 {
284 _ = 2;
285 try
286 {
287 resultAsset = await reader.FromStream<T>(stream, mainThreadCtx);
288 }
289 catch (Exception e2)
290 {
291 source.Rejections.Reject(asset.Name, new ContentRejectionAssetReaderException(e2));
292 continue;
293 }
294 }
295 if (source.ContentValidator != null && !source.ContentValidator.AssetIsValid(resultAsset, asset.Name, out var rejectionReason))
296 {
297 source.Rejections.Reject(asset.Name, rejectionReason);
298 continue;
299 }
302 {
303 throw new Exception("Asset transfer started without holding _requestLock");
304 }
305 asset.SubmitLoadedContent(resultAsset, source);
306 LoadedAssets++;
307 return;
308 }
309 throw AssetLoadException.FromMissingAsset(asset.Name);
310 }
311 catch (Exception e)
312 {
313 AssetLoadFailHandler?.Invoke(asset.Name, e);
314 if (mode == AssetRequestMode.ImmediateLoad)
315 {
316 throw;
317 }
318 }
319 finally
320 {
322 }
323 }
bool TryGetReader(string extension, out IAssetReader reader)
readonly AssetReaderCollection _readers
FailedToLoadAssetCustomAction AssetLoadFailHandler
static int Decrement(ref int location)
static int Increment(ref int location)
static bool IsEntered(object obj)
Definition Monitor.cs:71
static YieldAwaitable Yield()
Definition Task.cs:2220

References ReLogic.Content.AssetRepository._readers, ReLogic.Content.AssetRepository._Remaining, ReLogic.Content.AssetRepository._requestLock, ReLogic.Content.AssetRepository._sources, ReLogic.Content.AssetRepository.AssetLoadFailHandler, System.Threading.Interlocked.Decrement(), ReLogic.Content.AssetLoadException.FromMissingAsset(), ReLogic.Content.AssetReaderCollection.GetSupportedExtensions(), System.Threading.Interlocked.Increment(), System.Threading.Monitor.IsEntered(), ReLogic.Content.AssetRepository.IsMainThread, ReLogic.Content.AssetRepository.LoadedAssets, System.Linq.source, System.stream, ReLogic.Content.AssetRepository.TotalAssets, ReLogic.Content.AssetReaderCollection.TryGetReader(), and System.Threading.Tasks.Task< TResult >.Yield().