diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 96c2552..c301143 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,16 +65,18 @@ jobs: - name: Build Mod run: dotnet build -c Release - working-directory: ${{ env.PROJ_NAME }} - name: Upload Artifact uses: "actions/upload-artifact@v3" with: name: "${{ env.PROJ_USERNAME }}.${{ env.PROJ_NAME }}" - path: "${{ env.PROJ_USERNAME }}.${{ env.PROJ_NAME }}" + path: ${{ env.PROJ_NAME }}/bin/Release/ + + - name: Move + run: mkdir ${{ env.PROJ_USERNAME }}.${{ env.PROJ_NAME }}; move ./${{ env.PROJ_NAME }}/bin/Release/* ${{ env.PROJ_USERNAME }}.${{ env.PROJ_NAME }} - name: Zip For Release - run: 7z a ${{ env.PROJ_USERNAME }}.${{ env.PROJ_NAME }}.zip ${{ env.PROJ_NAME }}/bin/Release/** + run: 7z a ${{ env.PROJ_USERNAME }}.${{ env.PROJ_NAME }}.zip ${{ env.PROJ_USERNAME }}.${{ env.PROJ_NAME }}** - name: Create Release uses: "ncipollo/release-action@v1" diff --git a/README.md b/README.md index b5a19fa..bd6cc11 100644 --- a/README.md +++ b/README.md @@ -17,18 +17,20 @@ This is a mod for **Outer Wilds** which predicts and visualizes future trajector ## Settings ![Settings](https://user-images.githubusercontent.com/45887963/202139282-0c378a33-0c12-4907-99e4-c98604dcabe1.jpg) -##### Simulation Settings +#### Simulation Settings - **Seconds To Predict** - Determines how far into the future trajectories are predicted in seconds. Higher values take longer to compute. - **High Precision Mode** - Toggles simulation time step between 1 second and `Time.fixedDeltaTime`. High Precision Mode takes 60 times longer to compute. - **Predict GravityVolume Intersections** - Future trajectories may escape or enter gravity volumes of different celestial bodies. This setting toggles detection of which gravity volumes will be active at any given future time step. Takes longer to compute and allocates more memory. -##### Customization Settings +#### Customization Settings - **Player Trajectory Color** - Hex RGBA color of trajectory line of the player. - **Ship Trajectory Color** - Hex RGBA color of trajectory line of the ship. - **Scout Trajectory Color** - Hex RGBA color of trajectory line of the scout. -##### Performance Settings +- **Display Planet Trajectories** - Determines whether planet trajectories should be displayed. +- **Planet Trajectory Color** - Hex RGBA color of trajectory lines of the planets. +#### Performance Settings - **Multithreading** - Shifts computations to a separate thread. - **RAM To Allocate (Megabytes)** - Allocates roughly specified amount of RAM to reduce the frequency of GC lag spikes. -##### Experimental Settings +#### Experimental Settings - **Parallelization** - Runs simulation of all celestial bodies in parallel. Speeds up computation but makes results inaccurate. ## Limitations / Things to Improve diff --git a/TrajectoryPrediction/AstroObjectTrajectory.cs b/TrajectoryPrediction/AstroObjectTrajectory.cs index 10feebf..c9cbf16 100644 --- a/TrajectoryPrediction/AstroObjectTrajectory.cs +++ b/TrajectoryPrediction/AstroObjectTrajectory.cs @@ -1,25 +1,32 @@ using System; +using System.Threading; using UnityEngine; namespace TrajectoryPrediction; -public class AstroObjectTrajectory : MonoBehaviour +public class AstroObjectTrajectory : MonoBehaviour, ITrajectory { + public bool Busy { get; private set; } + public Vector3[] Trajectory { get; private set; } + public Vector3[] TrajectoryCache { get; private set; } private AstroObject _astroObject; private OWRigidbody _body; private GravityVolume _gravityVolume; private float _triggerRadius; private bool _updatedThisFrame; - private Vector3[] _trajectory; - private Vector3[] _trajectoryCache; private Vector3 _framePosition; private Vector3 _frameVelocity; + private TrajectoryVisualizer _visualizer; private void Start() { _astroObject = GetComponent(); _body = _astroObject.GetOWRigidbody(); _gravityVolume = _astroObject.GetGravityVolume(); + + if (_gravityVolume) + _visualizer = gameObject.AddComponent(); + TrajectoryPrediction.AstroObjectToTrajectoryMap[_astroObject] = this; if (_gravityVolume) { @@ -55,8 +62,15 @@ private void OnDestroy() private void ApplyConfig() { - _trajectory = new Vector3[TrajectoryPrediction.StepsToSimulate]; - _trajectoryCache = new Vector3[TrajectoryPrediction.StepsToSimulate]; + Trajectory = new Vector3[TrajectoryPrediction.StepsToSimulate]; + TrajectoryCache = new Vector3[TrajectoryPrediction.StepsToSimulate]; + Busy = false; + + if (_visualizer) + { + _visualizer.SetVisibility(TrajectoryPrediction.DisplayPlanetTrajectories); + _visualizer.SetColor(TrajectoryPrediction.PlanetTrajectoriesColor); + } } private void BeginFrame() @@ -73,10 +87,10 @@ private void BeginFrame() private void EndFrame() { - _trajectory.CopyTo(_trajectoryCache); + Trajectory.CopyTo(TrajectoryCache); } - internal void UpdateTrajectory() + public void UpdateTrajectory() { if (_updatedThisFrame) return; @@ -85,26 +99,34 @@ internal void UpdateTrajectory() if (_body == null || _body.GetAttachedForceDetector() == null) { - for (var i = 0; i < _trajectory.Length; i++) - _trajectory[i] = _astroObject.transform.position; + for (var i = 0; i < Trajectory.Length; i++) + Trajectory[i] = _astroObject.transform.position; } else { - if (TrajectoryPrediction.Parallelization) - TrajectoryPrediction.SimulateTrajectoryMultiThreaded(_body, _framePosition, _frameVelocity, _trajectory); + if (TrajectoryPrediction.Parallelization || TrajectoryPrediction.Multithreading && Thread.CurrentThread == TrajectoryPrediction.MainThread) + { + Busy = true; + TrajectoryPrediction.SimulateTrajectoryMultiThreaded(_body, _framePosition, _frameVelocity, Trajectory, null, false, false, () => Busy = false); + } else - TrajectoryPrediction.SimulateTrajectory(_body, _framePosition, _frameVelocity, _trajectory); + TrajectoryPrediction.SimulateTrajectory(_body, _framePosition, _frameVelocity, Trajectory); } } + public Vector3 GetCurrentPosition() + { + return _body ? _body.GetPosition() : _astroObject.transform.position; + } + public Vector3 GetFuturePosition(int step) { - return _trajectory[Math.Max(step, 0)]; + return Trajectory[Math.Max(step, 0)]; } - + public Vector3 GetFuturePositionCached(int step) { - return _trajectoryCache[Math.Max(step, 0)]; + return TrajectoryCache[Math.Max(step, 0)]; } public GravityVolume GetGravityVolume() diff --git a/TrajectoryPrediction/CanvasMapMarkerPatch.cs b/TrajectoryPrediction/CanvasMapMarkerPatch.cs index f7ba623..83ebb8c 100644 --- a/TrajectoryPrediction/CanvasMapMarkerPatch.cs +++ b/TrajectoryPrediction/CanvasMapMarkerPatch.cs @@ -11,6 +11,6 @@ public class CanvasMapMarkerPatch private static void MapMarker_InitMarker(MapMarker __instance) { if (__instance._markerType is MapMarker.MarkerType.Ship or MapMarker.MarkerType.Probe or MapMarker.MarkerType.Player) - __instance._canvasMarker.gameObject.AddComponent().SetMarkerType(__instance._markerType); + __instance._canvasMarker.gameObject.AddComponent().SetMarkerType(__instance._markerType); } } \ No newline at end of file diff --git a/TrajectoryPrediction/Extensions.cs b/TrajectoryPrediction/Extensions.cs index b90d0f7..1563944 100644 --- a/TrajectoryPrediction/Extensions.cs +++ b/TrajectoryPrediction/Extensions.cs @@ -12,12 +12,12 @@ public static Vector3 CalculateForceAccelerationAtFuturePoint(this GravityVolume return delta / distance * gravityMagnitude; } - public static AstroObjectTrajectory GetTrajectory(this GravityVolume gravityVolume) + public static ITrajectory GetTrajectory(this GravityVolume gravityVolume) { return TrajectoryPrediction.GravityVolumeToTrajectoryMap.ContainsKey(gravityVolume) ? TrajectoryPrediction.GravityVolumeToTrajectoryMap[gravityVolume] : null; } - public static AstroObjectTrajectory GetTrajectory(this AstroObject astroObject) + public static ITrajectory GetTrajectory(this AstroObject astroObject) { return TrajectoryPrediction.AstroObjectToTrajectoryMap.ContainsKey(astroObject) ? TrajectoryPrediction.AstroObjectToTrajectoryMap[astroObject] : null; } diff --git a/TrajectoryPrediction/ITrajectory.cs b/TrajectoryPrediction/ITrajectory.cs new file mode 100644 index 0000000..60cf219 --- /dev/null +++ b/TrajectoryPrediction/ITrajectory.cs @@ -0,0 +1,14 @@ +using UnityEngine; + +namespace TrajectoryPrediction; + +public interface ITrajectory +{ + bool Busy { get; } + Vector3[] Trajectory { get; } + Vector3[] TrajectoryCache { get; } + void UpdateTrajectory(); + Vector3 GetCurrentPosition(); + Vector3 GetFuturePosition(int step); + Vector3 GetFuturePositionCached(int step); +} \ No newline at end of file diff --git a/TrajectoryPrediction/MapMarkerTrajectory.cs b/TrajectoryPrediction/MapMarkerTrajectory.cs new file mode 100644 index 0000000..83d8a38 --- /dev/null +++ b/TrajectoryPrediction/MapMarkerTrajectory.cs @@ -0,0 +1,162 @@ +using System; +using System.Linq; +using System.Threading; +using UnityEngine; + +namespace TrajectoryPrediction; + +public class MapMarkerTrajectory : MonoBehaviour, ITrajectory +{ + public bool Busy { get; private set; } + public Vector3[] Trajectory { get; private set; } + public Vector3[] TrajectoryCache { get; private set; } + private CanvasMapMarker _marker; + private MapMarker.MarkerType _markerType; + private OWRigidbody _body; + private ForceDetector _forceDetector; + private bool _updatedThisFrame; + private Vector3 _framePosition; + private Vector3 _frameVelocity; + private TrajectoryVisualizer _visualizer; + + private void Start() + { + _marker = GetComponent(); + _body = _marker._rigidbodyTarget; + _forceDetector = _body.GetAttachedForceDetector(); + _visualizer = gameObject.AddComponent(); + ApplyConfig(); + + TrajectoryPrediction.OnConfigUpdate += ApplyConfig; + TrajectoryPrediction.OnBeginFrame += BeginFrame; + TrajectoryPrediction.OnEndFrame += EndFrame; + _marker.OnMarkerChangeVisibility += SetVisibility; + + if (_markerType == MapMarker.MarkerType.Player) + { + GlobalMessenger.AddListener("EnterShip", OnEnterShip); + GlobalMessenger.AddListener("ExitShip", OnExitShip); + OnEnterShip(); + } + } + + private void OnDestroy() + { + TrajectoryPrediction.OnConfigUpdate -= ApplyConfig; + TrajectoryPrediction.OnBeginFrame -= BeginFrame; + TrajectoryPrediction.OnEndFrame -= EndFrame; + _marker.OnMarkerChangeVisibility -= SetVisibility; + + if (_markerType == MapMarker.MarkerType.Player) + { + GlobalMessenger.RemoveListener("EnterShip", OnEnterShip); + GlobalMessenger.RemoveListener("ExitShip", OnExitShip); + } + } + + internal void SetMarkerType(MapMarker.MarkerType markerType) + { + _markerType = markerType; + } + + private void SetVisibility(bool value) + { + _visualizer.SetVisibility(value); + } + + private void ApplyConfig() + { + Trajectory = new Vector3[TrajectoryPrediction.StepsToSimulate]; + TrajectoryCache = new Vector3[TrajectoryPrediction.StepsToSimulate]; + Busy = false; + switch (_markerType) + { + case MapMarker.MarkerType.Player: + _visualizer.SetColor(TrajectoryPrediction.PlayerTrajectoryColor); + break; + case MapMarker.MarkerType.Ship: + _visualizer.SetColor(TrajectoryPrediction.ShipTrajectoryColor); + break; + case MapMarker.MarkerType.Probe: + _visualizer.SetColor(TrajectoryPrediction.ScoutTrajectoryColor); + break; + default: + throw new ArgumentOutOfRangeException(nameof(_markerType)); + } + } + + private void BeginFrame() + { + _updatedThisFrame = false; + _framePosition = _body.GetPosition(); + _frameVelocity = _body.GetVelocity(); + } + + private void EndFrame() + { + Trajectory.CopyTo(TrajectoryCache); + } + + private void OnEnterShip() + { + _body = Locator.GetShipBody(); + _forceDetector = _body.GetAttachedForceDetector(); + } + + private void OnExitShip() + { + _body = Locator.GetPlayerBody(); + _forceDetector = _body.GetAttachedForceDetector(); + } + + public void UpdateTrajectory() + { + if (_updatedThisFrame) + return; + + _updatedThisFrame = true; + + if (_forceDetector._activeVolumes.Count == 0 || _forceDetector._activeVolumes.All(volume => volume is not GravityVolume)) + { + if (TrajectoryPrediction.Multithreading) + { + Busy = true; + new Thread(() => + { + for (var i = 0; i < Trajectory.Length; i++) + Trajectory[i] = Vector3.zero; + + Busy = false; + }).Start(); + } + else + for (var i = 0; i < Trajectory.Length; i++) + Trajectory[i] = _framePosition; + } + else + { + if (TrajectoryPrediction.Multithreading) + { + Busy = true; + TrajectoryPrediction.SimulateTrajectoryMultiThreaded(_body, _framePosition, _frameVelocity, Trajectory, Locator.GetReferenceFrame()?.GetAstroObject(), true, TrajectoryPrediction.PredictGravityVolumeIntersections, () => Busy = false); + } + else + TrajectoryPrediction.SimulateTrajectory(_body, _framePosition, _frameVelocity, Trajectory, Locator.GetReferenceFrame()?.GetAstroObject(), true, TrajectoryPrediction.PredictGravityVolumeIntersections); + } + } + + public Vector3 GetCurrentPosition() + { + return _body.GetPosition(); + } + + public Vector3 GetFuturePosition(int step) + { + return Trajectory[Math.Max(step, 0)]; + } + + public Vector3 GetFuturePositionCached(int step) + { + return TrajectoryCache[Math.Max(step, 0)]; + } +} \ No newline at end of file diff --git a/TrajectoryPrediction/TrajectoryPrediction.cs b/TrajectoryPrediction/TrajectoryPrediction.cs index 3e2e8c6..65dbe9a 100644 --- a/TrajectoryPrediction/TrajectoryPrediction.cs +++ b/TrajectoryPrediction/TrajectoryPrediction.cs @@ -20,16 +20,20 @@ public class TrajectoryPrediction : ModBehaviour public static Color PlayerTrajectoryColor { get; private set; } public static Color ShipTrajectoryColor { get; private set; } public static Color ScoutTrajectoryColor { get; private set; } + public static bool DisplayPlanetTrajectories { get; private set; } + public static Color PlanetTrajectoriesColor { get; private set; } + public static bool Multithreading { get; private set; } public static int RAMToAllocate { get; private set; } public static bool Parallelization { get; private set; } - + internal static Thread MainThread { get; private set; } + public static event Action OnConfigUpdate; public static event Action OnBeginFrame; public static event Action OnEndFrame; - internal static readonly Dictionary AstroObjectToTrajectoryMap = new(); - internal static readonly Dictionary GravityVolumeToTrajectoryMap = new(); + internal static readonly Dictionary AstroObjectToTrajectoryMap = new(); + internal static readonly Dictionary GravityVolumeToTrajectoryMap = new(); private static readonly List AstroObjectTrajectories = new(); private static readonly List TrajectoryVisualizers = new(); private static readonly List BusyBodies = new(); @@ -39,6 +43,7 @@ public class TrajectoryPrediction : ModBehaviour private void Awake() { + MainThread = Thread.CurrentThread; Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly()); GlobalMessenger.AddListener("EnterMapView", OnEnterMapView); GlobalMessenger.AddListener("ExitMapView", OnExitMapView); @@ -69,6 +74,8 @@ public override void Configure(IModConfig config) PlayerTrajectoryColor = ColorUtility.TryParseHtmlString(config.GetSettingsValue("Player Trajectory Color"), out var playerTrajectoryColor) ? playerTrajectoryColor : Color.cyan; ShipTrajectoryColor = ColorUtility.TryParseHtmlString(config.GetSettingsValue("Ship Trajectory Color"), out var shipTrajectoryColor) ? shipTrajectoryColor : Color.yellow; ScoutTrajectoryColor = ColorUtility.TryParseHtmlString(config.GetSettingsValue("Scout Trajectory Color"), out var scoutTrajectoryColor) ? scoutTrajectoryColor : Color.white; + DisplayPlanetTrajectories = config.GetSettingsValue("Display Planet Trajectories"); + PlanetTrajectoriesColor = ColorUtility.TryParseHtmlString(config.GetSettingsValue("Planet Trajectories Color"), out var planetTrajectoryColor) ? planetTrajectoryColor : Color.white; Multithreading = config.GetSettingsValue("Multithreading"); RAMToAllocate = Math.Max(config.GetSettingsValue("RAM To Allocate (Megabytes)"), 0); Parallelization = config.GetSettingsValue("Parallelization"); @@ -154,8 +161,8 @@ public static void SimulateTrajectory(OWRigidbody body, Vector3 startingPosition if (predictVolumeIntersections) { - foreach (var astroObject in AstroObjectTrajectories) - astroObject.UpdateTrajectory(); + foreach (var astroObjectTrajectory in AstroObjectTrajectories) + astroObjectTrajectory.UpdateTrajectory(); } else { diff --git a/TrajectoryPrediction/TrajectoryVisualizer.cs b/TrajectoryPrediction/TrajectoryVisualizer.cs index 3d0b2ed..2e81b94 100644 --- a/TrajectoryPrediction/TrajectoryVisualizer.cs +++ b/TrajectoryPrediction/TrajectoryVisualizer.cs @@ -1,30 +1,21 @@ -using System; -using System.Linq; -using System.Threading; +using System.Linq; using UnityEngine; namespace TrajectoryPrediction; public class TrajectoryVisualizer : MonoBehaviour { - public bool Busy { get; private set; } - private CanvasMapMarker _marker; - private MapMarker.MarkerType _markerType; + public bool Busy => _trajectory.Busy; + private ITrajectory _trajectory; private LineRenderer _lineRenderer; - private OWRigidbody _body; - private ForceDetector _forceDetector; - private Vector3[] _trajectory; - private Vector3[] _trajectoryCached; private float _timeSinceUpdate; - private Vector3 _framePosition; - private Vector3 _frameVelocity; + private bool _visible = true; + private Color _color = Color.white; private static readonly int MainTex = Shader.PropertyToID("_MainTex"); private void Start() { - _marker = GetComponent(); - _body = _marker._rigidbodyTarget; - _forceDetector = _body.GetAttachedForceDetector(); + _trajectory = GetComponent(); _lineRenderer = gameObject.AddComponent(); _lineRenderer.useWorldSpace = true; var material = new Material(Shader.Find("Outer Wilds/Effects/Orbit Line")); @@ -32,21 +23,14 @@ private void Start() _lineRenderer.material = material; _lineRenderer.textureMode = LineTextureMode.RepeatPerSegment; TrajectoryPrediction.AddVisualizer(this); + UpdateVisibility(); + UpdateColor(); ApplyConfig(); GlobalMessenger.AddListener("EnterMapView", OnEnterMapView); GlobalMessenger.AddListener("ExitMapView", OnExitMapView); TrajectoryPrediction.OnConfigUpdate += ApplyConfig; TrajectoryPrediction.OnBeginFrame += BeginFrame; - TrajectoryPrediction.OnEndFrame += EndFrame; - _marker.OnMarkerChangeVisibility += SetVisibility; - - if (_markerType == MapMarker.MarkerType.Player) - { - GlobalMessenger.AddListener("EnterShip", OnEnterShip); - GlobalMessenger.AddListener("ExitShip", OnExitShip); - OnEnterShip(); - } } private void OnDestroy() @@ -56,67 +40,50 @@ private void OnDestroy() GlobalMessenger.RemoveListener("ExitMapView", OnExitMapView); TrajectoryPrediction.OnConfigUpdate -= ApplyConfig; TrajectoryPrediction.OnBeginFrame -= BeginFrame; - TrajectoryPrediction.OnEndFrame -= EndFrame; - _marker.OnMarkerChangeVisibility -= SetVisibility; + } - if (_markerType == MapMarker.MarkerType.Player) - { - GlobalMessenger.RemoveListener("EnterShip", OnEnterShip); - GlobalMessenger.RemoveListener("ExitShip", OnExitShip); - } + public void SetVisibility(bool value) + { + _visible = value; + UpdateVisibility(); + } + + private void UpdateVisibility() + { + if (!_lineRenderer) + return; + + _lineRenderer.enabled = _visible; } - internal void SetMarkerType(MapMarker.MarkerType markerType) + public void SetColor(Color color) { - _markerType = markerType; + _color = color; + UpdateColor(); } - private void SetVisibility(bool value) + private void UpdateColor() { - _lineRenderer.enabled = value; + if (!_lineRenderer) + return; + + _lineRenderer.startColor = _color; + _lineRenderer.endColor = new Color(_color.r, _color.g, _color.b, 0); } private void ApplyConfig() { - _trajectory = new Vector3[TrajectoryPrediction.StepsToSimulate]; - _trajectoryCached = new Vector3[TrajectoryPrediction.StepsToSimulate]; _lineRenderer.positionCount = TrajectoryPrediction.SecondsToPredict; - Busy = false; - switch (_markerType) - { - case MapMarker.MarkerType.Player: - _lineRenderer.startColor = TrajectoryPrediction.PlayerTrajectoryColor; - _lineRenderer.endColor = new Color(TrajectoryPrediction.PlayerTrajectoryColor.r, TrajectoryPrediction.PlayerTrajectoryColor.g, TrajectoryPrediction.PlayerTrajectoryColor.b, 0); - break; - case MapMarker.MarkerType.Ship: - _lineRenderer.startColor = TrajectoryPrediction.ShipTrajectoryColor; - _lineRenderer.endColor = new Color(TrajectoryPrediction.ShipTrajectoryColor.r, TrajectoryPrediction.ShipTrajectoryColor.g, TrajectoryPrediction.ShipTrajectoryColor.b, 0); - break; - case MapMarker.MarkerType.Probe: - _lineRenderer.startColor = TrajectoryPrediction.ScoutTrajectoryColor; - _lineRenderer.endColor = new Color(TrajectoryPrediction.ScoutTrajectoryColor.r, TrajectoryPrediction.ScoutTrajectoryColor.g, TrajectoryPrediction.ScoutTrajectoryColor.b, 0); - break; - default: - throw new ArgumentOutOfRangeException(nameof(_markerType)); - } } private void BeginFrame() { - _framePosition = _body.GetPosition(); - _frameVelocity = _body.GetVelocity(); _timeSinceUpdate = 0; } - private void EndFrame() - { - _trajectory.CopyTo(_trajectoryCached); - } - private void OnEnterMapView() { - _lineRenderer.enabled = _marker.IsVisible(); - Busy = false; + _lineRenderer.enabled = _visible; } private void OnExitMapView() @@ -124,50 +91,12 @@ private void OnExitMapView() _lineRenderer.enabled = false; } - private void OnEnterShip() - { - _body = Locator.GetShipBody(); - _forceDetector = _body.GetAttachedForceDetector(); - } - - private void OnExitShip() - { - _body = Locator.GetPlayerBody(); - _forceDetector = _body.GetAttachedForceDetector(); - } - public void Visualize() { if (!_lineRenderer.enabled) return; - if (_forceDetector._activeVolumes.Count == 0 || _forceDetector._activeVolumes.All(volume => volume is not GravityVolume)) - { - if (TrajectoryPrediction.Multithreading) - { - Busy = true; - new Thread(() => - { - for (var i = 0; i < _trajectory.Length; i++) - _trajectory[i] = Vector3.zero; - - Busy = false; - }).Start(); - } - else - for (var i = 0; i < _trajectory.Length; i++) - _trajectory[i] = _framePosition; - } - else - { - if (TrajectoryPrediction.Multithreading) - { - Busy = true; - TrajectoryPrediction.SimulateTrajectoryMultiThreaded(_body, _framePosition, _frameVelocity, _trajectory, Locator.GetReferenceFrame()?.GetAstroObject(), true, TrajectoryPrediction.PredictGravityVolumeIntersections, () => Busy = false); - } - else - TrajectoryPrediction.SimulateTrajectory(_body, _framePosition, _frameVelocity, _trajectory, Locator.GetReferenceFrame()?.GetAstroObject(), true, TrajectoryPrediction.PredictGravityVolumeIntersections); - } + _trajectory.UpdateTrajectory(); } private void Update() @@ -181,18 +110,18 @@ private void Update() for (var i = 0; i < _lineRenderer.positionCount; i++) { - int step = TrajectoryPrediction.HighPrecisionMode ? Mathf.Min((int)((i + _timeSinceUpdate) / Time.fixedDeltaTime), _trajectoryCached.Length - 1) : i; + int step = TrajectoryPrediction.HighPrecisionMode ? Mathf.Min((int)((i + _timeSinceUpdate) / Time.fixedDeltaTime), _trajectory.TrajectoryCache.Length - 1) : i; - if (_trajectoryCached[step] == Vector3.zero) + if (_trajectory.TrajectoryCache[step] == Vector3.zero) { _lineRenderer.SetPosition(i, _lineRenderer.GetPosition(Mathf.Max(0, i - 1))); continue; } - var position = _trajectoryCached[step] - referenceFrame.GetTrajectory().GetFuturePositionCached(step) + referenceFrame.GetOWRigidbody().GetPosition(); + var position = _trajectory.TrajectoryCache[step] - referenceFrame.GetTrajectory().GetFuturePositionCached(step) + referenceFrame.GetOWRigidbody().GetPosition(); _lineRenderer.SetPosition(i, position); } - _lineRenderer.widthMultiplier = Vector3.Distance(_body.GetPosition(), Locator.GetActiveCamera().transform.position) / 500f; + _lineRenderer.widthMultiplier = Vector3.Distance(_trajectory.GetCurrentPosition(), Locator.GetActiveCamera().transform.position) / 500f; } } \ No newline at end of file diff --git a/TrajectoryPrediction/default-config.json b/TrajectoryPrediction/default-config.json index a15b18b..4e44388 100644 --- a/TrajectoryPrediction/default-config.json +++ b/TrajectoryPrediction/default-config.json @@ -13,6 +13,8 @@ "Player Trajectory Color": "#00FFFFFF", "Ship Trajectory Color": "#FFFF00FF", "Scout Trajectory Color": "#FFFFFFFF", + "Display Planet Trajectories": false, + "Planet Trajectories Color": "#FFFFFFFF", "Performance Settings": { "type": "separator" }, diff --git a/TrajectoryPrediction/manifest.json b/TrajectoryPrediction/manifest.json index a9c1007..6182a99 100644 --- a/TrajectoryPrediction/manifest.json +++ b/TrajectoryPrediction/manifest.json @@ -4,7 +4,7 @@ "author": "Oleg Skutte", "name": "Trajectory Prediction", "uniqueName": "OlegSkutte.TrajectoryPrediction", - "version": "0.6.1", + "version": "0.6.2", "owmlVersion": "2.7.3", "dependencies": [] }