Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.1.0 closeout fixes #2010

Merged
merged 4 commits into from
May 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/kOS.Safe/UpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,31 @@ public void UpdateFixedObservers(double deltaTime)
observer.KOSFixedUpdate(deltaTime);
}
}


public void ClearAllObservers()
{
var snapshot = new HashSet<IUpdateObserver>(observers);
foreach (var observer in snapshot)
{
IDisposable disp = observer as IDisposable;
if (disp != null)
{
disp.Dispose();
}
}
var snapshotFixed = new HashSet<IFixedUpdateObserver>(fixedObservers);
foreach (var observer in snapshotFixed)
{
IDisposable disp = observer as IDisposable;
if (disp != null)
{
disp.Dispose();
}
}
observers.Clear();
fixedObservers.Clear();
}

/// <summary>
/// Return all the registered fixed update handlers of a particular type
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/kOS/Communication/CommNetConnectivityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public bool HasConnection(Vessel vessel1, Vessel vessel2)
return true;

// We next need to query the network to find a connection between the two vessels.
// I found no exposed method for accessing chached paths directly, other than the
// I found no exposed method for accessing cached paths directly, other than the
// control path.

// WARNING: In stock this will only work for vessels with a relay antenna installed.
// This is a limitation put in place to improve performance in the stock game, and
// there isn't a very good way around it.
var net = CommNetNetwork.Instance.CommNet;
tempPath = new CommPath();
return net.FindPath(vessel1.Connection.Comm, tempPath, vessel2.Connection.Comm) || net.FindPath(vessel2.Connection.Comm, tempPath, vessel1.Connection.Comm);
return vessel1.id == vessel2.id || net.FindPath(vessel1.Connection.Comm, tempPath, vessel2.Connection.Comm) || net.FindPath(vessel2.Connection.Comm, tempPath, vessel1.Connection.Comm);
}

public void AddAutopilotHook(Vessel vessel, FlightInputCallback hook)
Expand Down
14 changes: 14 additions & 0 deletions src/kOS/Function/HighlightStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public HighlightStructure(UpdateHandler updateHandler, object toHighlight, RgbaC
stale = true;
enabled = true;
updateHandler.AddObserver(this);
GameEvents.onStageSeparation.Add(OnHighlightStaleEvent);
GameEvents.onVesselPartCountChanged.Add(OnHighlightStaleEvent);
}

private void InitializeSuffixes()
Expand Down Expand Up @@ -111,9 +113,21 @@ private void HighlightPart(PartValue partValue)
part.SetHighlight(enabled, false);
}

private void OnHighlightStaleEvent(EventReport evt)
{
stale = true;
}

private void OnHighlightStaleEvent(Vessel ves)
{
stale = true;
}

public void Dispose()
{
updateHandler.RemoveObserver(this);
GameEvents.onStageSeparation.Remove(OnHighlightStaleEvent);
GameEvents.onVesselPartCountChanged.Remove(OnHighlightStaleEvent);
}

public override string ToString()
Expand Down
3 changes: 2 additions & 1 deletion src/kOS/SharedObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ public void DestroyObjects()
if (BindingMgr != null) { BindingMgr.Dispose(); }
if (Window != null) { UnityEngine.Object.Destroy(Window); }
if (SoundMaker != null) { SoundMaker.StopAllVoices(); }
if (UpdateHandler != null) { UpdateHandler.ClearAllObservers(); }
var props = typeof(SharedObjects).GetProperties();
foreach (var prop in props)
{
if (!prop.PropertyType.IsValueType)
if (!prop.PropertyType.IsValueType && prop.GetSetMethod() != null)
{
prop.SetValue(this, null, null);
}
Expand Down