Esempio n. 1
0
            public void RenderMarkers(DisposableIterator apsis_iterator,
                                      MapObject.ObjectType type,
                                      NodeSource source,
                                      ReferenceFrameSelector reference_frame)
            {
                MapObject associated_map_object;

                UnityEngine.Color colour;
                switch (type)
                {
                case MapObject.ObjectType.Apoapsis:
                case MapObject.ObjectType.Periapsis:
                    CelestialBody fixed_body = reference_frame.Centre();
                    associated_map_object = fixed_body.MapObject;
                    colour = fixed_body.orbit == null
                     ? XKCDColors.SunshineYellow
                     : fixed_body.orbitDriver.Renderer.nodeColor;
                    break;

                case MapObject.ObjectType.ApproachIntersect:
                    associated_map_object = reference_frame.target.mapObject;
                    colour = XKCDColors.Chartreuse;
                    break;

                case MapObject.ObjectType.AscendingNode:
                case MapObject.ObjectType.DescendingNode:
                    if (reference_frame.Centre() == null)
                    {
                        // In two-body frames, if apsides are shown, they are shown with the
                        // colour of the secondary (or in XKCD chartreuse if the secondary is
                        // a vessel).
                        // The nodes are with respect to the orbit of the secondary around the
                        // primary. We show the nodes with the colour of the primary.
                        CelestialBody primary = reference_frame.OrientingBody();
                        associated_map_object = primary.MapObject;
                        colour = primary.orbit == null
                        ? XKCDColors.SunshineYellow
                        : primary.orbitDriver.Renderer.nodeColor;
                    }
                    else
                    {
                        // In one-body frames, the apsides are shown with the colour of the
                        // body.
                        // The nodes are with respect to the equator, rather than with respect
                        // to an orbit. We show the nodes in a different (but arbitrary)
                        // colour so that they can be distinguished easily.
                        associated_map_object = reference_frame.Centre().MapObject;
                        colour = XKCDColors.Chartreuse;
                    }
                    break;

                default:
                    throw Log.Fatal($"Unexpected type {type}");
                }
                colour.a = 1;

                for (int i = 0;
                     i < MaxRenderedNodes && !apsis_iterator.IteratorAtEnd();
                     ++i, apsis_iterator.IteratorIncrement())
                {
                    QP apsis = apsis_iterator.IteratorGetDiscreteTrajectoryQP();
                    MapNodeProperties node_properties = new MapNodeProperties {
                        visible               = true,
                        object_type           = type,
                        colour                = colour,
                        reference_frame       = reference_frame,
                        world_position        = (Vector3d)apsis.q,
                        velocity              = (Vector3d)apsis.p,
                        source                = source,
                        time                  = apsis_iterator.IteratorGetDiscreteTrajectoryTime(),
                        associated_map_object = associated_map_object,
                    };
                    if (type == MapObject.ObjectType.Periapsis &&
                        reference_frame.Centre().GetAltitude(
                            node_properties.world_position) < 0)
                    {
                        node_properties.object_type = MapObject.ObjectType.PatchTransition;
                        node_properties.colour      = XKCDColors.Orange;
                    }

                    if (pool_index_ == nodes_.Count)
                    {
                        nodes_.Add(MakePoolNode());
                    }
                    else if (properties_[nodes_[pool_index_]].object_type !=
                             node_properties.object_type ||
                             properties_[nodes_[pool_index_]].colour !=
                             node_properties.colour)
                    {
                        // KSP attaches labels to its map nodes, but never detaches them.
                        // If the node changes type, we end up with an arbitrary combination of
                        // labels Ap, Pe, AN, DN.
                        // Similarly, if the node changes colour, the colour of the icon label
                        // is not updated to match the icon (making it unreadable in some
                        // cases).  Recreating the node entirely takes a long time
                        // (approximately 𝑁 * 70 μs, where 𝑁 is the total number of map nodes
                        // in existence), instead we manually get rid of the labels.
                        foreach (var component in nodes_[pool_index_].transform.
                                 GetComponentsInChildren <TMPro.TextMeshProUGUI>())
                        {
                            if (component.name == "iconLabel(Clone)")
                            {
                                UnityEngine.Object.Destroy(component.gameObject);
                            }
                        }
                        // Ensure that KSP thinks the type changed, and reattaches icon
                        // labels next time around, otherwise we might end up with no labels.
                        // Null nodes do not have a label, so inducing a type change through
                        // Null does not result in spurious labels.  Note that the type is
                        // updated only if the node is visible.
                        properties_[nodes_[pool_index_]].visible     = true;
                        properties_[nodes_[pool_index_]].object_type =
                            MapObject.ObjectType.Null;
                        nodes_[pool_index_].NodeUpdate();
                    }
                    properties_[nodes_[pool_index_++]] = node_properties;
                }
            }
Esempio n. 2
0
            public void RenderMarkers(DisposableIterator apsis_iterator,
                                      Provenance provenance,
                                      ReferenceFrameSelector reference_frame)
            {
                if (!nodes_.ContainsKey(provenance))
                {
                    nodes_.Add(provenance, new SingleProvenancePool());
                }
                var       pool = nodes_[provenance];
                MapObject associated_map_object;

                UnityEngine.Color colour;
                switch (provenance.type)
                {
                case MapObject.ObjectType.Apoapsis:
                case MapObject.ObjectType.Periapsis:
                    CelestialBody fixed_body = reference_frame.Centre();
                    associated_map_object = fixed_body.MapObject;
                    colour = fixed_body.orbit == null
                     ? XKCDColors.SunshineYellow
                     : fixed_body.orbitDriver.Renderer.nodeColor;
                    break;

                case MapObject.ObjectType.ApproachIntersect:
                    associated_map_object = reference_frame.target.mapObject;
                    colour = XKCDColors.Chartreuse;
                    break;

                case MapObject.ObjectType.AscendingNode:
                case MapObject.ObjectType.DescendingNode:
                    if (reference_frame.Centre() == null)
                    {
                        // In two-body frames, if apsides are shown, they are shown with the
                        // colour of the secondary (or in XKCD chartreuse if the secondary is
                        // a vessel).
                        // The nodes are with respect to the orbit of the secondary around the
                        // primary. We show the nodes with the colour of the primary.
                        CelestialBody primary = reference_frame.OrientingBody();
                        associated_map_object = primary.MapObject;
                        colour = primary.orbit == null
                        ? XKCDColors.SunshineYellow
                        : primary.orbitDriver.Renderer.nodeColor;
                    }
                    else
                    {
                        // In one-body frames, the apsides are shown with the colour of the
                        // body.
                        // The nodes are with respect to the equator, rather than with respect
                        // to an orbit. We show the nodes in a different (but arbitrary)
                        // colour so that they can be distinguished easily.
                        associated_map_object = reference_frame.Centre().MapObject;
                        colour = XKCDColors.Chartreuse;
                    }
                    break;

                default:
                    throw Log.Fatal($"Unexpected type {provenance.type}");
                }
                colour.a = 1;

                for (int i = 0;
                     i < MaxNodesPerProvenance && !apsis_iterator.IteratorAtEnd();
                     ++i, apsis_iterator.IteratorIncrement())
                {
                    QP apsis = apsis_iterator.IteratorGetDiscreteTrajectoryQP();
                    MapNodeProperties node_properties = new MapNodeProperties {
                        visible               = true,
                        object_type           = provenance.type,
                        colour                = colour,
                        reference_frame       = reference_frame,
                        world_position        = (Vector3d)apsis.q,
                        velocity              = (Vector3d)apsis.p,
                        source                = provenance.source,
                        time                  = apsis_iterator.IteratorGetDiscreteTrajectoryTime(),
                        associated_map_object = associated_map_object,
                    };
                    if (provenance.type == MapObject.ObjectType.Periapsis &&
                        reference_frame.Centre().GetAltitude(
                            node_properties.world_position) < 0)
                    {
                        node_properties.object_type = MapObject.ObjectType.PatchTransition;
                        node_properties.colour      = XKCDColors.Orange;
                    }

                    if (pool.nodes_used == pool.nodes.Count)
                    {
                        pool.nodes.Add(MakePoolNode());
                    }
                    properties_[pool.nodes[pool.nodes_used++]] = node_properties;
                }
            }