Skip to content

Commit

Permalink
Workaround to issue of blinking connection lines, caused by 1 GC opti…
Browse files Browse the repository at this point in the history
…misation (swap commits ed2104c and dc5ae51) (Issue #8)
  • Loading branch information
KSP-TaxiService committed Nov 10, 2019
1 parent a4c9ab7 commit 3256be7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
18 changes: 9 additions & 9 deletions src/CommNetConstellation/CommNetLayer/CNCCommNetNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace CommNetConstellation.CommNetLayer
/// </summary>
public class CNCCommNetNetwork : CommNetNetwork
{
//Part of inactive network optimisation in CNCCommNetNetwork.Update()
//private float nextUpdateTime = 0.0f;
//private const float networkInterval = 0.1f; // in seconds
//Part of network optimisation in CNCCommNetNetwork.Update()
private float nextUpdateTime = 0.0f;
private const float networkInterval = 0.5f; // in seconds

public static new CNCCommNetNetwork Instance
{
Expand Down Expand Up @@ -44,14 +44,14 @@ protected override void Awake()

protected override void Update()
{
//Comment: Not recommended to run along with other active optimisation of evaluating
//Comment: Not recommended to run along with other optimisation of evaluating
//subset of connections in CNCCommNetwork.UpdateNetwork()
//Effect of running both optimisations is unacceptable low rate of connection check per second
//if (Time.time >= nextUpdateTime)
//{
base.Update();
//nextUpdateTime += networkInterval;
//}
if (Time.time >= nextUpdateTime)
{
base.Update();
nextUpdateTime += networkInterval;
}
}
}
}
48 changes: 25 additions & 23 deletions src/CommNetConstellation/CommNetLayer/CNCCommNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace CommNetConstellation.CommNetLayer
/// </summary>
public class CNCCommNetwork : CommNetwork
{
private const int REFRESH_TICKS = 50;
private int mTick = 0, mTickIndex = 0;
//private const int REFRESH_TICKS = 50;
//private int mTick = 0, mTickIndex = 0;

private short publicFreq = CNCSettings.Instance.PublicRadioFrequency;

Expand Down Expand Up @@ -63,29 +63,31 @@ protected override bool SetNodeConnection(CommNode a, CommNode b)
return false;
}

protected override void UpdateNetwork()
{
/*
UpdateNetwork is part of a Unity physical frame, which happens few times per time second (4?)
This optimisation is to spread the full workload of connection check to few frames, instead of every frame, as RemoteTech does
Directly copied from RemoteTech codebase
*/
var count = this.nodes.Count;
if (count == 0) { return; }
//Issue of KSP 1.8: This optimisation is causing the blinking of connection lines in "All Active Connections" Mode for unknown reason
//Workaround: Disable this optimisation until permanent fix is found
//protected override void UpdateNetwork()
//{
// /*
// UpdateNetwork is part of a Unity physical frame, which happens few times per time second (4?)
// This optimisation is to spread the full workload of connection check to few frames, instead of every frame, as RemoteTech does
// Directly copied from RemoteTech codebase
// */
// var count = this.nodes.Count;
// if (count == 0) { return; }

var baseline = (count / REFRESH_TICKS);
var takeCount = baseline + (((mTick++ % REFRESH_TICKS) < (count - baseline * REFRESH_TICKS)) ? 1 : 0);
// var baseline = (count / REFRESH_TICKS);
// var takeCount = baseline + (((mTick++ % REFRESH_TICKS) < (count - baseline * REFRESH_TICKS)) ? 1 : 0);

for (int i = mTickIndex ; i < mTickIndex + takeCount; i++)
{
for (int j = i + 1; j < count; j++)
{
this.SetNodeConnection(this.nodes[i], this[j]);
}
}
// for (int i = mTickIndex; i < mTickIndex + takeCount; i++)
// {
// for (int j = i + 1; j < count; j++)
// {
// this.SetNodeConnection(this.nodes[i], this[j]);
// }
// }

mTickIndex += takeCount;
mTickIndex = mTickIndex % this.nodes.Count;
}
// mTickIndex += takeCount;
// mTickIndex = mTickIndex % this.nodes.Count;
//}
}
}

0 comments on commit 3256be7

Please sign in to comment.