Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Kopernicus/Kopernicus
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: adf77ebaae01
Choose a base ref
...
head repository: Kopernicus/Kopernicus
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0bb71647d22a
Choose a head ref
  • 4 commits
  • 1 file changed
  • 2 contributors

Commits on Sep 3, 2018

  1. Merge pull request #1 from Kopernicus/master

    Update fork to head
    marr75 authored Sep 3, 2018
    Copy the full SHA
    85fbb73 View commit details

Commits on Sep 6, 2018

  1. Copy the full SHA
    012fb49 View commit details

Commits on Sep 11, 2018

  1. Copy the full SHA
    111782e View commit details

Commits on Sep 21, 2018

  1. Merge pull request #310 from marr75/master

    Orbital icon customization loop performance issues
    StollD authored Sep 21, 2018
    Copy the full SHA
    0bb7164 View commit details
Showing with 34 additions and 14 deletions.
  1. +34 −14 src/Kopernicus/RuntimeUtility/RuntimeUtility.cs
48 changes: 34 additions & 14 deletions src/Kopernicus/RuntimeUtility/RuntimeUtility.cs
Original file line number Diff line number Diff line change
@@ -51,6 +51,8 @@ public class RuntimeUtility : MonoBehaviour
{
// Variables
public MapObject previous;
private readonly Dictionary<CelestialBody, Sprite> _spriteCache = new Dictionary<CelestialBody, Sprite>();
private bool _mapDirty = false;

// Awake() - flag this class as don't destroy on load and register delegates
void Awake()
@@ -71,6 +73,7 @@ void Awake()
// Add handlers
GameEvents.onPartUnpack.Add(OnPartUnpack);
GameEvents.onLevelWasLoaded.Add(FixCameras);
GameEvents.OnMapEntered.Add(delegate { _mapDirty = true; });
GameEvents.onLevelWasLoaded.Add(delegate (GameScenes scene)
{
//if (MapView.fetch != null)
@@ -346,7 +349,8 @@ void LateUpdate()
FixZooming();
ApplyOrbitVisibility();
RDFixer();

ApplyOrbitIconCustomization();

// Prevent the orbit lines from flickering
PlanetariumCamera.Camera.farClipPlane = 1e14f;

@@ -391,19 +395,6 @@ void LateUpdate()
}
}
}

// Apply orbit icon customization
foreach (MapNode node in Resources.FindObjectsOfTypeAll<MapNode>())
{
if (node.mapObject != null && node.mapObject.celestialBody != null && node.mapObject.celestialBody.Has("iconTexture"))
{
Texture2D texture = node.mapObject.celestialBody.Get<Texture2D>("iconTexture");
node.SetIcon(Sprite.Create(texture,
new Rect(0, 0, texture.width, texture.height),
new Vector2(0.5f, 0.5f), 100, 1, SpriteMeshType.Tight,
Vector4.zero));
}
}
}

foreach (CelestialBody body in PSystemManager.Instance.localBodies)
@@ -519,6 +510,35 @@ void RDFixer()
}
}

void ApplyOrbitIconCustomization()
{
bool nodesReady = FlightGlobals.Bodies.Any(b => b.MapObject?.uiNode != null);
if (_mapDirty && nodesReady)
{
IEnumerable<CelestialBody> customOrbitalIcons = FlightGlobals.Bodies.Where(b => b.MapObject?.uiNode != null && b.Has("iconTexture"));
foreach (CelestialBody body in customOrbitalIcons)
{
_spriteCache.TryGetValue(body, out Sprite sprite);
if (sprite == null)
{
Texture2D texture = body.Get<Texture2D>("iconTexture");
sprite = Sprite.Create(
texture,
new Rect(0, 0, texture.width, texture.height),
new Vector2(0.5f, 0.5f),
100,
1,
SpriteMeshType.Tight,
Vector4.zero
);
_spriteCache[body] = sprite;
}
body.MapObject.uiNode.SetIcon(sprite);
}
_mapDirty = false;
}
}

// Fix the Space Center
void FixCameras(GameScenes scene)
{