Skip to content

Commit 94707cf

Browse files
committed
perf: Minimal change to avoid iterating over every PART node
1 parent bd38405 commit 94707cf

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

Source/RocketSoundEnhancement/AudioUtility.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,6 @@ public static class AudioUtility
7070
public static AnimationCurve SmoothControl = AnimationCurve.EaseInOut(0f, 0.04f, 1f, 1f);
7171
public static string RSETag = "RSE";
7272

73-
public static ConfigNode GetConfigNode(string partInfoName, string moduleName, string moduleID = "")
74-
{
75-
var configs = GameDatabase.Instance.GetConfigs("PART");
76-
77-
foreach (var configNode in configs)
78-
{
79-
if (configNode.name.Replace("_", ".") == partInfoName)
80-
{
81-
if (moduleID == "")
82-
{
83-
return Array.FindAll(configNode.config.GetNodes("MODULE"), x => x.GetValue("name") == moduleName).FirstOrDefault();
84-
}
85-
else
86-
{
87-
return Array.FindAll(configNode.config.GetNodes("MODULE"), x => x.GetValue("name") == moduleName && x.GetValue("moduleID") == moduleID).FirstOrDefault();
88-
}
89-
}
90-
}
91-
return null;
92-
}
93-
9473
public static List<SoundLayer> CreateSoundLayerGroup(ConfigNode[] groupNodes)
9574
{
9675
var group = new List<SoundLayer>();

Source/RocketSoundEnhancement/PartModules/RSE_Module.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public override void OnStart(StartState state)
5353
{
5454
string partParentName = part.name + "_" + this.moduleName;
5555
AudioParent = AudioUtility.CreateAudioParent(part, partParentName);
56-
PartConfigNode = AudioUtility.GetConfigNode(part.partInfo.name, this.moduleName);
5756

5857
if (!float.TryParse(PartConfigNode.GetValue("volume"), out Volume)) Volume = 1;
5958
if (!float.TryParse(PartConfigNode.GetValue("DopplerFactor"), out DopplerFactor)) DopplerFactor = 0.5f;
@@ -338,5 +337,22 @@ public virtual void OnDestroy()
338337
}
339338
Destroy(AudioParent);
340339
}
340+
341+
public override void OnLoad(ConfigNode node)
342+
{
343+
base.OnLoad(node);
344+
345+
if (part.partInfo is null)
346+
{
347+
PartConfigNode = node;
348+
}
349+
else
350+
{
351+
PartConfigNode = part.partInfo.partPrefab
352+
.FindModuleImplementing<RSE_Module>()
353+
.PartConfigNode;
354+
}
355+
}
356+
341357
}
342358
}

Source/RocketSoundEnhancement/PartModules/RSE_RotorEngines.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public void SetupBlades()
5858
childPartsCount = childParts.Count;
5959
foreach (var childPart in childParts)
6060
{
61-
var configNode = GameDatabase.Instance.GetConfigs("PART").FirstOrDefault(x => x.name.Replace("_", ".") == childPart.partInfo.name);
62-
var propConfig = configNode.config.GetNode("RSE_Propellers");
61+
var configNode = childPart.partInfo.partConfig;
62+
var propConfig = configNode.GetNode("RSE_Propellers");
6363

6464
if (propConfig != null)
6565
{

0 commit comments

Comments
 (0)