Ejemplo n.º 1
0
        public static SimulatedControlSurface Borrow(ModuleControlSurface module, SimulatedPart part)
        {
            SimulatedControlSurface surface = pool.Borrow();

            surface.Init(module, part);
            return(surface);
        }
Ejemplo n.º 2
0
 protected void Init(ModuleEngines engine, SimulatedPart part)
 {
     this.flameoutBar                 = engine.flameoutBar;
     this.atmChangeFlow               = engine.atmChangeFlow;
     this.useAtmCurve                 = engine.useAtmCurve;
     this.useAtmCurveIsp              = engine.useAtmCurveIsp;
     this.atmCurve                    = new FloatCurve(engine.atmCurve.Curve.keys);
     this.atmCurveIsp                 = new FloatCurve(engine.atmCurveIsp.Curve.keys);
     this.useVelCurve                 = engine.useVelCurve;
     this.useVelCurveIsp              = engine.useVelCurveIsp;
     this.velCurve                    = new FloatCurve(engine.velCurve.Curve.keys);
     this.velCurveIsp                 = new FloatCurve(engine.velCurveIsp.Curve.keys);
     this.flowMultCap                 = engine.flowMultCap;
     this.flowMultCapSharpness        = engine.flowMultCapSharpness;
     this.atmosphereCurve             = new FloatCurve(engine.atmosphereCurve.Curve.keys);
     this.useThrustCurve              = engine.useThrustCurve;
     this.thrustCurve                 = new FloatCurve(engine.thrustCurve.Curve.keys);
     this.useThrottleIspCurve         = engine.useThrottleIspCurve;
     this.throttleIspCurve            = new FloatCurve(engine.throttleIspCurve.Curve.keys);
     this.throttleIspCurveAtmStrength = new FloatCurve(engine.throttleIspCurveAtmStrength.Curve.keys);
     this.requiresOxygen              = engine.propellants.Any(propellant => propellant.name == "IntakeAir");
     this.g                = engine.g;
     this.multIsp          = engine.multIsp;
     this.maxFuelFlow      = engine.maxFuelFlow;
     this.multFlow         = engine.multFlow;
     this.thrustPercentage = engine.thrustPercentage;
     this.thrustVector     = Vector3.zero;
     for (int i = engine.thrustTransforms.Count - 1; i >= 0; i--)
     {
         this.thrustVector -= engine.thrustTransforms[i].forward * engine.thrustTransformMultipliers[i];
     }
     this.CLAMP = engine.CLAMP;
     this.stage = engine.part.inverseStage;
     this.part  = part;
 }
Ejemplo n.º 3
0
        public static SimulatedLiftingSurface Borrow(ModuleLiftingSurface module, SimulatedPart part)
        {
            SimulatedLiftingSurface surface = pool.Borrow();

            surface.vessel = part.vessel;
            surface.Init(module, part);
            return(surface);
        }
Ejemplo n.º 4
0
 private static void Reset(SimulatedPart obj)
 {
     foreach (DragCube cube in obj.cubes.Cubes)
     {
         DragCubePool.Instance.Release(cube);
     }
     obj.simCurves.Release();
 }
Ejemplo n.º 5
0
        public static SimulatedPart Borrow(Part p, SimulatedVessel vessel)
        {
            SimulatedPart part = pool.Borrow();

            part.vessel = vessel;
            part.Init(p);
            return(part);
        }
Ejemplo n.º 6
0
        public static SimulatedEngine Borrow(ModuleEngines module, SimulatedPart part)
        {
            SimulatedEngine engine = pool.Borrow();

            engine.vessel = part.vessel;
            engine.Init(module, part);
            return(engine);
        }
Ejemplo n.º 7
0
        private static SimulatedPart Create()
        {
            SimulatedPart part = new SimulatedPart();

            part.cubes.BodyLiftCurve = new PhysicsGlobals.LiftingSurfaceCurve();
            part.cubes.SurfaceCurves = new PhysicsGlobals.SurfaceCurvesList();
            return(part);
        }
Ejemplo n.º 8
0
 private static void Reset(SimulatedVessel obj)
 {
     SimulatedPart.Release(obj.parts);
     obj.parts.Clear();
     SimulatedLiftingSurface.Release(obj.surfaces);
     obj.surfaces.Clear();
     SimulatedControlSurface.Release(obj.ctrls);
     obj.ctrls.Clear();
     SimulatedEngine.Release(obj.engines);
     obj.engines.Clear();
 }
Ejemplo n.º 9
0
        protected void Init(ModuleControlSurface surface, SimulatedPart part)
        {
            base.Init(surface, part);

            this.deflectionLiftCoeff = surface.deflectionLiftCoeff * surface.ctrlSurfaceArea;
            this.authorityLimiter    = surface.authorityLimiter;
            this.ctrlSurfaceRange    = surface.ctrlSurfaceRange;
            // TODO: Incorporate transformName if required.
            this.rotationAxis = surface.transform.rotation * Vector3.right;
            this.ignorePitch  = surface.ignorePitch;
            this.maxAuthority = 150f; // surface.maxAuthority is private. Hopefully its value never changes.
        }
Ejemplo n.º 10
0
 protected static void Reset(PartCollection obj)
 {
     SimulatedPart.Release(obj.parts);
     obj.parts.Clear();
     SimulatedLiftingSurface.Release(obj.surfaces);
     obj.surfaces.Clear();
     SimulatedControlSurface.Release(obj.ctrls);
     obj.ctrls.Clear();
     SimulatedEngine.Release(obj.engines);
     obj.engines.Clear();
     PartCollection.Release(obj.partCollections);
     obj.partCollections.Clear();
 }
Ejemplo n.º 11
0
        private void GenerateHighlightingData(ShipConstruct ship, CelestialBody body, float altitude, float speed, float aoa)
        {
            float mach, atmDensity;

            lock (body)
            {
                atmDensity = (float)Extensions.KSPClassExtensions.GetDensity(body, altitude);
                mach       = speed / (float)body.GetSpeedOfSound(body.GetPressure(altitude), atmDensity);
            }

            int count = ship.parts.Count;

            highlightingData = new PartAeroData[count];

            Vector3 inflow = AeroPredictor.InflowVect(aoa);

            float pseudoReDragMult;

            lock (PhysicsGlobals.DragCurvePseudoReynolds)
                pseudoReDragMult = PhysicsGlobals.DragCurvePseudoReynolds.Evaluate(atmDensity * speed);

            for (int i = 0; i < count; i++)
            {
                if (WindTunnelSettings.HighlightIgnoresLiftingSurfaces && ship.parts[i].HasModuleImplementing <ModuleLiftingSurface>())
                {
                    highlightingData[i] = new PartAeroData(0, 0, ship.parts[i].mass);
                    continue;
                }

                VesselCache.SimulatedPart simPart = VesselCache.SimulatedPart.Borrow(ship.parts[i], null);
                Vector3 partForce = simPart.GetAero(inflow, mach, pseudoReDragMult);

                ModuleLiftingSurface liftingSurface = ship.parts[i].FindModuleImplementing <ModuleLiftingSurface>();
                if (liftingSurface != null)
                {
                    VesselCache.SimulatedLiftingSurface simLiftSurf = VesselCache.SimulatedLiftingSurface.Borrow(liftingSurface, simPart);
                    partForce += simLiftSurf.GetForce(inflow, mach);
                    simLiftSurf.Release();
                }
                simPart.Release();
                //Vector3 partForce = highlightingVessel.parts[i].GetAero(inflow, mach, pseudoReDragMult);
                //Vector3 partForce = StockAeroUtil.SimAeroForce(body, new ShipConstruct("test", "", new List<Part>() { EditorLogic.fetch.ship.parts[i] }), inflow * speed, altitude);
                partForce = AeroPredictor.ToFlightFrame(partForce, aoa);  // (Quaternion.AngleAxis((aoa * 180 / Mathf.PI), Vector3.left) * partForce);

                highlightingData[i] = new PartAeroData(Math.Abs(partForce.z), Math.Abs(partForce.y), ship.parts[i].mass);
            }
        }
Ejemplo n.º 12
0
        protected void Init(ModuleLiftingSurface surface, SimulatedPart part)
        {
            surface.SetupCoefficients(Vector3.forward, out Vector3 nVel, out this.liftVector, out float liftDot, out float absDot);
            this.omnidirectional      = surface.omnidirectional;
            this.perpendicularOnly    = surface.perpendicularOnly;
            this.liftCurve            = surface.liftCurve.Clone();
            this.liftMachCurve        = surface.liftMachCurve.Clone();
            this.dragCurve            = surface.dragCurve.Clone();
            this.dragMachCurve        = surface.dragMachCurve.Clone();
            this.deflectionLiftCoeff  = surface.deflectionLiftCoeff;
            this.useInternalDragModel = surface.useInternalDragModel;
            this.part = part;

            if (surface is ModuleControlSurface ctrl)
            {
                this.deflectionLiftCoeff *= (1 - ctrl.ctrlSurfaceArea);
            }
        }
Ejemplo n.º 13
0
        private void Init(IShipconstruct v, SimCurves _simCurves)
        {
            totalMass = 0;
            dryMass = 0;
            CoM = Vector3.zero;
            CoM_dry = Vector3.zero;

            List<Part> oParts = v.Parts;
            List<SimulatedPart> variableDragParts_ctrls = new List<SimulatedPart>();
            count = oParts.Count;

            if (HighLogic.LoadedSceneIsEditor)
            {
                for (int i = 0; i < v.Parts.Count; i++)
                {
                    Part p = v.Parts[i];
                    if (p.dragModel == Part.DragModel.CUBE && !p.DragCubes.None)
                    {
                        DragCubeList cubes = p.DragCubes;
                        DragCubeList.CubeData p_drag_data = new DragCubeList.CubeData();

                        try
                        {
                            cubes.SetDragWeights();
                            cubes.SetPartOcclusion();
                            cubes.AddSurfaceDragDirection(-Vector3.forward, 0, ref p_drag_data);
                        }
                        catch (Exception)
                        {
                            cubes.SetDrag(Vector3.forward, 0);
                            cubes.ForceUpdate(true, true);
                            cubes.SetDragWeights();
                            cubes.SetPartOcclusion();
                            cubes.AddSurfaceDragDirection(-Vector3.forward, 0, ref p_drag_data);
                            //Debug.Log(String.Format("Trajectories: Caught NRE on Drag Initialization.  Should be fixed now.  {0}", e));
                        }
                    }
                }
            }

            simCurves = _simCurves;

            if (parts.Capacity < count)
                parts.Capacity = count;

            bool lgWarning = false;
            int stage = 0;
            for (int i = 0; i < count; i++)
            {
                if (!lgWarning)
                {
                    ModuleWheels.ModuleWheelDeployment gear = oParts[i].FindModuleImplementing<ModuleWheels.ModuleWheelDeployment>();
                    bool forcedRetract = !oParts[i].ShieldedFromAirstream && gear != null && gear.Position > 0;

                    if (forcedRetract)
                        lgWarning = true;
                }

                SimulatedPart simulatedPart = SimulatedPart.Borrow(oParts[i], this);
                parts.Add(simulatedPart);

                totalMass += simulatedPart.totalMass;
                dryMass += simulatedPart.dryMass;
                CoM += simulatedPart.totalMass * simulatedPart.CoM;
                CoM_dry += simulatedPart.dryMass * simulatedPart.CoM;
                
                ModuleLiftingSurface liftingSurface = oParts[i].FindModuleImplementing<ModuleLiftingSurface>();
                if (liftingSurface != null)
                {
                    parts[i].hasLiftModule = true;
                    if (liftingSurface is ModuleControlSurface ctrlSurface)
                    {
                        ctrls.Add(SimulatedControlSurface.Borrow(ctrlSurface, simulatedPart));
                        variableDragParts_ctrls.Add(simulatedPart);
                        if (ctrlSurface.ctrlSurfaceArea < 1)
                            surfaces.Add(SimulatedLiftingSurface.Borrow(ctrlSurface, simulatedPart));
                    }
                    else
                        surfaces.Add(SimulatedLiftingSurface.Borrow(liftingSurface, simulatedPart));
                }

                List<ITorqueProvider> torqueProviders = oParts[i].FindModulesImplementing<ITorqueProvider>();
                // TODO: Add them to a list.

                if(oParts[i].inverseStage > stage)
                {
                    SimulatedEngine.Release(engines);
                    engines.Clear();
                    stage = oParts[i].inverseStage;
                }
                if (oParts[i].inverseStage >= stage)
                {
                    MultiModeEngine multiMode = oParts[i].FindModuleImplementing<MultiModeEngine>();
                    if (multiMode != null)
                    {
                        engines.Add(SimulatedEngine.Borrow(oParts[i].FindModulesImplementing<ModuleEngines>().Find(engine => engine.engineID == multiMode.mode), simulatedPart));
                    }
                    else
                    {
                        ModuleEngines engine = oParts[i].FindModulesImplementing<ModuleEngines>().FirstOrDefault();
                        if (engine != null)
                            engines.Add(SimulatedEngine.Borrow(engine, simulatedPart));
                    }
                }
            }
            CoM /= totalMass;
            CoM_dry /= dryMass;

            if (lgWarning)
                ScreenMessages.PostScreenMessage("Landing gear deployed, results may not be accurate.", 5, ScreenMessageStyle.UPPER_CENTER);

            /*for (int i = 0; i < count; i++)
            {
                parts[i].CoM -= this.CoM;
                parts[i].CoL -= this.CoM;
                parts[i].CoP -= this.CoM;
            }*/

            parts.RemoveAll(part => variableDragParts_ctrls.Contains(part));
        }
Ejemplo n.º 14
0
        protected void AddPart(Part part)
        {
            if (parts.Count > 0 && part.HasModuleImplementing <Expansions.Serenity.ModuleRoboticServoRotor>())
            {
                partCollections.Add(RotorPartCollection.Borrow(parentVessel, part));
                return;
            }

            SimulatedPart simulatedPart = SimulatedPart.Borrow(part, parentVessel);

            parts.Add(simulatedPart);

            parentVessel.totalMass += simulatedPart.totalMass;
            parentVessel.dryMass   += simulatedPart.dryMass;
            parentVessel.CoM       += simulatedPart.totalMass * simulatedPart.CoM;
            parentVessel.CoM_dry   += simulatedPart.dryMass * simulatedPart.CoM;

            bool variableDragCube_Ctrl = false;

            ModuleLiftingSurface liftingSurface = part.FindModuleImplementing <ModuleLiftingSurface>();

            if (liftingSurface != null)
            {
                part.hasLiftModule = true;
                SimulatedLiftingSurface surface;
                if (liftingSurface is ModuleControlSurface ctrlSurface)
                {
                    surface = SimulatedControlSurface.Borrow(ctrlSurface, simulatedPart);
                    ctrls.Add((SimulatedControlSurface)surface);

                    // Controls change their drag cubes with deployment and so we can't precalculate them.
                    // The effect of their drag cubes is captured in the methods for SimulatedControlSurface
                    variableDragCube_Ctrl = true;

                    if (ctrlSurface.ctrlSurfaceArea < 1)
                    {
                        surface = SimulatedLiftingSurface.Borrow(ctrlSurface, simulatedPart);
                        surfaces.Add(surface);
                    }
                }
                else
                {
                    surface = SimulatedLiftingSurface.Borrow(liftingSurface, simulatedPart);
                    surfaces.Add(surface);
                }
                Math.Abs(0);
                parentVessel.relativeWingArea += surface.deflectionLiftCoeff * Math.Abs(surface.liftVector[1]);
            }

            List <ITorqueProvider> torqueProviders = part.FindModulesImplementing <ITorqueProvider>();

            // TODO: Add them to a list.

            if (part.inverseStage > parentVessel.stage)
            {
                // Recursively clear all engines - there's an earlier stage active.
                parentVessel.partCollection.ClearEngines();
                parentVessel.stage = part.inverseStage;
            }
            if (part.inverseStage >= parentVessel.stage)
            {
                MultiModeEngine multiMode = part.FindModuleImplementing <MultiModeEngine>();
                if (multiMode != null)
                {
                    engines.Add(SimulatedEngine.Borrow(part.FindModulesImplementing <ModuleEngines>().Find(engine => engine.engineID == multiMode.mode), simulatedPart));
                }
                else
                {
                    ModuleEngines engine = part.FindModulesImplementing <ModuleEngines>().FirstOrDefault();
                    if (engine != null)
                    {
                        engines.Add(SimulatedEngine.Borrow(engine, simulatedPart));
                    }
                }
            }

            if (variableDragCube_Ctrl)
            {
                simulatedPart.Release();
                parts.Remove(simulatedPart);
            }

            for (int i = part.children.Count - 1; i >= 0; i--)
            {
                AddPart(part.children[i]);
            }
        }