Skip to content

Commit

Permalink
Fix a timewarp kraken, add MNA and ArgPe to simulation GUI options, a…
Browse files Browse the repository at this point in the history
…nd some other various simulation GUI changes (#2494)

* tell user that they can input seconds in the simulation datetime

since DateTime can ofc handle seconds

* avoid timewarp kraken

* also remind users of allowing time in seconds

who would use this?

* Update GUI_Simulation.cs

* Update GUI_Simulation.cs

* prevent user from inputting exact date and time when "From Now" is selected

* Update GUI_Simulation.cs

* add small buffer to default sim orbit altitude

especially a problem with principia

* add mean anomaly and argument of periapsis to simulation gui

is that some good code siimav? ill be stealing that, thank you very much

* Update SimulationParams.cs

* Update SpaceCenterManagement.cs

* Update SimulationParams.cs

* change ArgPE to ArgPe

its argPe in the docs so this is a little better

* misc changes

* fix logic

previously, it was doing:
if (!whitespace and (contains ":" and does not have date format)) OR fails parse

now its doing:
if !whitespace and ((contains ":" and does not have date format) OR fails parse)

this should correctly allow for whitespaces

* cut tip text down, as it was overrunning the box

* change default height above atmosphere orbit to be 5000 instead of 20000

if we already tell the user what the minimum value is, then we dont need to set them so high above the atmosphere, as this could just be confusing. 5000 is more than high enough to counteract principia shenanigans, while still allowing the user to be in a low orbit by default

* change position of "(s)" in delay, add "km" to min and max

* increase width of info box?

does this even work?

* revert previous change

just increases the size of the simulation config box, not the tooltip
  • Loading branch information
Clayell authored Feb 15, 2025
1 parent faa39b9 commit ea0f7ca
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
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;
}
}
}

0 comments on commit ea0f7ca

Please sign in to comment.