Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Improved the **FastLoader** second config pass by refreshing GameData directories in parallel and using faster filesystem functions.

**Bug Fixes**
- **OptimisedVectorLines** : Fixed orbit and CommNet lines lagging the camera by a frame, seen as the lines sliding against the bodies whenever the camera moved. The cached camera projection matrix was scoped to a frame and filled lazily by whichever `LateUpdate` drew first. Every Vectrosity consumer draws from its own `LateUpdate` and the cameras move during `LateUpdate` too, with no defined order between them, so a draw issued before the camera moved would pin the previous frame's pose for every line drawn after it. The cache is now refreshed per draw call.
- **BlockMapViewPartClick** : Fixed a `NullReferenceException` thrown from `Part.UpdateMouseOver` on every frame of a scene load into flight. The scene reports itself as flight well before `CameraManager.Instance` exists, and both the patch and stock dereferenced it unconditionally. `Part.UpdateMouseOver` is now skipped until there is a camera manager.
- **EditorAnimatedPartsShipModified** : Fixed a memory leak ([issue #396](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/396)) where listeners were not properly cleaned up.
- **EditorAnimatedPartsShipModified** : This patch is now disabled if DMagic Orbital Science is installed because DMagic Orbital Science has a bug that causes a stack overflow crash if you ever call `DMSoilMoisture.OnStop`, which this patch does.
Expand Down
16 changes: 15 additions & 1 deletion KSPCommunityFixes/Performance/OptimisedVectorLines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ protected override void ApplyPatches()
AddPatch(PatchType.Transpiler, typeof(VectorLine), nameof(VectorLine.IntersectAndDoSkip));

AddPatch(PatchType.Transpiler, typeof(VectorLine), nameof(VectorLine.Draw3D));

AddPatch(PatchType.Prefix, typeof(VectorLine), nameof(VectorLine.Draw3D));
AddPatch(PatchType.Prefix, typeof(VectorLine), nameof(VectorLine.Draw));
}

#region VectorLine Patches
Expand All @@ -42,6 +45,17 @@ static IEnumerable<CodeInstruction> VectorLine_BehindCamera_Transpiler(IEnumerab
static IEnumerable<CodeInstruction> VectorLine_IntersectAndDoSkip_Transpiler(IEnumerable<CodeInstruction> instructions) =>
ReplaceWorldToScreenPoint(instructions, 2);

// Because draw calls originate from multiple LateUpdate methods with unpredictable
// execution orders, the camera pose might change mid-frame. To ensure consistency,
// we scope the cache strictly to a single draw call.
static void VectorLine_Draw3D_Prefix() => VectorLineCameraProjection.UpdateCache();

static void VectorLine_Draw_Prefix(VectorLine __instance)
{
if (!__instance.is2D)
VectorLineCameraProjection.UpdateCache();
}

static IEnumerable<CodeInstruction> VectorLine_Draw3D_Transpiler(IEnumerable<CodeInstruction> instructions)
{
instructions = ReplaceWorldToScreenPoint(instructions, 2);
Expand Down Expand Up @@ -145,7 +159,7 @@ public ViewportInfo(Rect viewport)

private static ViewportInfo viewport;

private static void UpdateCache()
internal static void UpdateCache()
{
lastCachedFrame = KSPCommunityFixes.UpdateCount;
Camera camera = VectorLine.cam3D;
Expand Down