Skip to content

Commit

Permalink
Fix #3112 : disable KOSNameTag's update functions (#3121)
Browse files Browse the repository at this point in the history
-these are obviously very tiny but considering every part gets one, that's a lot of no-op virtual calls
  • Loading branch information
JonnyOThan authored Jan 31, 2025
1 parent cb3eb98 commit 6e9388f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/kOS/Module/KOSNameTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using kOS.Suffixed;
using kOS.Safe.Utilities;
using UnityEngine;
using System;

namespace kOS.Module
{
Expand Down Expand Up @@ -61,6 +62,10 @@ public override void OnAwake()
part.RemoveModule(pm);
}
}

// make this module cheaper in update loops
isEnabled = false;
enabled = false;
}

public void TypingDone(string newValue)
Expand All @@ -76,4 +81,39 @@ public void TypingCancel()
typingWindow = null;
}
}

// setting isEnabled to false prevents the nametag from showing up in the PAW...work around that.
[KSPAddon(KSPAddon.Startup.FlightAndEditor, false)]
class KOSNameTagActivationManager : MonoBehaviour
{
void Awake()
{
GameEvents.onPartActionUICreate.Add(OnPartActionUICreate);
GameEvents.onPartActionUIShown.Add(OnPartActionUIShown);
}

void OnDestroy()
{
GameEvents.onPartActionUICreate.Remove(OnPartActionUICreate);
GameEvents.onPartActionUIShown.Remove(OnPartActionUIShown);
}

private void OnPartActionUICreate(Part part)
{
var nameTagModule = part.FindModuleImplementing<KOSNameTag>();
if (nameTagModule != null)
{
nameTagModule.isEnabled = true;
}
}

private void OnPartActionUIShown(UIPartActionWindow paw, Part part)
{
var nameTagModule = part.FindModuleImplementing<KOSNameTag>();
if (nameTagModule != null)
{
nameTagModule.isEnabled = false;
}
}
}
}

0 comments on commit 6e9388f

Please sign in to comment.