From ba59c97d88a5a51d36d2349e266f11c9604dd294 Mon Sep 17 00:00:00 2001 From: Ez Diy Date: Wed, 5 Aug 2020 05:25:00 +0200 Subject: [PATCH] Port to Framework/NET45 * Get rid of netstandard abuse, as far as compiler errors are concerned * Replace Buffer.MemoryCopy with Unsafe.CopyBlock for NET45 --- BepuPhysics/Bodies.cs | 44 ++++++++++++++----- BepuPhysics/BodyProperties.cs | 12 ++--- BepuPhysics/Collidables/Compound.cs | 4 +- BepuPhysics/Collidables/ConvexHull.cs | 18 +++++--- .../CollisionDetection/CollisionBatcher.cs | 9 ++++ .../CollisionTasks/BoxConvexHullTester.cs | 4 +- .../CollisionTasks/BoxCylinderTester.cs | 6 +-- .../CollisionTasks/BoxPairTester.cs | 8 ++-- .../CollisionTasks/BoxTriangleTester.cs | 2 +- .../CollisionTasks/CapsuleConvexHullTester.cs | 6 +-- .../CollisionTasks/CapsuleTriangleTester.cs | 6 +-- .../CompoundPairOverlapFinder.cs | 2 +- .../CollisionTasks/ConvexHullPairTester.cs | 4 +- .../CylinderConvexHullTester.cs | 10 ++--- .../CollisionTasks/CylinderPairTester.cs | 2 +- .../CollisionTasks/ManifoldCandidateHelper.cs | 7 ++- .../CollisionTasks/SphereTriangleTester.cs | 6 +-- .../TriangleConvexHullTester.cs | 4 +- .../CollisionTasks/TriangleCylinderTester.cs | 6 +-- .../CollisionTasks/TrianglePairTester.cs | 8 ++-- .../CollisionDetection/DepthRefiner.cs | 12 ++--- .../SweepTasks/ConvexSweepTaskCommon.cs | 8 ++-- .../SweepTasks/GJKDistanceTester.cs | 7 +-- .../SphereTriangleDistanceTester.cs | 2 +- .../CollisionDetection/WideRayTester.cs | 1 + BepuPhysics/Constraints/LinearAxisLimit.cs | 4 +- BepuPhysics/Constraints/SwivelHinge.cs | 2 +- BepuPhysics/Constraints/TwistLimit.cs | 4 +- BepuPhysics/Constraints/TwistMotor.cs | 4 +- BepuPhysics/Constraints/TwistServo.cs | 4 +- BepuPhysics/FallbackBatch.cs | 8 ++-- BepuPhysics/Helpers.cs | 4 +- BepuPhysics/PoseIntegrator.cs | 4 +- BepuPhysics/StaticDescription.cs | 8 ++-- BepuPhysics/Statics.cs | 6 ++- BepuPhysics/Trees/RayBatcher.cs | 2 +- BepuUtilities/Memory/BufferPool.cs | 4 ++ 37 files changed, 150 insertions(+), 102 deletions(-) diff --git a/BepuPhysics/Bodies.cs b/BepuPhysics/Bodies.cs index e7e6d4981..8f13082bc 100644 --- a/BepuPhysics/Bodies.cs +++ b/BepuPhysics/Bodies.cs @@ -547,6 +547,7 @@ public void GatherInertia(ref Vector references, int count, Debug.Assert(count >= 0 && count <= Vector.Count); //Grab the base references for the body indices. Note that we make use of the references memory layout again. ref var baseIndexA = ref Unsafe.As, int>(ref references); + inertiaA = default; for (int i = 0; i < count; ++i) { GatherInertiaForBody(ref Inertias[Unsafe.Add(ref baseIndexA, i)], ref GatherScatter.GetOffsetInstance(ref inertiaA, i)); @@ -567,6 +568,8 @@ public void GatherInertia(ref TwoBodyReferences references, int count, out BodyI //Grab the base references for the body indices. Note that we make use of the references memory layout again. ref var baseIndexA = ref Unsafe.As, int>(ref references.IndexA); ref var baseIndexB = ref Unsafe.As, int>(ref references.IndexB); + inertiaA = default; + inertiaB = default; for (int i = 0; i < count; ++i) { GatherInertiaForBody(ref Inertias[Unsafe.Add(ref baseIndexA, i)], ref GatherScatter.GetOffsetInstance(ref inertiaA, i)); @@ -590,6 +593,9 @@ public void GatherInertia(ref ThreeBodyReferences references, int count, out Bod ref var baseIndexA = ref Unsafe.As, int>(ref references.IndexA); ref var baseIndexB = ref Unsafe.As, int>(ref references.IndexB); ref var baseIndexC = ref Unsafe.As, int>(ref references.IndexC); + inertiaA = default; + inertiaB = default; + inertiaC = default; for (int i = 0; i < count; ++i) { GatherInertiaForBody(ref Inertias[Unsafe.Add(ref baseIndexA, i)], ref GatherScatter.GetOffsetInstance(ref inertiaA, i)); @@ -616,6 +622,10 @@ public void GatherInertia(ref FourBodyReferences references, int count, out Body ref var baseIndexB = ref Unsafe.As, int>(ref references.IndexB); ref var baseIndexC = ref Unsafe.As, int>(ref references.IndexC); ref var baseIndexD = ref Unsafe.As, int>(ref references.IndexD); + inertiaA = default; + inertiaB = default; + inertiaC = default; + inertiaD = default; for (int i = 0; i < count; ++i) { GatherInertiaForBody(ref Inertias[Unsafe.Add(ref baseIndexA, i)], ref GatherScatter.GetOffsetInstance(ref inertiaA, i)); @@ -642,6 +652,8 @@ public void GatherOrientation(ref TwoBodyReferences references, int count, ref var baseIndexB = ref Unsafe.As, int>(ref references.IndexB); ref var poses = ref ActiveSet.Poses; + orientationA = default; + orientationB = default; for (int i = 0; i < count; ++i) { ref var indexA = ref Unsafe.Add(ref baseIndexA, i); @@ -667,6 +679,7 @@ public void GatherOrientation(ref Vector references, int count, ref var baseIndexA = ref Unsafe.As, int>(ref references); ref var poses = ref ActiveSet.Poses; + orientation = default; for (int i = 0; i < count; ++i) { ref var indexA = ref Unsafe.Add(ref baseIndexA, i); @@ -695,6 +708,8 @@ public void GatherPose(ref Vector references, int count, out Vector3Wide po ref var baseIndex = ref Unsafe.As, int>(ref references); ref var poses = ref ActiveSet.Poses; + position = default; + orientation = default; for (int i = 0; i < count; ++i) { ref var indexA = ref Unsafe.Add(ref baseIndex, i); @@ -722,7 +737,9 @@ public void GatherPose(ref TwoBodyReferences references, int count, ref var baseIndexA = ref Unsafe.As, int>(ref references.IndexA); ref var baseIndexB = ref Unsafe.As, int>(ref references.IndexB); - Vector3Wide positionA, positionB; + Vector3Wide positionA = default, positionB = default; + orientationA = default; + orientationB = default; ref var poses = ref ActiveSet.Poses; for (int i = 0; i < count; ++i) { @@ -761,7 +778,7 @@ public void GatherOffsets(ref TwoBodyReferences references, int count, out Vecto ref var baseIndexA = ref Unsafe.As, int>(ref references.IndexA); ref var baseIndexB = ref Unsafe.As, int>(ref references.IndexB); - Vector3Wide positionA, positionB; + Vector3Wide positionA = default, positionB = default; ref var poses = ref ActiveSet.Poses; for (int i = 0; i < count; ++i) { @@ -788,7 +805,7 @@ public void GatherOffsets(ref ThreeBodyReferences references, int count, out Vec ref var baseIndexB = ref Unsafe.As, int>(ref references.IndexB); ref var baseIndexC = ref Unsafe.As, int>(ref references.IndexC); - Vector3Wide positionA, positionB, positionC; + Vector3Wide positionA = default, positionB = default, positionC = default; ref var poses = ref ActiveSet.Poses; for (int i = 0; i < count; ++i) { @@ -818,7 +835,7 @@ public void GatherOffsets(ref FourBodyReferences references, int count, out Vect ref var baseIndexC = ref Unsafe.As, int>(ref references.IndexC); ref var baseIndexD = ref Unsafe.As, int>(ref references.IndexD); - Vector3Wide positionA, positionB, positionC, positionD; + Vector3Wide positionA = default, positionB = default, positionC = default, positionD = default; ref var poses = ref ActiveSet.Poses; for (int i = 0; i < count; ++i) { @@ -857,6 +874,7 @@ public static unsafe void GatherVelocities(ref Buffer sourceVeloci { //Grab the base references for the body indices. Note that we make use of the references memory layout again. ref var baseIndex = ref Unsafe.As, int>(ref references); + velocities = default; for (int i = 0; i < count; ++i) { GatherVelocities(ref sourceVelocities, ref velocities, ref baseIndex, i); @@ -871,8 +889,9 @@ public static unsafe void GatherVelocities(ref Buffer sourceVeloci /// Gathered velocities of A bodies. /// Gathered velocities of B bodies. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void GatherVelocities(ref Buffer sourceVelocities, ref TwoBodyReferences references, int count, out BodyVelocities velocitiesA, out BodyVelocities velocitiesB) - { + public static unsafe void GatherVelocities(ref Buffer sourceVelocities, ref TwoBodyReferences references, int count, out BodyVelocities velocitiesA, out BodyVelocities velocitiesB) { + velocitiesA = default; + velocitiesB = default; Debug.Assert(count >= 0 && count <= Vector.Count); //Grab the base references for the body indices. Note that we make use of the references memory layout again. ref var baseIndexA = ref Unsafe.As, int>(ref references.IndexA); @@ -894,8 +913,10 @@ public static unsafe void GatherVelocities(ref Buffer sourceVeloci /// Gathered velocities of C bodies. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe void GatherVelocities(ref Buffer sourceVelocities, ref ThreeBodyReferences references, int count, - out BodyVelocities velocitiesA, out BodyVelocities velocitiesB, out BodyVelocities velocitiesC) - { + out BodyVelocities velocitiesA, out BodyVelocities velocitiesB, out BodyVelocities velocitiesC) { + velocitiesA = default; + velocitiesB = default; + velocitiesC = default; Debug.Assert(count >= 0 && count <= Vector.Count); //Grab the base references for the body indices. Note that we make use of the references memory layout again. ref var baseIndexA = ref Unsafe.As, int>(ref references.IndexA); @@ -920,8 +941,11 @@ public static unsafe void GatherVelocities(ref Buffer sourceVeloci /// Gathered velocities of D bodies. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe void GatherVelocities(ref Buffer sourceVelocities, ref FourBodyReferences references, int count, - out BodyVelocities velocitiesA, out BodyVelocities velocitiesB, out BodyVelocities velocitiesC, out BodyVelocities velocitiesD) - { + out BodyVelocities velocitiesA, out BodyVelocities velocitiesB, out BodyVelocities velocitiesC, out BodyVelocities velocitiesD) { + velocitiesA = default; + velocitiesB = default; + velocitiesC = default; + velocitiesD = default; Debug.Assert(count >= 0 && count <= Vector.Count); //Grab the base references for the body indices. Note that we make use of the references memory layout again. ref var baseIndexA = ref Unsafe.As, int>(ref references.IndexA); diff --git a/BepuPhysics/BodyProperties.cs b/BepuPhysics/BodyProperties.cs index 180ff6936..e95cfe06d 100644 --- a/BepuPhysics/BodyProperties.cs +++ b/BepuPhysics/BodyProperties.cs @@ -68,8 +68,8 @@ public static void TransformByInverse(in Vector3 v, in RigidPose pose, out Vecto /// /// Pose to invert. /// Inverse of the pose. - public static void Invert(in RigidPose pose, out RigidPose inverse) - { + public static void Invert(in RigidPose pose, out RigidPose inverse) { + inverse = default; QuaternionEx.Conjugate(pose.Orientation, out inverse.Orientation); QuaternionEx.Transform(-pose.Position, inverse.Orientation, out inverse.Position); } @@ -81,8 +81,8 @@ public static void Invert(in RigidPose pose, out RigidPose inverse) /// Second transform to concatenate. /// Result of the concatenation. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void MultiplyWithoutOverlap(in RigidPose a, in RigidPose b, out RigidPose result) - { + public static void MultiplyWithoutOverlap(in RigidPose a, in RigidPose b, out RigidPose result) { + result = default; QuaternionEx.ConcatenateWithoutOverlap(a.Orientation, b.Orientation, out result.Orientation); QuaternionEx.Transform(a.Position, b.Orientation, out var rotatedTranslationA); result.Position = rotatedTranslationA + b.Position; @@ -135,8 +135,8 @@ public static void WriteFirst(in RigidPose pose, ref RigidPoses poses) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ReadFirst(in RigidPoses poses, out RigidPose pose) - { + public static void ReadFirst(in RigidPoses poses, out RigidPose pose) { + pose = default; Vector3Wide.ReadFirst(poses.Position, out pose.Position); QuaternionWide.ReadFirst(poses.Orientation, out pose.Orientation); } diff --git a/BepuPhysics/Collidables/Compound.cs b/BepuPhysics/Collidables/Compound.cs index 20d23dbf8..ed25e9050 100644 --- a/BepuPhysics/Collidables/Compound.cs +++ b/BepuPhysics/Collidables/Compound.cs @@ -80,8 +80,8 @@ public static bool ValidateChildIndices(ref Buffer children, Shap } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void GetRotatedChildPose(in RigidPose localPose, in Quaternion orientation, out RigidPose rotatedChildPose) - { + public static void GetRotatedChildPose(in RigidPose localPose, in Quaternion orientation, out RigidPose rotatedChildPose) { + rotatedChildPose = default; QuaternionEx.ConcatenateWithoutOverlap(localPose.Orientation, orientation, out rotatedChildPose.Orientation); QuaternionEx.Transform(localPose.Position, orientation, out rotatedChildPose.Position); } diff --git a/BepuPhysics/Collidables/ConvexHull.cs b/BepuPhysics/Collidables/ConvexHull.cs index 13d4417ca..510275413 100644 --- a/BepuPhysics/Collidables/ConvexHull.cs +++ b/BepuPhysics/Collidables/ConvexHull.cs @@ -322,8 +322,10 @@ public void Broadcast(in ConvexHull shape) Hulls[i] = shape; } - public void GetBounds(ref QuaternionWide orientations, int countInBundle, out Vector maximumRadius, out Vector maximumAngularExpansion, out Vector3Wide min, out Vector3Wide max) - { + public void GetBounds(ref QuaternionWide orientations, int countInBundle, out Vector maximumRadius, out Vector maximumAngularExpansion, out Vector3Wide min, out Vector3Wide max) { + maximumRadius = default; + min = default; + max = default; for (int i = 0; i < countInBundle; ++i) { Vector3Wide.Broadcast(new Vector3(float.MaxValue), out var minWide); @@ -366,8 +368,10 @@ public void GetBounds(ref QuaternionWide orientations, int countInBundle, out Ve maximumAngularExpansion = maximumRadius; } - public void RayTest(ref RigidPoses poses, ref RayWide rayWide, out Vector intersected, out Vector t, out Vector3Wide normal) - { + public void RayTest(ref RigidPoses poses, ref RayWide rayWide, out Vector intersected, out Vector t, out Vector3Wide normal) { + intersected = default; + t = default; + normal = default; Debug.Assert(Hulls.Length > 0 && Hulls.Length <= Vector.Count); for (int i = 0; i < Hulls.Length; ++i) { @@ -391,7 +395,7 @@ public void RayTest(ref RigidPoses poses, ref RayWide rayWide, out Vector i [MethodImpl(MethodImplOptions.AggressiveInlining)] public void EstimateEpsilonScale(in Vector terminatedLanes, out Vector epsilonScale) { - Vector3Wide bundle; + Vector3Wide bundle = default; for (int i = 0; i < Vector.Count; ++i) { if (terminatedLanes[i] < 0) @@ -420,8 +424,8 @@ public struct ConvexHullSupportFinder : ISupportFinder false; //[MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ComputeLocalSupport(in ConvexHullWide shape, in Vector3Wide direction, in Vector terminatedLanes, out Vector3Wide support) - { + public void ComputeLocalSupport(in ConvexHullWide shape, in Vector3Wide direction, in Vector terminatedLanes, out Vector3Wide support) { + support = default; Helpers.FillVectorWithLaneIndices(out var indexOffsets); for (int slotIndex = 0; slotIndex < Vector.Count; ++slotIndex) { diff --git a/BepuPhysics/CollisionDetection/CollisionBatcher.cs b/BepuPhysics/CollisionDetection/CollisionBatcher.cs index 8067d4c34..c225c3dc6 100644 --- a/BepuPhysics/CollisionDetection/CollisionBatcher.cs +++ b/BepuPhysics/CollisionDetection/CollisionBatcher.cs @@ -245,8 +245,13 @@ unsafe void CacheShapes(ref CollisionTaskReference reference, void* shapeA, void cachedShapeA = batch.Shapes.Allocate(shapeSizeA); cachedShapeB = batch.Shapes.Allocate(shapeSizeB); //TODO: Given the size of these copies, it's not clear that this copy implementation is ideal. Wouldn't worry too much about it. +#if NET45 + Unsafe.CopyBlockUnaligned(cachedShapeA, shapeA, (uint)shapeSizeA); + Unsafe.CopyBlockUnaligned(cachedShapeB, shapeB, (uint)shapeSizeB); +#else Buffer.MemoryCopy(shapeA, cachedShapeA, shapeSizeA, shapeSizeA); Buffer.MemoryCopy(shapeB, cachedShapeB, shapeSizeB, shapeSizeB); +#endif } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -261,7 +266,11 @@ public unsafe void CacheShapeB(int shapeTypeA, int shapeTypeB, void* shapeDataB, Debug.Assert(batch.Shapes.ByteCount == 0); } cachedShapeDataB = batch.Shapes.Allocate(shapeSizeB); +#if NET45 + Unsafe.CopyBlockUnaligned(cachedShapeDataB, shapeDataB, (uint)shapeDataB); +#else Buffer.MemoryCopy(shapeDataB, cachedShapeDataB, shapeSizeB, shapeSizeB); +#endif } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/BoxConvexHullTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/BoxConvexHullTester.cs index ca92622c2..11948cda2 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/BoxConvexHullTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/BoxConvexHullTester.cs @@ -11,8 +11,8 @@ public struct BoxConvexHullTester : IPairTester 16; - public unsafe void Test(ref BoxWide a, ref ConvexHullWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, out Convex4ContactManifoldWide manifold) - { + public unsafe void Test(ref BoxWide a, ref ConvexHullWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, out Convex4ContactManifoldWide manifold) { + manifold = default; Matrix3x3Wide.CreateFromQuaternion(orientationA, out var boxOrientation); Matrix3x3Wide.CreateFromQuaternion(orientationB, out var hullOrientation); Matrix3x3Wide.MultiplyByTransposeWithoutOverlap(boxOrientation, hullOrientation, out var hullLocalBoxOrientation); diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/BoxCylinderTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/BoxCylinderTester.cs index d6dd7be5d..3355e0ba5 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/BoxCylinderTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/BoxCylinderTester.cs @@ -95,7 +95,7 @@ static void TryAddInteriorPoint(in Vector2Wide point, in Vector featureId, var contained = Vector.BitwiseAnd(allowContact, Vector.BitwiseAnd( Vector.BitwiseAnd(Vector.GreaterThanOrEqual(edge0010Dot, edge0010PlaneMin), Vector.LessThanOrEqual(edge0010Dot, edge0010PlaneMax)), Vector.BitwiseAnd(Vector.GreaterThanOrEqual(edge1011Dot, edge1011PlaneMin), Vector.LessThanOrEqual(edge1011Dot, edge1011PlaneMax)))); - ManifoldCandidate candidate; + ManifoldCandidate candidate = default; candidate.X = point.X; candidate.Y = point.Y; candidate.FeatureId = featureId; @@ -106,8 +106,8 @@ static void TryAddInteriorPoint(in Vector2Wide point, in Vector featureId, public unsafe void Test( ref BoxWide a, ref CylinderWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, - out Convex4ContactManifoldWide manifold) - { + out Convex4ContactManifoldWide manifold) { + manifold = default; Matrix3x3Wide.CreateFromQuaternion(orientationA, out var worldRA); Matrix3x3Wide.CreateFromQuaternion(orientationB, out var worldRB); //Work in b's local space. diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/BoxPairTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/BoxPairTester.cs index e939a6486..f1ba1e794 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/BoxPairTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/BoxPairTester.cs @@ -113,7 +113,7 @@ static void AddBoxAVertex(in Vector3Wide vertex, in Vector featureId, in Ve Vector3Wide.Subtract(vertex, offset, out var vertexOnBFace); Vector3Wide.Subtract(vertexOnBFace, faceCenterB, out var vertexOffsetOnBFace); - ManifoldCandidate candidate; + ManifoldCandidate candidate = default; Vector3Wide.Dot(vertexOffsetOnBFace, faceTangentBX, out candidate.X); Vector3Wide.Dot(vertexOffsetOnBFace, faceTangentBY, out candidate.Y); candidate.FeatureId = featureId; @@ -275,7 +275,7 @@ private static void CreateEdgeContacts( //We now have intervals for all four box B edges. var edgeFeatureIdOffset = new Vector(64); var epsilon = epsilonScale * 1e-5f; - ManifoldCandidate min, max; + ManifoldCandidate min = default, max = default; //X0 min.FeatureId = featureIdX0; min.X = minX0; @@ -320,8 +320,8 @@ private static void CreateEdgeContacts( public unsafe void Test( ref BoxWide a, ref BoxWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, - out Convex4ContactManifoldWide manifold) - { + out Convex4ContactManifoldWide manifold) { + manifold = default; Matrix3x3Wide.CreateFromQuaternion(orientationA, out var worldRA); Matrix3x3Wide.CreateFromQuaternion(orientationB, out var worldRB); Matrix3x3Wide.MultiplyByTransposeWithoutOverlap(worldRB, worldRA, out var rB); diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/BoxTriangleTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/BoxTriangleTester.cs index d8bdf74c0..70b07a92a 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/BoxTriangleTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/BoxTriangleTester.cs @@ -112,7 +112,7 @@ static void Add(in Vector3Wide pointOnTriangle, in Vector3Wide triangleCenter, i in Vector exists, ref ManifoldCandidate candidates, ref Vector candidateCount, int pairCount) { Vector3Wide.Subtract(pointOnTriangle, triangleCenter, out var offset); - ManifoldCandidate candidate; + ManifoldCandidate candidate = default; Vector3Wide.Dot(offset, triangleTangentX, out candidate.X); Vector3Wide.Dot(offset, triangleTangentY, out candidate.Y); candidate.FeatureId = featureId; diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/CapsuleConvexHullTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/CapsuleConvexHullTester.cs index 594d6292a..be0696a65 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/CapsuleConvexHullTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/CapsuleConvexHullTester.cs @@ -47,10 +47,10 @@ public void Test(ref CapsuleWide a, ref ConvexHullWide b, ref Vector spec //To find the contact manifold, we'll clip the capsule axis against the face as usual, but we're dealing with potentially //distinct convex hulls. Rather than vectorizing over the different hulls, we vectorize within each hull. Helpers.FillVectorWithLaneIndices(out var slotOffsetIndices); - Vector3Wide faceNormalBundle; + Vector3Wide faceNormalBundle = default; var boundingPlaneEpsilon = 1e-3f * epsilonScale; - Vector latestEntryNumeratorBundle, latestEntryDenominatorBundle; - Vector earliestExitNumeratorBundle, earliestExitDenominatorBundle; + Vector latestEntryNumeratorBundle = default, latestEntryDenominatorBundle = default; + Vector earliestExitNumeratorBundle = default, earliestExitDenominatorBundle = default; for (int slotIndex = 0; slotIndex < pairCount; ++slotIndex) { if (inactiveLanes[slotIndex] < 0) diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/CapsuleTriangleTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/CapsuleTriangleTester.cs index dea4ba598..64029146a 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/CapsuleTriangleTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/CapsuleTriangleTester.cs @@ -110,8 +110,8 @@ public static void ClipAgainstEdgePlane(in Vector3Wide edgeStart, in Vector3Wide public void Test( ref CapsuleWide a, ref TriangleWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, - out Convex2ContactManifoldWide manifold) - { + out Convex2ContactManifoldWide manifold) { + manifold = default; //Work in the triangle's local space to limit transformation requirements. Matrix3x3Wide.CreateFromQuaternion(orientationB, out var rB); Matrix3x3Wide.TransformByTransposedWithoutOverlap(offsetB, rB, out var localOffsetB); @@ -194,7 +194,7 @@ public void Test( manifold.Contact1Exists = Vector.Zero; return; } - Vector3Wide b0, b1; + Vector3Wide b0 = default, b1 = default; Vector contactCount; if (Vector.EqualsAny(useEdge, new Vector(-1))) { diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/CompoundPairOverlapFinder.cs b/BepuPhysics/CollisionDetection/CollisionTasks/CompoundPairOverlapFinder.cs index 1dbf27c9d..49242a1b1 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/CompoundPairOverlapFinder.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/CompoundPairOverlapFinder.cs @@ -56,7 +56,7 @@ public unsafe void FindLocalOverlaps(ref Buffer pairs, int pai Vector maximumAllowedExpansion = default; Vector maximumRadius = default; Vector maximumAngularExpansion = default; - RigidPoses localPosesA; + RigidPoses localPosesA = default; Vector3Wide mins = default; Vector3Wide maxes = default; for (int i = 0; i < totalCompoundChildCount; i += Vector.Count) diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/ConvexHullPairTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/ConvexHullPairTester.cs index 0ef3f69ed..5af539825 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/ConvexHullPairTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/ConvexHullPairTester.cs @@ -17,8 +17,8 @@ struct CachedEdge } public int BatchSize => 16; - public unsafe void Test(ref ConvexHullWide a, ref ConvexHullWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, out Convex4ContactManifoldWide manifold) - { + public unsafe void Test(ref ConvexHullWide a, ref ConvexHullWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, out Convex4ContactManifoldWide manifold) { + manifold = default; Matrix3x3Wide.CreateFromQuaternion(orientationA, out var rA); Matrix3x3Wide.CreateFromQuaternion(orientationB, out var rB); Matrix3x3Wide.MultiplyByTransposeWithoutOverlap(rA, rB, out var bLocalOrientationA); diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/CylinderConvexHullTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/CylinderConvexHullTester.cs index 6b565b0e8..68cff13f6 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/CylinderConvexHullTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/CylinderConvexHullTester.cs @@ -80,8 +80,8 @@ static void InsertContact(in Vector3 slotSideEdgeCenter, in Vector3 slotCylinder GatherScatter.GetFirst(ref contactExistsWide) = -1; } - public unsafe void Test(ref CylinderWide a, ref ConvexHullWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, out Convex4ContactManifoldWide manifold) - { + public unsafe void Test(ref CylinderWide a, ref ConvexHullWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, out Convex4ContactManifoldWide manifold) { + manifold = default; Matrix3x3Wide.CreateFromQuaternion(orientationA, out var cylinderOrientation); Matrix3x3Wide.CreateFromQuaternion(orientationB, out var hullOrientation); Matrix3x3Wide.MultiplyByTransposeWithoutOverlap(cylinderOrientation, hullOrientation, out var hullLocalCylinderOrientation); @@ -122,8 +122,8 @@ public unsafe void Test(ref CylinderWide a, ref ConvexHullWide b, ref Vector.One / localNormalInA.Y; var useCap = Vector.GreaterThan(Vector.Abs(localNormalInA.Y), new Vector(0.70710678118f)); - Vector3Wide capNormal, capCenter; - Vector2Wide interior0, interior1, interior2, interior3; + Vector3Wide capNormal, capCenter = default; + Vector2Wide interior0 = default, interior1 = default, interior2 = default, interior3 = default; if (Vector.LessThanAny(Vector.AndNot(useCap, inactiveLanes), Vector.Zero)) { Vector3Wide.ConditionallyNegate(Vector.GreaterThan(localNormalInA.Y, Vector.Zero), hullLocalCylinderOrientation.Y, out capNormal); @@ -135,7 +135,7 @@ public unsafe void Test(ref CylinderWide a, ref ConvexHullWide b, ref Vector.Zero)) { //If the contact is on the cylinder's side, use the closestOnHull-derived position rather than resampling the support function with the local normal to avoid numerical noise. diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/CylinderPairTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/CylinderPairTester.cs index cd739f182..11852e913 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/CylinderPairTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/CylinderPairTester.cs @@ -184,7 +184,7 @@ public void Test( var capThreshold = new Vector(0.70710678118f); var useCapA = Vector.GreaterThan(Vector.Abs(nDotAY), capThreshold); var useCapB = Vector.GreaterThan(Vector.Abs(localNormal.Y), capThreshold); - Vector3Wide contact0, contact1, contact2, contact3; + Vector3Wide contact0 = default, contact1 = default, contact2 = default, contact3 = default; manifold.Contact0Exists = default; manifold.Contact1Exists = default; manifold.Contact2Exists = default; diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/ManifoldCandidateHelper.cs b/BepuPhysics/CollisionDetection/CollisionTasks/ManifoldCandidateHelper.cs index 635e2934f..4217d011c 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/ManifoldCandidateHelper.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/ManifoldCandidateHelper.cs @@ -89,8 +89,11 @@ public static void Reduce(ref ManifoldCandidate candidates, in Vector rawCo in Vector3Wide faceNormalA, in Vector3Wide normal, in Vector3Wide faceCenterBToFaceCenterA, in Vector3Wide tangentBX, in Vector3Wide tangentBY, in Vector epsilonScale, in Vector minimumDepth, int pairCount, out ManifoldCandidate contact0, out ManifoldCandidate contact1, out ManifoldCandidate contact2, out ManifoldCandidate contact3, - out Vector contact0Exists, out Vector contact1Exists, out Vector contact2Exists, out Vector contact3Exists) - { + out Vector contact0Exists, out Vector contact1Exists, out Vector contact2Exists, out Vector contact3Exists) { + contact0 = default; + contact1 = default; + contact2 = default; + contact3 = default; //See if we can avoid visiting some of the higher indices. //Mask out any contacts generated on the pairs which don't actually exist. They can waste time and cause problems. Vector maskedContactCount = rawContactCount; diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/SphereTriangleTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/SphereTriangleTester.cs index 3e4c75431..4fc194b73 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/SphereTriangleTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/SphereTriangleTester.cs @@ -27,8 +27,8 @@ static void Select(ref Vector distanceSquared, ref Vector3Wide localNorma [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Test(ref SphereWide a, ref TriangleWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationB, int pairCount, - out Convex1ContactManifoldWide manifold) - { + out Convex1ContactManifoldWide manifold) { + manifold = default; //Work in the local space of the triangle, since it's quicker to transform the sphere position than the vertices of the triangle. Matrix3x3Wide.CreateFromQuaternion(orientationB, out var rB); Matrix3x3Wide.TransformByTransposedWithoutOverlap(offsetB, rB, out var localOffsetB); @@ -76,7 +76,7 @@ public void Test(ref SphereWide a, ref TriangleWide b, ref Vector specula var outsideBC = Vector.LessThan(edgePlaneTestBC, Vector.Zero); var outsideAnyEdge = Vector.BitwiseOr(outsideAB, Vector.BitwiseOr(outsideAC, outsideBC)); - Vector3Wide localClosestOnTriangle; + Vector3Wide localClosestOnTriangle = default; var negativeOne = new Vector(-1); if (Vector.EqualsAny(Vector.BitwiseAnd(collidingWithSolidSide, outsideAnyEdge), negativeOne)) { diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/TriangleConvexHullTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/TriangleConvexHullTester.cs index eebfa1519..4615aae3d 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/TriangleConvexHullTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/TriangleConvexHullTester.cs @@ -12,8 +12,8 @@ public struct TriangleConvexHullTester : IPairTester 16; - public unsafe void Test(ref TriangleWide a, ref ConvexHullWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, out Convex4ContactManifoldWide manifold) - { + public unsafe void Test(ref TriangleWide a, ref ConvexHullWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, out Convex4ContactManifoldWide manifold) { + manifold = default; Matrix3x3Wide.CreateFromQuaternion(orientationA, out var triangleOrientation); Matrix3x3Wide.CreateFromQuaternion(orientationB, out var hullOrientation); Matrix3x3Wide.MultiplyByTransposeWithoutOverlap(triangleOrientation, hullOrientation, out var hullLocalTriangleOrientation); diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/TriangleCylinderTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/TriangleCylinderTester.cs index aa245a0f2..08d4f3654 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/TriangleCylinderTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/TriangleCylinderTester.cs @@ -57,7 +57,7 @@ static void TryAddInteriorPoint(in Vector2Wide point, in Vector featureId, var sum = Vector.GreaterThan(abDot, Vector.Zero) + Vector.GreaterThan(bcDot, Vector.Zero) + Vector.GreaterThan(caDot, Vector.Zero); var contained = Vector.BitwiseAnd(allowContact, Vector.BitwiseOr(Vector.Equals(sum, Vector.Zero), Vector.Equals(sum, new Vector(-3)))); - ManifoldCandidate candidate; + ManifoldCandidate candidate = default; candidate.X = point.X; candidate.Y = point.Y; candidate.FeatureId = featureId; @@ -68,8 +68,8 @@ static void TryAddInteriorPoint(in Vector2Wide point, in Vector featureId, public unsafe void Test( ref TriangleWide a, ref CylinderWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, - out Convex4ContactManifoldWide manifold) - { + out Convex4ContactManifoldWide manifold) { + manifold = default; Matrix3x3Wide.CreateFromQuaternion(orientationA, out var worldRA); Matrix3x3Wide.CreateFromQuaternion(orientationB, out var worldRB); //Work in b's local space. diff --git a/BepuPhysics/CollisionDetection/CollisionTasks/TrianglePairTester.cs b/BepuPhysics/CollisionDetection/CollisionTasks/TrianglePairTester.cs index d8b18f488..9db12aa9c 100644 --- a/BepuPhysics/CollisionDetection/CollisionTasks/TrianglePairTester.cs +++ b/BepuPhysics/CollisionDetection/CollisionTasks/TrianglePairTester.cs @@ -95,7 +95,7 @@ private static void TryAddTriangleAVertex(in Vector3Wide vertex, in Vector Vector3Wide.Scale(contactNormal, t, out var unprojectedVertex); Vector3Wide.Add(unprojectedVertex, vertex, out unprojectedVertex); - ManifoldCandidate candidate; + ManifoldCandidate candidate = default; Vector3Wide.Subtract(unprojectedVertex, triangleCenterB, out var offsetOnB); Vector3Wide.Dot(offsetOnB, tangentBX, out candidate.X); Vector3Wide.Dot(offsetOnB, tangentBY, out candidate.Y); @@ -148,7 +148,7 @@ private static void ClipBEdgeAgainstABounds( Vector3Wide.Dot(tangentBX, edgeDirectionB, out var edgeDirectionX); Vector3Wide.Dot(tangentBY, edgeDirectionB, out var edgeDirectionY); - ManifoldCandidate candidate; + ManifoldCandidate candidate = default; var six = new Vector(6); //Entry var exists = Vector.BitwiseAnd(allowContacts, Vector.BitwiseAnd( @@ -182,8 +182,8 @@ private static void ClipBEdgeAgainstABounds( public unsafe void Test( ref TriangleWide a, ref TriangleWide b, ref Vector speculativeMargin, ref Vector3Wide offsetB, ref QuaternionWide orientationA, ref QuaternionWide orientationB, int pairCount, - out Convex4ContactManifoldWide manifold) - { + out Convex4ContactManifoldWide manifold) { + manifold = default; Matrix3x3Wide.CreateFromQuaternion(orientationA, out var worldRA); Matrix3x3Wide.CreateFromQuaternion(orientationB, out var worldRB); Matrix3x3Wide.MultiplyByTransposeWithoutOverlap(worldRB, worldRA, out var rB); diff --git a/BepuPhysics/CollisionDetection/DepthRefiner.cs b/BepuPhysics/CollisionDetection/DepthRefiner.cs index a210fa58e..ed76bc14d 100644 --- a/BepuPhysics/CollisionDetection/DepthRefiner.cs +++ b/BepuPhysics/CollisionDetection/DepthRefiner.cs @@ -84,8 +84,8 @@ public static void Create(in Vector3Wide normal, in Vector3Wide support, out Sim static void GetNextNormal(ref Simplex simplex, in Vector3Wide support, ref Vector terminatedLanes, in Vector3Wide bestNormal, in Vector bestDepth, in Vector convergenceThreshold, - out Vector3Wide nextNormal) - { + out Vector3Wide nextNormal) { + nextNormal = default; //In the penetrating case, the search target is the closest point to the origin on the so-far-best bounding plane. //In the separated case, it's just the origin itself. //Termination conditions are based on the distance to the search target. In the penetrating case, we try to approach zero distance. @@ -425,8 +425,8 @@ static void ForceFillSlot(in Vector shouldFill, ref VertexWithWitness verte } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Create(in Vector3Wide normal, in Vector3Wide support, in Vector3Wide supportOnA, out SimplexWithWitness simplex) - { + public static void Create(in Vector3Wide normal, in Vector3Wide support, in Vector3Wide supportOnA, out SimplexWithWitness simplex) { + simplex = default; //While only one slot is actually full, GetNextNormal expects every slot to have some kind of data- //for those slots which are not yet filled, it should be duplicates of other data. //(The sub-triangle case is treated the same as the degenerate case.) @@ -443,8 +443,8 @@ public static void Create(in Vector3Wide normal, in Vector3Wide support, in Vect static void GetNextNormal(ref SimplexWithWitness simplex, in Vector3Wide support, in Vector3Wide supportOnA, ref Vector terminatedLanes, in Vector3Wide bestNormal, in Vector bestDepth, in Vector convergenceThreshold, - out Vector3Wide nextNormal) - { + out Vector3Wide nextNormal) { + nextNormal = default; //In the penetrating case, the search target is the closest point to the origin on the so-far-best bounding plane. //In the separated case, it's just the origin itself. //Termination conditions are based on the distance to the search target. In the penetrating case, we try to approach zero distance. diff --git a/BepuPhysics/CollisionDetection/SweepTasks/ConvexSweepTaskCommon.cs b/BepuPhysics/CollisionDetection/SweepTasks/ConvexSweepTaskCommon.cs index 43316012c..9185fa4c3 100644 --- a/BepuPhysics/CollisionDetection/SweepTasks/ConvexSweepTaskCommon.cs +++ b/BepuPhysics/CollisionDetection/SweepTasks/ConvexSweepTaskCommon.cs @@ -358,10 +358,10 @@ static unsafe bool Sweep( Vector3Wide.Broadcast(velocityB.Angular, out var wideAngularVelocityB); //The initial samples are distributed evenly over [t0, t1]. - Vector samples; - Vector3Wide sampleOffsetB; - QuaternionWide sampleOrientationA; - QuaternionWide sampleOrientationB; + Vector samples = default; + Vector3Wide sampleOffsetB = default; + QuaternionWide sampleOrientationA = default; + QuaternionWide sampleOrientationB = default; Vector3Wide normals; Vector3Wide closestA; Vector distances; diff --git a/BepuPhysics/CollisionDetection/SweepTasks/GJKDistanceTester.cs b/BepuPhysics/CollisionDetection/SweepTasks/GJKDistanceTester.cs index fe1b12d1b..b701bbbe6 100644 --- a/BepuPhysics/CollisionDetection/SweepTasks/GJKDistanceTester.cs +++ b/BepuPhysics/CollisionDetection/SweepTasks/GJKDistanceTester.cs @@ -333,13 +333,14 @@ void FindClosestPoint(ref Vector outerLoopTerminatedMask, ref Simplex simpl public void Test(in TShapeWideA a, in TShapeWideB b, in Vector3Wide offsetB, in QuaternionWide orientationA, in QuaternionWide orientationB, in Vector inactiveLanes, - out Vector intersected, out Vector distance, out Vector3Wide closestA, out Vector3Wide normal) - { + out Vector intersected, out Vector distance, out Vector3Wide closestA, out Vector3Wide normal) { + closestA = default; + normal = default; Matrix3x3Wide.CreateFromQuaternion(orientationA, out var rA); Matrix3x3Wide.CreateFromQuaternion(orientationB, out var rB); var supportFinderA = default(TSupportFinderA); var supportFinderB = default(TSupportFinderB); - Simplex simplex; + Simplex simplex = default; //TODO: It would be pretty easy to initialize to a triangle or tetrahedron. Might be worth it. SampleMinkowskiDifference(a, rA, ref supportFinderA, b, rB, ref supportFinderB, offsetB, offsetB, inactiveLanes, out simplex.AOnA, out simplex.A); simplex.Count = new Vector(1); diff --git a/BepuPhysics/CollisionDetection/SweepTasks/SphereTriangleDistanceTester.cs b/BepuPhysics/CollisionDetection/SweepTasks/SphereTriangleDistanceTester.cs index 6baca822e..d025e5778 100644 --- a/BepuPhysics/CollisionDetection/SweepTasks/SphereTriangleDistanceTester.cs +++ b/BepuPhysics/CollisionDetection/SweepTasks/SphereTriangleDistanceTester.cs @@ -51,7 +51,7 @@ public void Test(in SphereWide a, in TriangleWide b, in Vector3Wide offsetB, in var outsideBC = Vector.LessThan(edgePlaneTestBC, Vector.Zero); var outsideAnyEdge = Vector.BitwiseOr(outsideAB, Vector.BitwiseOr(outsideAC, outsideBC)); - Vector3Wide localClosestOnTriangle; + Vector3Wide localClosestOnTriangle = default; var negativeOne = new Vector(-1); if (Vector.EqualsAny(outsideAnyEdge, negativeOne)) { diff --git a/BepuPhysics/CollisionDetection/WideRayTester.cs b/BepuPhysics/CollisionDetection/WideRayTester.cs index ddb5249ae..3cbff9d47 100644 --- a/BepuPhysics/CollisionDetection/WideRayTester.cs +++ b/BepuPhysics/CollisionDetection/WideRayTester.cs @@ -49,6 +49,7 @@ public unsafe static void Test(r GatherScatter.GetOffsetInstance(ref *&rayWide, j).Gather(raySource.GetRay(i + j)); } + rayWide = default; wide.RayTest(ref poses, ref rayWide, out var intersected, out var t, out var normal); for (int j = 0; j < count; ++j) diff --git a/BepuPhysics/Constraints/LinearAxisLimit.cs b/BepuPhysics/Constraints/LinearAxisLimit.cs index 84f5fb26c..1e52ac960 100644 --- a/BepuPhysics/Constraints/LinearAxisLimit.cs +++ b/BepuPhysics/Constraints/LinearAxisLimit.cs @@ -113,8 +113,8 @@ public void Modify(in Vector3Wide anchorA, in Vector3Wide anchorB, ref Vector3Wi [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Prestep(Bodies bodies, ref TwoBodyReferences bodyReferences, int count, float dt, float inverseDt, ref BodyInertias inertiaA, ref BodyInertias inertiaB, - ref LinearAxisLimitPrestepData prestep, out LinearAxisServoProjection projection) - { + ref LinearAxisLimitPrestepData prestep, out LinearAxisServoProjection projection) { + projection = default; SpringSettingsWide.ComputeSpringiness(prestep.SpringSettings, dt, out var positionErrorToVelocity, out var effectiveMassCFMScale, out projection.SoftnessImpulseScale); LimitJacobianModifier modifier; modifier.MinimumOffset = prestep.MinimumOffset; diff --git a/BepuPhysics/Constraints/SwivelHinge.cs b/BepuPhysics/Constraints/SwivelHinge.cs index 56431957c..8c76c89fd 100644 --- a/BepuPhysics/Constraints/SwivelHinge.cs +++ b/BepuPhysics/Constraints/SwivelHinge.cs @@ -117,7 +117,7 @@ public void Prestep(Bodies bodies, ref TwoBodyReferences bodyReferences, int cou //The upper left 3x3 block is just the ball socket. Symmetric3x3Wide.SkewSandwichWithoutOverlap(projection.OffsetA, inertiaA.InverseInertiaTensor, out var ballSocketContributionAngularA); Symmetric3x3Wide.SkewSandwichWithoutOverlap(projection.OffsetB, inertiaB.InverseInertiaTensor, out var ballSocketContributionAngularB); - Symmetric4x4Wide inverseEffectiveMass; + Symmetric4x4Wide inverseEffectiveMass = default; ref var upperLeft = ref Symmetric4x4Wide.GetUpperLeft3x3Block(ref inverseEffectiveMass); Symmetric3x3Wide.Add(ballSocketContributionAngularA, ballSocketContributionAngularB, out upperLeft); var linearContribution = projection.InertiaA.InverseMass + projection.InertiaB.InverseMass; diff --git a/BepuPhysics/Constraints/TwistLimit.cs b/BepuPhysics/Constraints/TwistLimit.cs index cc732981e..9be85bc4d 100644 --- a/BepuPhysics/Constraints/TwistLimit.cs +++ b/BepuPhysics/Constraints/TwistLimit.cs @@ -96,8 +96,8 @@ public struct TwistLimitFunctions : IConstraintFunctions references, int count, out Vector jacobiScale) { ref var start = ref Unsafe.As, int>(ref references); - Vector counts; + Vector counts = default; ref var countsStart = ref Unsafe.As, int>(ref counts); for (int i = 0; i < count; ++i) { @@ -253,7 +253,7 @@ public void GetJacobiScaleForBodies(ref TwoBodyReferences references, int count, { ref var startA = ref Unsafe.As, int>(ref references.IndexA); ref var startB = ref Unsafe.As, int>(ref references.IndexB); - Vector countsA, countsB; + Vector countsA = default, countsB = default; ref var countsAStart = ref Unsafe.As, int>(ref countsA); ref var countsBStart = ref Unsafe.As, int>(ref countsB); for (int i = 0; i < count; ++i) @@ -275,7 +275,7 @@ public void GetJacobiScaleForBodies(ref ThreeBodyReferences references, int coun ref var startA = ref Unsafe.As, int>(ref references.IndexA); ref var startB = ref Unsafe.As, int>(ref references.IndexB); ref var startC = ref Unsafe.As, int>(ref references.IndexC); - Vector countsA, countsB, countsC; + Vector countsA = default, countsB = default, countsC = default; ref var countsAStart = ref Unsafe.As, int>(ref countsA); ref var countsBStart = ref Unsafe.As, int>(ref countsB); ref var countsCStart = ref Unsafe.As, int>(ref countsC); @@ -302,7 +302,7 @@ public void GetJacobiScaleForBodies(ref FourBodyReferences references, int count ref var startB = ref Unsafe.As, int>(ref references.IndexB); ref var startC = ref Unsafe.As, int>(ref references.IndexC); ref var startD = ref Unsafe.As, int>(ref references.IndexD); - Vector countsA, countsB, countsC, countsD; + Vector countsA = default, countsB = default, countsC = default, countsD = default; ref var countsAStart = ref Unsafe.As, int>(ref countsA); ref var countsBStart = ref Unsafe.As, int>(ref countsB); ref var countsCStart = ref Unsafe.As, int>(ref countsC); diff --git a/BepuPhysics/Helpers.cs b/BepuPhysics/Helpers.cs index 0b1e70976..1d1934207 100644 --- a/BepuPhysics/Helpers.cs +++ b/BepuPhysics/Helpers.cs @@ -62,8 +62,8 @@ public static void BuildOrthnormalBasis(in Vector3 normal, out Vector3 t1, out V } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void FillVectorWithLaneIndices(out Vector indices) - { + public static void FillVectorWithLaneIndices(out Vector indices) { + indices = default; ref var start = ref Unsafe.As, int>(ref indices); start = 0; for (int i = 1; i < Vector.Count; ++i) diff --git a/BepuPhysics/PoseIntegrator.cs b/BepuPhysics/PoseIntegrator.cs index c17466df0..11f371754 100644 --- a/BepuPhysics/PoseIntegrator.cs +++ b/BepuPhysics/PoseIntegrator.cs @@ -133,8 +133,8 @@ public static void Integrate(in QuaternionWide start, in Vector3Wide angularVelo } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void Integrate(in RigidPose pose, in BodyVelocity velocity, float dt, out RigidPose integratedPose) - { + public static unsafe void Integrate(in RigidPose pose, in BodyVelocity velocity, float dt, out RigidPose integratedPose) { + integratedPose = default; Integrate(pose.Position, velocity.Linear, dt, out integratedPose.Position); Integrate(pose.Orientation, velocity.Angular, dt, out integratedPose.Orientation); } diff --git a/BepuPhysics/StaticDescription.cs b/BepuPhysics/StaticDescription.cs index b6499c1f7..03954f295 100644 --- a/BepuPhysics/StaticDescription.cs +++ b/BepuPhysics/StaticDescription.cs @@ -23,8 +23,8 @@ public struct StaticDescription /// Position of the static. /// Orientation of the static. /// Collidable description for the static. - public StaticDescription(in Vector3 position, in Quaternion orientation, in CollidableDescription collidable) - { + public StaticDescription(in Vector3 position, in Quaternion orientation, in CollidableDescription collidable) { + Pose = default; Pose.Position = position; Pose.Orientation = orientation; Collidable = collidable; @@ -46,8 +46,8 @@ public StaticDescription(in Vector3 position, in CollidableDescription collidabl /// Orientation of the static. /// Index of the static's shape in the simulation shapes set. /// Distance beyond the surface of the static to allow speculative contacts to be generated. - public StaticDescription(in Vector3 position, in Quaternion orientation, TypedIndex shapeIndex, float speculativeMargin) - { + public StaticDescription(in Vector3 position, in Quaternion orientation, TypedIndex shapeIndex, float speculativeMargin) { + Pose = default; Pose.Position = position; Pose.Orientation = orientation; Collidable.Continuity = new ContinuousDetectionSettings(); diff --git a/BepuPhysics/Statics.cs b/BepuPhysics/Statics.cs index 44bf74e86..d66e03e87 100644 --- a/BepuPhysics/Statics.cs +++ b/BepuPhysics/Statics.cs @@ -400,8 +400,10 @@ private void GatherPose(ref float targetPositionBase, ref float targetOrientatio //This looks a little different because it's used by AABB calculation, not constraint pairs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal void GatherDataForBounds(ref int start, int count, out RigidPoses poses, out Vector shapeIndices, out Vector maximumExpansion) - { + internal void GatherDataForBounds(ref int start, int count, out RigidPoses poses, out Vector shapeIndices, out Vector maximumExpansion) { + poses = default; + shapeIndices = default; + maximumExpansion = default; Debug.Assert(count <= Vector.Count); ref var targetPositionBase = ref Unsafe.As, float>(ref poses.Position.X); ref var targetOrientationBase = ref Unsafe.As, float>(ref poses.Orientation.X); diff --git a/BepuPhysics/Trees/RayBatcher.cs b/BepuPhysics/Trees/RayBatcher.cs index c954b9fe2..fa67c899d 100644 --- a/BepuPhysics/Trees/RayBatcher.cs +++ b/BepuPhysics/Trees/RayBatcher.cs @@ -320,7 +320,7 @@ unsafe void TestNode(ref Node node, byte depth, ref TRaySource raySo int bStart = stackPointerB; int a1Start = stackPointerA1; BroadcastNode(ref node, out var wideNode); - TreeRayWide rayBundle; + TreeRayWide rayBundle = default; for (int bundleStartIndex = 0; bundleStartIndex < raySource.RayCount; bundleStartIndex += Vector.Count) { diff --git a/BepuUtilities/Memory/BufferPool.cs b/BepuUtilities/Memory/BufferPool.cs index 1bfbf0f2b..7f679bc41 100644 --- a/BepuUtilities/Memory/BufferPool.cs +++ b/BepuUtilities/Memory/BufferPool.cs @@ -450,7 +450,11 @@ public unsafe void ResizeToAtLeast(ref RawBuffer buffer, int targetSize, int cop if (currentSize != targetSize || pools[powerIndex].GetStartPointerForSlot(slotIndex) != buffer.Memory) { TakeAtLeast(targetSize, out var newBuffer); +#if NET45 + Unsafe.CopyBlock(newBuffer.Memory, buffer.Memory, (uint)copyCount); +#else Buffer.MemoryCopy(buffer.Memory, newBuffer.Memory, buffer.Length, copyCount); +#endif pools[powerIndex].Return(slotIndex); buffer = newBuffer; }