Exemple #1
0
        private static IEnumerable <bool> ComputeTrajectoryIncrement()
        {
            // create or update aerodynamic model
            if (aerodynamicModel_ == null || !aerodynamicModel_.IsValidFor(Trajectories.AttachedVessel.mainBody))
            {
                aerodynamicModel_ = AerodynamicModelFactory.GetModel(Trajectories.AttachedVessel.mainBody);
            }
            else
            {
                aerodynamicModel_.IncrementalUpdate();
            }

            // create new VesselState from vessel, or null if it's on the ground
            VesselState state = Trajectories.AttachedVessel.LandedOrSplashed ? null : new VesselState(Trajectories.AttachedVessel);

            // iterate over patches until MaxPatchCount is reached
            for (int patchIdx = 0; patchIdx < Settings.MaxPatchCount; ++patchIdx)
            {
                // stop if we don't have a vessel state
                if (state == null)
                {
                    break;
                }

                // If we spent more time in this calculation than allowed, pause until the next frame
                if (incrementTime_.ElapsedMilliseconds > MaxIncrementTime)
                {
                    yield return(false);
                }

                // if we have a patched conics solver, check for maneuver nodes
                if (null != Trajectories.AttachedVessel.patchedConicSolver)
                {
                    // search through maneuver nodes of the vessel
                    List <ManeuverNode> maneuverNodes = Trajectories.AttachedVessel.patchedConicSolver.maneuverNodes;
                    foreach (ManeuverNode node in maneuverNodes)
                    {
                        // if the maneuver node time corresponds to the end time of the last patch
                        if (node.UT == state.Time)
                        {
                            // add the velocity change of the burn to the velocity of the last patch
                            state.Velocity += node.GetBurnVector(CreateOrbitFromState(state));
                            break;
                        }
                    }

                    // Add one patch, then pause execution after every patch
                    foreach (bool result in AddPatch(state))
                    {
                        yield return(false);
                    }
                }

                state = AddPatch_outState;
            }
        }
        private IEnumerable <bool> computeTrajectoryIncrement(Vessel vessel, DescentProfile profile)
        {
            if (aerodynamicModel_ == null || !aerodynamicModel_.isValidFor(vessel, vessel.mainBody))
            {
                aerodynamicModel_ = AerodynamicModelFactory.GetModel(vessel, vessel.mainBody);
            }
            else
            {
                aerodynamicModel_.IncrementalUpdate();
            }

            var state = vessel.LandedOrSplashed ? null : new VesselState(vessel);

            for (int patchIdx = 0; patchIdx < Settings.fetch.MaxPatchCount; ++patchIdx)
            {
                if (state == null)
                {
                    break;
                }

                if (incrementTime_.ElapsedMilliseconds > MaxIncrementTime)
                {
                    yield return(false);
                }

                if (null != vessel_.patchedConicSolver)
                {
                    var maneuverNodes = vessel_.patchedConicSolver.maneuverNodes;
                    foreach (var node in maneuverNodes)
                    {
                        if (node.UT == state.time)
                        {
                            state.velocity += node.GetBurnVector(createOrbitFromState(state));
                            break;
                        }
                    }
                    foreach (var result in AddPatch(state, profile))
                    {
                        yield return(false);
                    }
                }

                state = AddPatch_outState;
            }
        }
        internal void ComputeTrajectory()
        {
            if (!VesselHasParts)// || AttachedVessel.LandedOrSplashed)
            {
                increment_time = 0d;
                Patches.Clear();
                return;
            }

            try
            {
                // start of trajectory calculation in current frame
                increment_time = Util.Clocks;

                // create or update aerodynamic model
                if (aerodynamicModel_ == null || !aerodynamicModel_.IsValidFor(AttachedVessel.mainBody))
                {
                    aerodynamicModel_ = AerodynamicModelFactory.GetModel(this, AttachedVessel.mainBody);
                }
                else
                {
                    aerodynamicModel_.UpdateVesselMass();
                }

                // if there is no ongoing partial computation, start a new one
                if (partialComputation_ == null)
                {
                    //total_time = Util.Clocks;

                    // restart the public buffers
                    patchesBackBuffer_.Clear();
                    maxAccelBackBuffer_ = 0;

                    // Create enumerator for Trajectory increment calculator
                    partialComputation_ = ComputeTrajectoryIncrement().GetEnumerator();
                }

                // we are finished when there are no more partial computations to be done
                bool finished = !partialComputation_.MoveNext();

                // when calculation is finished,
                if (finished)
                {
                    // swap the buffers for the patches and the maximum acceleration,
                    // "publishing" the results
                    List <Patch> tmp = Patches;
                    Patches            = patchesBackBuffer_;
                    patchesBackBuffer_ = tmp;

                    MaxAccel = maxAccelBackBuffer_;

                    // Reset partial computation
                    partialComputation_.Dispose();
                    partialComputation_ = null;

                    // how long did the whole calculation take?
                    //total_time = Util.ElapsedMilliseconds(total_time);
                }

                // how long did the calculation in this frame take?
                increment_time = Util.ElapsedMilliseconds(increment_time);
            }
            catch (Exception)
            {
                ++ErrorCount;
                throw;
            }
        }