Skip to content

Commit 6e9388f

Browse files
authored
Fix #3112 : disable KOSNameTag's update functions (#3121)
-these are obviously very tiny but considering every part gets one, that's a lot of no-op virtual calls
1 parent cb3eb98 commit 6e9388f

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

src/kOS/Module/KOSNameTag.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using kOS.Suffixed;
33
using kOS.Safe.Utilities;
44
using UnityEngine;
5+
using System;
56

67
namespace kOS.Module
78
{
@@ -61,6 +62,10 @@ public override void OnAwake()
6162
part.RemoveModule(pm);
6263
}
6364
}
65+
66+
// make this module cheaper in update loops
67+
isEnabled = false;
68+
enabled = false;
6469
}
6570

6671
public void TypingDone(string newValue)
@@ -76,4 +81,39 @@ public void TypingCancel()
7681
typingWindow = null;
7782
}
7883
}
84+
85+
// setting isEnabled to false prevents the nametag from showing up in the PAW...work around that.
86+
[KSPAddon(KSPAddon.Startup.FlightAndEditor, false)]
87+
class KOSNameTagActivationManager : MonoBehaviour
88+
{
89+
void Awake()
90+
{
91+
GameEvents.onPartActionUICreate.Add(OnPartActionUICreate);
92+
GameEvents.onPartActionUIShown.Add(OnPartActionUIShown);
93+
}
94+
95+
void OnDestroy()
96+
{
97+
GameEvents.onPartActionUICreate.Remove(OnPartActionUICreate);
98+
GameEvents.onPartActionUIShown.Remove(OnPartActionUIShown);
99+
}
100+
101+
private void OnPartActionUICreate(Part part)
102+
{
103+
var nameTagModule = part.FindModuleImplementing<KOSNameTag>();
104+
if (nameTagModule != null)
105+
{
106+
nameTagModule.isEnabled = true;
107+
}
108+
}
109+
110+
private void OnPartActionUIShown(UIPartActionWindow paw, Part part)
111+
{
112+
var nameTagModule = part.FindModuleImplementing<KOSNameTag>();
113+
if (nameTagModule != null)
114+
{
115+
nameTagModule.isEnabled = false;
116+
}
117+
}
118+
}
79119
}

0 commit comments

Comments
 (0)