mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-15 09:49:23 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
52 lines
1.0 KiB
C#
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 );
|
|
}
|
|
}
|