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

Fix a timewarp kraken, add MNA and ArgPe to simulation GUI options, and some other various simulation GUI changes #2494

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Source/RP0/SpaceCenter/SimulationParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public CelestialBody SimulationBody
public bool SimulateInOrbit, DisableFailures;
public bool IsVesselMoved;
[Persistent]
public double SimulationUT, SimOrbitAltitude, SimOrbitPe, SimOrbitAp, SimInclination, SimLAN;
public double SimulationUT, SimOrbitAltitude, SimOrbitPe, SimOrbitAp, SimInclination, SimLAN, SimMNA, SimArgPe;
[Persistent]
public int DelayMoveSeconds;

Expand Down
4 changes: 2 additions & 2 deletions Source/RP0/SpaceCenter/SpaceCenterManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ private static IEnumerator SetSimOrbit(SimulationParams simParams)
double sma = simParams.SimOrbitAltitude + body.Radius;
double ecc = 0.0000001; // Just a really smol value to prevent Ap and Pe from flickering around
RP0Debug.Log($"Moving vessel to orbit. {body.bodyName}:{simParams.SimOrbitAltitude}:{simParams.SimInclination}");
FlightGlobals.fetch.SetShipOrbit(body.flightGlobalsIndex, ecc, sma, simParams.SimInclination, simParams.SimLAN, 0.0, 0.0, 0.0);
FlightGlobals.fetch.SetShipOrbit(body.flightGlobalsIndex, ecc, sma, simParams.SimInclination, simParams.SimLAN, simParams.SimMNA, simParams.SimArgPe, 0.0); // selBodyIndex, ecc, sma, inc, LAN, mna, argPe, ObT
FloatingOrigin.ResetTerrainShaderOffset();
}
else
Expand All @@ -1311,7 +1311,7 @@ private static IEnumerator SetSimOrbit(SimulationParams simParams)
double sma = (ra + rp) / 2;
double ecc = (ra - rp) / (ra + rp);
RP0Debug.Log($"Moving vessel to orbit. {body.bodyName}:{simParams.SimOrbitPe}/{simParams.SimOrbitAp}:{simParams.SimInclination}");
FlightGlobals.fetch.SetShipOrbit(body.flightGlobalsIndex, ecc, sma, simParams.SimInclination, simParams.SimLAN, Math.PI, 0.0, 0.0);
FlightGlobals.fetch.SetShipOrbit(body.flightGlobalsIndex, ecc, sma, simParams.SimInclination, simParams.SimLAN, simParams.SimMNA, simParams.SimArgPe, 0.0); // selBodyIndex, ecc, sma, inc, LAN, mna, argPe, ObT
FloatingOrigin.ResetTerrainShaderOffset();
}
}
Expand Down
60 changes: 47 additions & 13 deletions Source/RP0/UI/KCT/GUI_Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static partial class KCT_GUI
private static Rect _simulationConfigPosition = new Rect((Screen.width / 2) - 150, (Screen.height / 4), 300, 1);
private static Vector2 _bodyChooserScrollPos;

private static string _sOrbitAlt = "", _sOrbitPe = "", _sOrbitAp = "", _sOrbitInc = "", _sOrbitLAN = "", _UTString = "", _sDelay = "0";
private static string _sOrbitAlt = "", _sOrbitPe = "", _sOrbitAp = "", _sOrbitInc = "", _sOrbitLAN = "", _sOrbitMNA = "", _sOrbitArgPe = "", _UTString = "", _sDelay = "0";
private static bool _fromCurrentUT = true;
private static bool _circOrbit = true;

Expand Down Expand Up @@ -79,16 +79,16 @@ public static void DrawSimulationConfigure(int windowID)
}
if (simParams.SimulationBody != Planetarium.fetch.Home || simParams.SimulateInOrbit)
{
_circOrbit = GUILayout.Toggle(_circOrbit, "Circular");
_circOrbit = GUILayout.Toggle(_circOrbit, " Circular");
if (_circOrbit)
{
GUILayout.BeginHorizontal();
GUILayout.Label("Orbit Altitude (km): ");
_sOrbitAlt = GUILayout.TextField(_sOrbitAlt, GUILayout.Width(100));
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Min: " + simParams.SimulationBody.atmosphereDepth / 1000);
GUILayout.Label("Max: " + Math.Floor((simParams.SimulationBody.sphereOfInfluence - simParams.SimulationBody.Radius) / 1000));
GUILayout.Label("Min: " + simParams.SimulationBody.atmosphereDepth / 1000 + "km");
GUILayout.Label("Max: " + Math.Floor((simParams.SimulationBody.sphereOfInfluence - simParams.SimulationBody.Radius) / 1000) + "km");
GUILayout.EndHorizontal();
}
else
Expand All @@ -109,33 +109,50 @@ public static void DrawSimulationConfigure(int windowID)
if (simParams.SimulateInOrbit)
{
GUILayout.BeginHorizontal();
GUILayout.Label("Delay: (s)");
GUILayout.Label("Delay (s): ");
_sDelay = GUILayout.TextField(_sDelay, 3, GUILayout.Width(40));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Inclination: ");
GUILayout.Label("Inclination (degrees): ");
_sOrbitInc = GUILayout.TextField(_sOrbitInc, GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("LAN: ");
GUILayout.Label("LAN (degrees): ");
_sOrbitLAN = GUILayout.TextField(_sOrbitLAN, GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Mean Anomaly (radians): ");
_sOrbitMNA = GUILayout.TextField(_sOrbitMNA, GUILayout.Width(50));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Argument of Periapsis (degrees): ");
_sOrbitArgPe = GUILayout.TextField(_sOrbitArgPe, GUILayout.Width(50));
GUILayout.EndHorizontal();
}

GUILayout.Space(4);
GUILayout.BeginHorizontal();
GUILayout.Label("Time: ");
_UTString = GUILayout.TextField(_UTString, GUILayout.Width(110));
_fromCurrentUT = GUILayout.Toggle(_fromCurrentUT, new GUIContent(" From Now", "If selected the game will warp forwards by the amount of time entered onto the field. Otherwise the date and time will be set to entered value."));
_fromCurrentUT = GUILayout.Toggle(_fromCurrentUT, new GUIContent(" From Now", "If selected the game will warp forwards by the entered value. Otherwise the date and time will be set to the entered value."));
GUILayout.EndHorizontal();
GUILayout.Label("Accepts values with format \"1y 2d 3h 4m 5s\" or \"1960-12-31 23:59\"");
if (_fromCurrentUT)
{
GUILayout.Label("Valid formats: \"1y 2d 3h 4m 5s\" and \"31719845\".");
}
else
{
GUILayout.Label("Valid formats: \"1y 2d 3h 4m 5s\", \"31719845\", and \"1960-12-31 23:59:59\".");
}
GUILayout.Space(4);

if (ModUtils.IsTestFlightInstalled || ModUtils.IsTestLiteInstalled)
{
simParams.DisableFailures = !GUILayout.Toggle(!simParams.DisableFailures, " Enable Part Failures");
simParams.DisableFailures = !GUILayout.Toggle(!simParams.DisableFailures, " Enable Part Failures (TestFlight or TestLite)");
GUILayout.Space(4);
}

Expand Down Expand Up @@ -234,17 +251,34 @@ private static void StartSim(SimulationParams simParams)
simParams.SimLAN = 0;
else
simParams.SimLAN %= 360;

if (!double.TryParse(_sOrbitMNA, out simParams.SimMNA))
simParams.SimMNA = Math.PI; // this will set it at apoapsis, good for safety
else
simParams.SimMNA %= 2 * Math.PI;

if (!double.TryParse(_sOrbitArgPe, out simParams.SimArgPe))
simParams.SimArgPe = 0;
else
simParams.SimArgPe %= 360;
}

double currentUT = Planetarium.GetUniversalTime();
double ut = 0;
if (!string.IsNullOrWhiteSpace(_UTString) && !ROUtils.DTUtils.TryParseTimeString(_UTString, isTimespan: !_fromCurrentUT, out ut))
if (_fromCurrentUT && (_UTString.Contains("-") || _UTString.Contains(":"))) // prevent the user from doing 1960-12-31, accidentally selecting "From Now", and then warping 1960 years forward
{
var message = new ScreenMessage("Value must be of format \"1y 2d 3h 4m 5s\" or \"31719845\" when \"From Now\" is selected.", 6f, ScreenMessageStyle.UPPER_CENTER);
ScreenMessages.PostScreenMessage(message);
return;
}
else if (!string.IsNullOrWhiteSpace(_UTString) &&
((_UTString.Contains(":") && !System.Text.RegularExpressions.Regex.IsMatch(_UTString, @"^\d{4}-\d{2}-\d{2}")) ||
!ROUtils.DTUtils.TryParseTimeString(_UTString, isTimespan: !_fromCurrentUT, out ut))) // if string is not empty and ((string has HH:mm but no YYYY-MM-DD) or (string fails TryParseTimeString)), then output failure
{
var message = new ScreenMessage("Please enter a valid time value.", 6f, ScreenMessageStyle.UPPER_CENTER);
ScreenMessages.PostScreenMessage(message);
return;
}

simParams.DelayMoveSeconds = 0;
if (_fromCurrentUT)
{
Expand Down Expand Up @@ -310,7 +344,7 @@ private static double EnsureSafeMaxAltitude(double altitudeMeters, CelestialBody

private static double GetDefaultAltitudeForBody(CelestialBody body)
{
return body.atmosphere ? body.atmosphereDepth + 20000 : 20000;
return body.atmosphere ? body.atmosphereDepth + 5000 : 20000;
}
}
}