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 {
17 public static async Task<T> LoadAsync<T>(string path, string typeHint = "", bool useSubThreads = false,
18 ResourceLoader.CacheMode cacheMode = ResourceLoader.CacheMode.Reuse) where T : Resource
19 {
20 var tree = (SceneTree)Engine.GetMainLoop();
21 var error = ResourceLoader.LoadThreadedRequest(path, typeHint, useSubThreads, cacheMode);
22
23 if (error != Error.Ok)
24 throw new ThreadedResourceRequestException($"Error occured while requesting resource: (Error = {error}, Path = {path})");
25
26 var status = ResourceLoader.LoadThreadedGetStatus(path);
27
28 while (status != ResourceLoader.ThreadLoadStatus.Loaded)
29 {
30 if (status != ResourceLoader.ThreadLoadStatus.InProgress)
31 throw new ThreadedResourceRequestException($"Thread load status error: (Error = {status}, Path = {path})");
32
33 await tree.ToSignal(tree, SceneTree.SignalName.ProcessFrame);
34 status = ResourceLoader.LoadThreadedGetStatus(path);
35 }
36
37 return (T)ResourceLoader.LoadThreadedGet(path);
38 }
39 }
40}
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.
Raised if an error is encountered while loading a resource asynchronously.