Skip to content

Commit 7a726d1

Browse files
committed
tiny performance update
VesselSattelite.Position is quite costly due to get_SignalProcessor, so lets not do this in a loop!
1 parent a6622e3 commit 7a726d1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/RemoteTech2/RangeModel/RangeModelExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ public static double DistanceTo(this ISatellite a, NetworkLink<ISatellite> b)
4545

4646
public static bool HasLineOfSightWith(this ISatellite a, ISatellite b)
4747
{
48+
var aPos = a.Position;
49+
var bPos = b.Position;
4850
foreach (CelestialBody referenceBody in FlightGlobals.Bodies)
4951
{
50-
Vector3d bodyFromA = referenceBody.position - a.Position;
51-
Vector3d bFromA = b.Position - a.Position;
52+
Vector3d bodyFromA = referenceBody.position - aPos;
53+
Vector3d bFromA = bPos - aPos;
5254
if (Vector3d.Dot(bodyFromA, bFromA) <= 0) continue;
5355
Vector3d bFromAnorm = bFromA.normalized;
5456
if (Vector3d.Dot(bodyFromA, bFromAnorm) >= bFromA.magnitude) continue;

0 commit comments

Comments
 (0)