Skip to content

Commit

Permalink
Memoize Y-offset for pawn rendering
Browse files Browse the repository at this point in the history
Matrix4x4.rotation and Quaternion.eulerAngles are, somewhat confusingly,
not fields but relatively costly property accessors. When rendering many
pawns, repeated calls to them can have a measurable impact, so store the
result in a local variable and reuse it.
  • Loading branch information
mszabo-wikia committed Oct 30, 2024
1 parent 46a544f commit 82de6a4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Source/CombatExtended/Harmony/Harmony_PawnRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ private static void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material mat, int laye
muzzleJump = -muzzleJump;
casingOffset.x *= -1;
}
matrix.SetTRS(position + posVec.RotatedBy(matrix.rotation.eulerAngles.y) + recoilOffset, Quaternion.AngleAxis(matrix.rotation.eulerAngles.y + muzzleJump, Vector3.up), scale);

float yAngle = matrix.rotation.eulerAngles.y;
matrix.SetTRS(position + posVec.RotatedBy(yAngle) + recoilOffset, Quaternion.AngleAxis(yAngle + muzzleJump, Vector3.up), scale);
CompEquippable compEquippable = eq.TryGetComp<CompEquippable>();
if (compEquippable != null && compEquippable.PrimaryVerb is Verb_ShootCE verbCE)
{
verbCE.drawPos = casingDrawPos + (casingOffset + posVec).RotatedBy(matrix.rotation.eulerAngles.y);
verbCE.drawPos = casingDrawPos + (casingOffset + posVec).RotatedBy(yAngle);
}
if (eq is WeaponPlatform platform)
{
Expand Down

0 comments on commit 82de6a4

Please sign in to comment.