Skip to content

Commit 3571dc2

Browse files
committed
Merge remote-tracking branch 'leftler/NullableReturn' into 1.6.0
2 parents 06d62c7 + f115b28 commit 3571dc2

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

src/RemoteTech/NetworkManager.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,13 @@ IEnumerator IEnumerable.GetEnumerator()
208208
}
209209

210210
/// <summary>Gets the position of a RemoteTech target from its id</summary>
211-
/// <returns>The absolute position.</returns>
211+
/// <returns>The absolute position or null if <paramref name="targetable"/> is neither
212+
/// a satellite nor a celestial body.</returns>
212213
/// <param name="targetable">The id of the satellite or celestial body whose position is
213-
/// desired. May be the active vessel Guid.</param>
214-
///
215-
/// <exception cref="System.ArgumentException">Thrown if <paramref name="targetable"/> is neither
216-
/// a satellite nor a celestial body.</exception>
214+
/// desired. May be the active vessel Guid.</param>
217215
///
218216
/// <exceptsafe>The program state is unchanged in the event of an exception.</exceptsafe>
219-
internal Vector3d GetPositionFromGuid(Guid targetable)
217+
internal Vector3d? GetPositionFromGuid(Guid targetable)
220218
{
221219
ISatellite targetSat = this[targetable];
222220
if (targetSat != null) {
@@ -227,7 +225,7 @@ internal Vector3d GetPositionFromGuid(Guid targetable)
227225
return Planets[targetable].position;
228226
}
229227

230-
throw new ArgumentException("Guid is neither a satellite nor a celestial body: ", "targetable");
228+
return null;
231229
}
232230
}
233231

src/RemoteTech/NetworkRenderer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Collections.Generic;
44
using UnityEngine;
5+
using Debug = System.Diagnostics.Debug;
56

67
namespace RemoteTech
78
{
@@ -141,9 +142,16 @@ private void UpdateNetworkCones()
141142
mCones[i].Material = MapView.fetch.orbitLinesMaterial;
142143
mCones[i].LineWidth = 2.0f;
143144
mCones[i].Antenna = antennas[i];
144-
mCones[i].Center = RTCore.Instance.Network.GetPositionFromGuid(antennas[i].Target);
145145
mCones[i].Color = Color.gray;
146146
mCones[i].Active = ShowCone;
147+
148+
var center = RTCore.Instance.Network.GetPositionFromGuid(antennas[i].Target);
149+
Debug.Assert(center != null,
150+
"center != null",
151+
String.Format("GetPositionFromGuid retuned a null value for the target {0}",
152+
antennas[i].Target)
153+
);
154+
mCones[i].Center = center.Value;
147155
}
148156
}
149157

src/RemoteTech/RangeModel/RangeModelExtensions.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,21 @@ public static bool IsInFieldOfView(this IAntenna dish, ISatellite target, ISatel
4646
return false;
4747
}
4848

49-
try {
50-
Vector3d coneCenter = RTCore.Instance.Network.GetPositionFromGuid(dish.Target);
49+
Vector3d? coneCenter = RTCore.Instance.Network.GetPositionFromGuid(dish.Target);
5150

52-
Vector3d dirToConeCenter = (coneCenter - antennaSat.Position);
53-
Vector3d dirToTarget = (target.Position - antennaSat.Position);
51+
if (coneCenter.HasValue)
52+
{
53+
Vector3d dirToConeCenter = (coneCenter.Value - antennaSat.Position);
54+
Vector3d dirToTarget = (target.Position - antennaSat.Position);
5455

5556
return (Vector3d.Dot(dirToConeCenter.normalized, dirToTarget.normalized) >= dish.CosAngle);
56-
} catch (ArgumentException e) {
57-
RTLog.Notify("Unexpected dish target: {0}", e);
57+
}
58+
else
59+
{
60+
RTLog.Notify("Unexpected dish target: {0}", dish.Target);
5861
return false;
5962
}
63+
6064
}
6165

6266
/// <summary>Finds the distance between two ISatellites</summary>

0 commit comments

Comments
 (0)