ManiaMap.Godot
Procedural generation of metroidvania style maps for Godot .NET.
AsyncResourceLoader.cs
1using Godot;
3using System.Threading.Tasks;
4
6{
10 public static class AsyncResourceLoader
11 {
12 private static int _threadStatusCheckDelay = 16;
16 public static int ThreadStatusCheckDelay { get => _threadStatusCheckDelay; set => _threadStatusCheckDelay = Mathf.Max(value, 1); }
17
23 public static async Task<T> LoadAsync<T>(string path, string typeHint = "", bool useSubThreads = false,
24 ResourceLoader.CacheMode cacheMode = ResourceLoader.CacheMode.Reuse) where T : Resource
25 {
26 var error = ResourceLoader.LoadThreadedRequest(path, typeHint, useSubThreads, cacheMode);
27
28 if (error != Error.Ok)
29 throw new ThreadedResourceRequestException($"Error occured while requesting resource: (Error = {error}, Path = {path})");
30
31 var status = ResourceLoader.LoadThreadedGetStatus(path);
32
33 while (status != ResourceLoader.ThreadLoadStatus.Loaded)
34 {
35 if (status != ResourceLoader.ThreadLoadStatus.InProgress)
36 throw new ThreadedResourceRequestException($"Thread load status error: (Error = {status}, Path = {path})");
37
38 await Task.Delay(ThreadStatusCheckDelay);
39 status = ResourceLoader.LoadThreadedGetStatus(path);
40 }
41
42 return (T)ResourceLoader.LoadThreadedGet(path);
43 }
44 }
45}
Contains methods for loading Resources asynchronously.
static async Task< T > LoadAsync< T >(string path, string typeHint="", bool useSubThreads=false, ResourceLoader.CacheMode cacheMode=ResourceLoader.CacheMode.Reuse)
Loads a Resource from file asynchronously.
static int ThreadStatusCheckDelay
The delay time in milliseconds between each resource load status check.
Raised if an error is encountered while loading a resource asynchronously.