Skip to content

Commit 31a04a5

Browse files
committed
Refactor MAS_PAGE loading.
Create a dictionary once up front, so we don't search the game database for every single page of every single MFD.
1 parent bf11afb commit 31a04a5

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Source/MASLoader.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ public class MASLoader : MonoBehaviour
6767
static public Dictionary<char, AudioClip> morseCode = new Dictionary<char, AudioClip>(26);
6868

6969
/// <summary>
70-
/// Dictionary of all MAS_SUBPAGE nodes.
70+
/// Dictionary of all MAS_PAGE nodes.
71+
/// </summary>
72+
static public Dictionary<string, ConfigNode> pages = new Dictionary<string, ConfigNode>();
73+
74+
/// <summary>
75+
/// Dictionary of all MAS_SUB_PAGE nodes.
7176
/// </summary>
7277
static public Dictionary<string, List<ConfigNode>> subPages = new Dictionary<string, List<ConfigNode>>();
7378

@@ -772,6 +777,19 @@ private void LoadAssets()
772777
}
773778
}
774779

780+
pages.Clear();
781+
ConfigNode[] pageNode = GameDatabase.Instance.GetConfigNodes("MAS_PAGE");
782+
for (int pageIdx = 0; pageIdx < pageNode.Length; ++pageIdx)
783+
{
784+
string pageName = string.Empty;
785+
if (pageNode[pageIdx].TryGetValue("name", ref pageName))
786+
{
787+
pageName = pageName.Trim();
788+
pages.Add(pageName, pageNode[pageIdx]);
789+
Utility.LogMessage(this, "Found MAS_PAGE \"{0}\"", pageName);
790+
}
791+
}
792+
775793
subPages.Clear();
776794
ConfigNode[] subPageNode = GameDatabase.Instance.GetConfigNodes("MAS_SUB_PAGE");
777795
for (int subPageIdx = 0; subPageIdx < subPageNode.Length; ++subPageIdx)

Source/Utility.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,18 +588,13 @@ internal static void DebugDumpConfigNode(ConfigNode node)
588588
/// <returns>The ConfigNode, or null if it wasn't found.</returns>
589589
internal static ConfigNode GetPageConfigNode(string pageName)
590590
{
591-
ConfigNode[] asPageNodes = GameDatabase.Instance.GetConfigNodes("MAS_PAGE");
592-
593-
for (int nodeIdx = asPageNodes.Length - 1; nodeIdx >= 0; --nodeIdx)
591+
ConfigNode pageNode;
592+
if (!MASLoader.pages.TryGetValue(pageName, out pageNode))
594593
{
595-
string nodeName = string.Empty;
596-
if (asPageNodes[nodeIdx].TryGetValue("name", ref nodeName) && nodeName == pageName)
597-
{
598-
return asPageNodes[nodeIdx];
599-
}
594+
return null;
600595
}
601596

602-
return null;
597+
return pageNode;
603598
}
604599

605600
/// <summary>

0 commit comments

Comments
 (0)