Files
sbox-public/engine/Sandbox.Engine/Resources/AsyncResourceLoader.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

52 lines
1.0 KiB
C#

using System.Threading;
namespace Sandbox;
//
// This is just a test right now
//
class AsyncResourceLoader : IDisposable
{
HResourceManifest manifest;
AsyncResourceLoader( HResourceManifest manifest )
{
this.manifest = manifest;
}
~AsyncResourceLoader()
{
Dispose();
}
public async Task WaitForLoad( CancellationToken token = default )
{
// does this shit itself if the resource is missing?
// does it handle compiling okay?
while ( !NativeEngine.g_pResourceSystem.IsManifestLoaded( manifest ) )
{
await Task.Yield();
token.ThrowIfCancellationRequested();
}
}
public void Dispose()
{
if ( manifest.IsValid )
{
NativeEngine.g_pResourceSystem.DestroyResourceManifest( manifest );
manifest = default;
}
GC.SuppressFinalize( this );
}
static public AsyncResourceLoader Load( string filename )
{
var manifest = NativeEngine.g_pResourceSystem.LoadResourceInManifest( filename );
if ( manifest.IsNull ) return default;
return new AsyncResourceLoader( manifest );
}
}