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

Support for collisions in the flight plan #3859

Merged
merged 2 commits into from
Jan 28, 2024
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
49 changes: 46 additions & 3 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,8 @@ select PartCentredForceHolder.
}
}

private TQP? RenderedCollision(string vessel_guid, CelestialBody centre) {
private TQP? RenderedPredictionCollision(string vessel_guid,
CelestialBody centre) {
var executor = plugin_.CollisionNewPredictionExecutor(
celestial_index: centre.flightGlobalsIndex,
sun_world_position: (XYZ)Planetarium.fetch.Sun.position,
Expand All @@ -2321,6 +2322,34 @@ select PartCentredForceHolder.
}
}

private TQP? RenderedFlightPlanCollision(string vessel_guid,
CelestialBody centre) {
var executor = plugin_.CollisionNewFlightPlanExecutor(
celestial_index: centre.flightGlobalsIndex,
sun_world_position: (XYZ)Planetarium.fetch.Sun.position,
// TODO(phl): This should be much larger, if it is limited at all.
max_points: MapNodePool.MaxNodesPerProvenance,
vessel_guid: vessel_guid);

for (;;) {
bool more = executor.CollisionGetLatitudeLongitude(
out double trial_latitude,
out double trial_longitude);
if (!more) {
if (plugin_.CollisionDeleteExecutor(ref executor, out TQP collision)) {
return collision;
} else {
return null;
}
}
executor.CollisionSetRadius(centre.TerrainAltitude(
trial_latitude,
trial_longitude,
allowNegative: !centre.ocean) +
centre.Radius);
}
}

private void RenderPredictionMarkers(string vessel_guid,
XYZ sun_world_position) {
if (plotting_frame_selector_.target_frame_selected &&
Expand Down Expand Up @@ -2360,7 +2389,7 @@ out DisposableIterator
var centre = plotting_frame_selector_.Centre();
var centre_index = centre.flightGlobalsIndex;
if (plotting_frame_selector_.IsSurfaceFrame()) {
TQP? collision = RenderedCollision(vessel_guid, centre);
TQP? collision = RenderedPredictionCollision(vessel_guid, centre);
if (collision.HasValue) {
map_node_pool_.RenderMarkers(new[] {collision.Value },
new MapNodePool.Provenance(
Expand Down Expand Up @@ -2451,7 +2480,21 @@ out DisposableIterator
plotting_frame_selector_);
} else {
if (plotting_frame_selector_.Centre() != null) {
var centre_index = plotting_frame_selector_.Centre().flightGlobalsIndex;
var centre = plotting_frame_selector_.Centre();
var centre_index = centre.flightGlobalsIndex;
if (plotting_frame_selector_.IsSurfaceFrame()) {
TQP? collision = RenderedFlightPlanCollision(vessel_guid, centre);
if (collision.HasValue) {
map_node_pool_.RenderMarkers(new[] {collision.Value },
new MapNodePool.Provenance(
vessel_guid,
MapNodePool.NodeSource.
FlightPlan,
MapObject.ObjectType.
PatchTransition),
plotting_frame_selector_);
}
}
plugin_.FlightPlanRenderedApsides(vessel_guid,
centre_index,
sun_world_position,
Expand Down
38 changes: 9 additions & 29 deletions ksp_plugin_adapter/map_node_pool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,6 @@ public class SingleProvenancePool {
time = marker.t,
associated_map_object = associated_map_object,
};
if (provenance.type == MapObject.ObjectType.Periapsis) {
var centre = reference_frame.Centre();
if (provenance.source == NodeSource.FlightPlan ||
!reference_frame.IsSurfaceFrame()) {
// TODO(phl): For the flight plan, preserve the old behaviour for now.
// Also, the terrain-based markers only make sense for the surface
// frame.
if (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());
Expand Down Expand Up @@ -314,25 +301,18 @@ public class SingleProvenancePool {
source,
celestial.GetAltitude(position).FormatN(0));
caption.captionLine1 = "";
// TODO(phl): Add support for the flight plan.
if (properties.source == NodeSource.Prediction) {
caption.captionLine2 = L10N.CacheFormat(
"#Principia_MapNode_ImpactCaptionLine2",
speed.FormatN(0));
} else {
caption.captionLine2 = "";
}
caption.captionLine2 = L10N.CacheFormat(
"#Principia_MapNode_ImpactCaptionLine2",
speed.FormatN(0));
break;
}
}
// TODO(phl): Add support for the flight plan.
if (properties.object_type != MapObject.ObjectType.PatchTransition ||
properties.source == NodeSource.Prediction) {
caption.captionLine1 =
"T" + new PrincipiaTimeSpan(
Planetarium.GetUniversalTime() - properties.time).
Format(with_leading_zeroes: false, with_seconds: true);
}
caption.captionLine1 = "T" +
new PrincipiaTimeSpan(
Planetarium.GetUniversalTime() -
properties.time).
Format(with_leading_zeroes: false,
with_seconds: true);
// The font used by map nodes does not support the minus sign, so we
// fall back to the hyphen-minus.
string minus = Culture.culture.NumberFormat.NegativeSign;
Expand Down
Loading