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(); }
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(); }
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); } }
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]); } }