From 8a21d692d990ed3c7f4849f4598cdef78492ea2b Mon Sep 17 00:00:00 2001 From: user Date: Tue, 3 Dec 2024 03:05:21 +0300 Subject: [PATCH] Performance fix: get rid of GetRoom called on every redraw of shuttle bay, which is slow if not enclosed. --- Source/1.5/Comp/CompShipBay.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/1.5/Comp/CompShipBay.cs b/Source/1.5/Comp/CompShipBay.cs index 14d3f272..dea909e6 100644 --- a/Source/1.5/Comp/CompShipBay.cs +++ b/Source/1.5/Comp/CompShipBay.cs @@ -37,6 +37,7 @@ public override void PostExposeData() public CellRect bayRect; Matrix4x4 matrix = new Matrix4x4(); public HashSet reservedArea = new HashSet(); + private bool? needDrawRoof = null; HashSet dockedShuttles = new HashSet(); CompRefuelable compRefuelable; CompPowerTrader compPowerTrader; @@ -140,7 +141,12 @@ public IntVec3 CanFitShuttleSize(VehiclePawn vehicle) //we only have square shut public override void PostDraw() { base.PostDraw(); - if ((Find.PlaySettings.showRoofOverlay || parent.GetRoom() != null && parent.GetRoom().Cells.Any(c => c.Fogged(parent.Map))) && parent.Position.Roofed(parent.Map)) + // Get room is slow if not enclosed, so update flag rarely. + if (needDrawRoof == null || Find.TickManager.TicksGame % 60 == 0) + { + needDrawRoof = parent.GetRoom() != null && parent.GetRoom().Cells.Any(c => c.Fogged(parent.Map)); + } + if ((Find.PlaySettings.showRoofOverlay || (needDrawRoof ?? false)) && parent.Position.Roofed(parent.Map)) { //roofedGraphic.Draw(new Vector3(parent.DrawPos.x, Altitudes.AltitudeFor(AltitudeLayer.MoteOverhead), parent.DrawPos.z), parent.Rotation, parent);