Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions MechJeb2/FlyingSim/SimulatedPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ public class SimulatedPart
protected QuaternionD vesselToPart;
private QuaternionD partToVessel;

// The cube list's own curve containers. Stock DragCubeList.SetPart points the list at the global ones
// (PhysicsGlobals.BodyLiftCurve, PhysicsGlobals.SurfaceCurves), and SimCurves.CopyTo writes the simulation's curve copies into
// what the list holds: into the globals, KSP's own physics then evaluated the same AnimationCurves on the main thread as the
// simulation on its thread, and both read garbage, often 0 (no body lift in half the predictions).
private readonly PhysicsGlobals.LiftingSurfaceCurve ownBodyLiftCurve = new PhysicsGlobals.LiftingSurfaceCurve();
private readonly PhysicsGlobals.SurfaceCurvesList ownSurfaceCurves = new PhysicsGlobals.SurfaceCurvesList();

private static readonly Pool<SimulatedPart> pool = new Pool<SimulatedPart>(Create, Reset);

public static int PoolSize => pool.Size;

private static SimulatedPart Create()
{
var part = new SimulatedPart();
part.cubes.BodyLiftCurve = new PhysicsGlobals.LiftingSurfaceCurve();
part.cubes.SurfaceCurves = new PhysicsGlobals.SurfaceCurvesList();
return part;
}
private static SimulatedPart Create() => new SimulatedPart();

public virtual void Release()
{
Expand Down Expand Up @@ -285,6 +286,8 @@ protected void CopyDragCubesList(DragCubeList source, DragCubeList dest)
dest.ClearCubes();

dest.SetPart(source.Part);
dest.BodyLiftCurve = ownBodyLiftCurve; // not stock's global ones, which SetPart just gave it
dest.SurfaceCurves = ownSurfaceCurves;

dest.None = source.None;

Expand Down
Loading