-
Notifications
You must be signed in to change notification settings - Fork 0
/
Resource.cs
45 lines (37 loc) · 962 Bytes
/
Resource.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Threading;
namespace PiGameSharp
{
/// <summary>
/// A (un)loadable resource identified by an int32 resource key.
/// </summary>
public abstract class Resource
{
private static int ResourceId = 0;
protected readonly object sync_key = new object();
protected Resource() => Key = Interlocked.Increment(ref ResourceId);
public Func<byte[]> DataSource;
/// <summary>
/// The unique resource identifier for this resource
/// </summary>
public int Key { get; }
/// <summary>
/// Load the resource and prepare it for use
/// </summary>
public void LoadSync()
{
lock (sync_key)
Load();
}
/// <summary>
/// Releases all resource used by the <see cref="PiGameSharp.Resource"/> object.
/// </summary>
public void UnloadSync()
{
lock (sync_key)
Unload();
}
protected abstract void Load();
protected abstract void Unload();
}
}