-
Notifications
You must be signed in to change notification settings - Fork 12
/
KCLCache.cs
67 lines (53 loc) · 1.56 KB
/
KCLCache.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using OpenTK;
using OpenTK.Graphics.OpenGL;
namespace SM64DSe
{
static class KCLCache
{
public static KCL GetKCL(string name)
{
if (m_Clsns.ContainsKey(name))
{
CachedKCL found = m_Clsns[name];
found.m_References++;
return found.m_Clsn;
}
if (!Program.m_ROM.FileExists(name))
return null;
NitroFile kclfile = Program.m_ROM.GetFileFromName(name);
KCL clsn = new KCL(kclfile);
CachedKCL ckcl = new CachedKCL();
ckcl.m_Clsn = clsn;
ckcl.m_References = 1;
m_Clsns.Add(name, ckcl);
return clsn;
}
public static void RemoveKCL(KCL clsn)
{
if (!m_Clsns.ContainsKey(clsn.m_File.m_Name))
return;
RemoveKCL(clsn.m_File.m_Name);
}
public static void RemoveKCL(string clsnName)
{
if (!m_Clsns.ContainsKey(clsnName))
return;
CachedKCL ckcl = m_Clsns[clsnName];
ckcl.m_References--;
if (ckcl.m_References > 0)
return;
m_Clsns.Remove(clsnName);
}
private class CachedKCL
{
public KCL m_Clsn;
public int m_References;
}
private static Dictionary<string, CachedKCL> m_Clsns = new Dictionary<string, CachedKCL>();
}
}