Skip to content

Commit

Permalink
Merge pull request #65 from RemoteTechnologiesGroup/1.6.0
Browse files Browse the repository at this point in the history
Sync 1.6.0
  • Loading branch information
Peppie84 committed Jan 8, 2015
2 parents f7e373e + 0fd53ec commit b91889d
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 92 deletions.
2 changes: 1 addition & 1 deletion build.remotetech.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ then
rm -f dlls.zip
fi

cd src/RemoteTech && xbuild
cd src/RemoteTech && xbuild /p:Configuration=Release

3 changes: 1 addition & 2 deletions src/RemoteTech/Modules/ModuleSPU.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace RemoteTech
Expand All @@ -26,7 +25,7 @@ public bool IsCommandStation
}
public FlightComputer FlightComputer { get; private set; }
public Vessel Vessel { get { return vessel; } }
public bool IsMaster { get { return Satellite != null && Satellite.SignalProcessor == (ISignalProcessor) this; } }
public bool IsMaster { get { return Satellite != null && Satellite.SignalProcessor == this; } }

private VesselSatellite Satellite { get { return RTCore.Instance.Satellites[mRegisteredId]; } }

Expand Down
35 changes: 12 additions & 23 deletions src/RemoteTech/NetworkManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using UnityEngine;

Expand Down Expand Up @@ -119,14 +118,7 @@ public IEnumerable<NetworkLink<ISatellite>> FindNeighbors(ISatellite s)

private void UpdateGraph(ISatellite a)
{
var result = new List<NetworkLink<ISatellite>>();

foreach (ISatellite b in this)
{
var link = GetLink(a, b);
if (link == null) continue;
result.Add(link);
}
var result = this.Select(b => GetLink(a, b)).Where(link => link != null).ToList();

// Send events for removed edges
foreach (var link in Graph[a.Guid].Except(result))
Expand All @@ -152,11 +144,10 @@ public static NetworkLink<ISatellite> GetLink(ISatellite sat_a, ISatellite sat_b

switch (RTSettings.Instance.RangeModelType)
{
default:
case RangeModel.Standard: // Stock range model
return RangeModelStandard.GetLink(sat_a, sat_b);
case RangeModel.Additive: // NathanKell
return RangeModelRoot.GetLink(sat_a, sat_b);
default: // Stock range model
return RangeModelStandard.GetLink(sat_a, sat_b);
}
}

Expand Down Expand Up @@ -208,15 +199,13 @@ IEnumerator IEnumerable.GetEnumerator()
}

/// <summary>Gets the position of a RemoteTech target from its id</summary>
/// <returns>The absolute position.</returns>
/// <returns>The absolute position or null if <paramref name="targetable"/> is neither
/// a satellite nor a celestial body.</returns>
/// <param name="targetable">The id of the satellite or celestial body whose position is
/// desired. May be the active vessel Guid.</param>
///
/// <exception cref="System.ArgumentException">Thrown if <paramref name="targetable"/> is neither
/// a satellite nor a celestial body.</exception>
/// desired. May be the active vessel Guid.</param>
///
/// <exceptsafe>The program state is unchanged in the event of an exception.</exceptsafe>
internal Vector3d GetPositionFromGuid(Guid targetable)
internal Vector3d? GetPositionFromGuid(Guid targetable)
{
ISatellite targetSat = this[targetable];
if (targetSat != null) {
Expand All @@ -227,7 +216,7 @@ internal Vector3d GetPositionFromGuid(Guid targetable)
return Planets[targetable].position;
}

throw new ArgumentException("Guid is neither a satellite nor a celestial body: ", "targetable");
return null;
}
}

Expand All @@ -241,12 +230,12 @@ public sealed class MissionControlSatellite : ISatellite, IPersistenceLoad
[Persistent] private double Height = 75.0f;
[Persistent] private int Body = 1;
[Persistent] private Color MarkColor = new Color(0.996078f, 0, 0, 1);
[Persistent(collectionIndex = "ANTENNA")] private MissionControlAntenna[] Antennas = new MissionControlAntenna[] { new MissionControlAntenna() };
[Persistent(collectionIndex = "ANTENNA")] private MissionControlAntenna[] Antennas = { new MissionControlAntenna() };

bool ISatellite.Powered { get { return true; } }
bool ISatellite.Visible { get { return true; } }
String ISatellite.Name { get { return Name; } set { Name = value; } }
Guid ISatellite.Guid { get { return this.mGuid; } }
Guid ISatellite.Guid { get { return mGuid; } }
Vector3d ISatellite.Position { get { return FlightGlobals.Bodies[Body].GetWorldSurfacePosition(Latitude, Longitude, Height); } }
bool ISatellite.IsCommandStation { get { return true; } }
bool ISatellite.HasLocalControl { get { return false; } }
Expand All @@ -261,7 +250,7 @@ void ISatellite.OnConnectionRefresh(List<NetworkRoute<ISatellite>> route) { }

public MissionControlSatellite()
{
this.mGuid = new Guid(this.Guid);
mGuid = new Guid(Guid);
}

void IPersistenceLoad.PersistenceLoad()
Expand All @@ -270,7 +259,7 @@ void IPersistenceLoad.PersistenceLoad()
{
antenna.Parent = this;
}
this.mGuid = new Guid(this.Guid);
mGuid = new Guid(Guid);
}

public override String ToString()
Expand Down
30 changes: 19 additions & 11 deletions src/RemoteTech/NetworkRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using Debug = System.Diagnostics.Debug;

namespace RemoteTech
{
Expand Down Expand Up @@ -32,10 +33,10 @@ public MapFilter Filter {
}
}

private static Texture2D mTexMark;
private HashSet<BidirectionalEdge<ISatellite>> mEdges = new HashSet<BidirectionalEdge<ISatellite>>();
private List<NetworkLine> mLines = new List<NetworkLine>();
private List<NetworkCone> mCones = new List<NetworkCone>();
private static readonly Texture2D mTexMark;
private readonly HashSet<BidirectionalEdge<ISatellite>> mEdges = new HashSet<BidirectionalEdge<ISatellite>>();
private readonly List<NetworkLine> mLines = new List<NetworkLine>();
private readonly List<NetworkCone> mCones = new List<NetworkCone>();

public bool ShowOmni { get { return (Filter & MapFilter.Omni) == MapFilter.Omni; } }
public bool ShowDish { get { return (Filter & MapFilter.Dish) == MapFilter.Dish; } }
Expand Down Expand Up @@ -82,13 +83,13 @@ public void OnGUI()
var worldPos = ScaledSpace.LocalToScaledSpace(s.Position);
if (MapView.MapCamera.transform.InverseTransformPoint(worldPos).z < 0f) continue;
Vector3 pos = MapView.MapCamera.camera.WorldToScreenPoint(worldPos);
Rect screenRect = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16);
var screenRect = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16);

if (s is MissionControlSatellite && RTSettings.Instance.HideGroundStationsBehindBody)
{
CelestialBody Kerbin = FlightGlobals.Bodies.Find(body => body.name == "Kerbin");
CelestialBody kerbin = FlightGlobals.Bodies.Find(body => body.name == "Kerbin");
// Hide the current ISatellite if it is behind its body
if (IsOccluded(s.Position, Kerbin))
if (IsOccluded(s.Position, kerbin))
showOnMapview = false;
}

Expand All @@ -107,7 +108,7 @@ public void OnGUI()

/// <summary>
/// Checks whether the location is behind the body
/// Orginal code by regex from https://github.com/NathanKell/RealSolarSystem/blob/master/Source/KSCSwitcher.cs
/// Original code by regex from https://github.com/NathanKell/RealSolarSystem/blob/master/Source/KSCSwitcher.cs
/// </summary>
private bool IsOccluded(Vector3d loc, CelestialBody body)
{
Expand Down Expand Up @@ -141,22 +142,29 @@ private void UpdateNetworkCones()
mCones[i].Material = MapView.fetch.orbitLinesMaterial;
mCones[i].LineWidth = 2.0f;
mCones[i].Antenna = antennas[i];
mCones[i].Center = RTCore.Instance.Network.GetPositionFromGuid(antennas[i].Target);
mCones[i].Color = Color.gray;
mCones[i].Active = ShowCone;

var center = RTCore.Instance.Network.GetPositionFromGuid(antennas[i].Target);
Debug.Assert(center != null,
"center != null",
String.Format("GetPositionFromGuid returned a null value for the target {0}",
antennas[i].Target)
);
mCones[i].Center = center.Value;
}
}

private void UpdateNetworkEdges()
{
var edges = mEdges.Where(e => CheckVisibility(e)).ToList();
var edges = mEdges.Where(CheckVisibility).ToList();
int oldLength = mLines.Count;
int newLength = edges.Count;

// Free any unused lines
for (int i = newLength; i < oldLength; i++)
{
GameObject.Destroy(mLines[i]);
Destroy(mLines[i]);
mLines[i] = null;
}
mLines.RemoveRange(Math.Min(oldLength, newLength), Math.Max(oldLength - newLength, 0));
Expand Down
25 changes: 11 additions & 14 deletions src/RemoteTech/RangeModel/RangeModelExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RemoteTech
{
Expand Down Expand Up @@ -46,17 +43,17 @@ public static bool IsInFieldOfView(this IAntenna dish, ISatellite target, ISatel
return false;
}

try {
Vector3d coneCenter = RTCore.Instance.Network.GetPositionFromGuid(dish.Target);
Vector3d? coneCenter = RTCore.Instance.Network.GetPositionFromGuid(dish.Target);

Vector3d dirToConeCenter = (coneCenter - antennaSat.Position);
Vector3d dirToTarget = (target.Position - antennaSat.Position);
if (coneCenter.HasValue)
{
Vector3d dirToConeCenter = (coneCenter.Value - antennaSat.Position);
Vector3d dirToTarget = (target.Position - antennaSat.Position);

return (Vector3d.Dot(dirToConeCenter.normalized, dirToTarget.normalized) >= dish.CosAngle);
} catch (ArgumentException e) {
RTLog.Notify("Unexpected dish target: {0}", e);
return false;
}
RTLog.Notify("Unexpected dish target: {0}", dish.Target);
return false;
}

/// <summary>Finds the distance between two ISatellites</summary>
Expand All @@ -68,8 +65,8 @@ public static double DistanceTo(this ISatellite a, ISatellite b)

/// <summary>Finds the distance between an ISatellite and the target of a connection</summary>
/// <returns>The distance in meters.</returns>
/// <param name="sat">The satellite from which the distance is to be measured.
/// <param name="link">The network node to whose destination the distance is to be measured.
/// <param name="sat">The satellite from which the distance is to be measured.</param>
/// <param name="link">The network node to whose destination the distance is to be measured.</param>
public static double DistanceTo(this ISatellite sat, NetworkLink<ISatellite> link)
{
return Vector3d.Distance(sat.Position, link.Target.Position);
Expand All @@ -80,7 +77,7 @@ public static double DistanceTo(this ISatellite sat, NetworkLink<ISatellite> lin
/// otherwise, <c>false</c>.</returns>
public static bool HasLineOfSightWith(this ISatellite satA, ISatellite satB)
{
const double minHeight = 5.0;
const double MIN_HEIGHT = 5.0;
Vector3d satAPos = satA.Position;
Vector3d satBPos = satB.Position;

Expand All @@ -97,7 +94,7 @@ public static bool HasLineOfSightWith(this ISatellite satA, ISatellite satB)
// Above conditions guarantee that Vector3d.Dot(bodyFromA, bFromANorm) * bFromANorm
// lies between the origin and bFromA
Vector3d lateralOffset = bodyFromA - Vector3d.Dot(bodyFromA, bFromANorm) * bFromANorm;
if (lateralOffset.magnitude < referenceBody.Radius - minHeight) return false;
if (lateralOffset.magnitude < referenceBody.Radius - MIN_HEIGHT) return false;
}
return true;
}
Expand Down
8 changes: 5 additions & 3 deletions src/RemoteTech/RemoteTech.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteTech", "RemoteTech.csproj", "{42155D82-1F25-4E59-9F65-64ABC583F420}"
EndProject
Global
Expand All @@ -9,8 +11,8 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{42155D82-1F25-4E59-9F65-64ABC583F420}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{42155D82-1F25-4E59-9F65-64ABC583F420}.Debug|Any CPU.Build.0 = Release|Any CPU
{42155D82-1F25-4E59-9F65-64ABC583F420}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{42155D82-1F25-4E59-9F65-64ABC583F420}.Debug|Any CPU.Build.0 = Debug|Any CPU
{42155D82-1F25-4E59-9F65-64ABC583F420}.Release|Any CPU.ActiveCfg = Release|Any CPU
{42155D82-1F25-4E59-9F65-64ABC583F420}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
Loading

0 comments on commit b91889d

Please sign in to comment.