Browse Source

Sonar: Code smell fixes

Jorrit Rouwe 3 years ago
parent
commit
e7ae916d35

+ 1 - 1
Jolt/Core/NonCopyable.h

@@ -9,7 +9,7 @@ namespace JPH {
 class NonCopyable
 class NonCopyable
 {
 {
 public:
 public:
-	inline	NonCopyable() = default;
+			NonCopyable() = default;
 			NonCopyable(const NonCopyable &) = delete;
 			NonCopyable(const NonCopyable &) = delete;
 	void	operator = (const NonCopyable &) = delete;
 	void	operator = (const NonCopyable &) = delete;
 };
 };

+ 15 - 15
Jolt/Physics/Collision/BroadPhase/BroadPhaseQuadTree.cpp

@@ -161,7 +161,7 @@ BroadPhase::AddState BroadPhaseQuadTree::AddBodiesPrepare(BodyID *ioBodies, int
 	// Sort bodies on layer
 	// Sort bodies on layer
 	const BroadPhaseLayer *object_to_broadphase = mObjectToBroadPhaseLayer.data();
 	const BroadPhaseLayer *object_to_broadphase = mObjectToBroadPhaseLayer.data();
 	Body * const * const bodies_ptr = bodies.data(); // C pointer or else sort is incredibly slow in debug mode
 	Body * const * const bodies_ptr = bodies.data(); // C pointer or else sort is incredibly slow in debug mode
-	sort(ioBodies, ioBodies + inNumber, [bodies_ptr, object_to_broadphase](BodyID inLHS, BodyID inRHS) -> bool { return object_to_broadphase[bodies_ptr[inLHS.GetIndex()]->GetObjectLayer()] < object_to_broadphase[bodies_ptr[inRHS.GetIndex()]->GetObjectLayer()]; });
+	sort(ioBodies, ioBodies + inNumber, [bodies_ptr, object_to_broadphase](BodyID inLHS, BodyID inRHS) { return object_to_broadphase[bodies_ptr[inLHS.GetIndex()]->GetObjectLayer()] < object_to_broadphase[bodies_ptr[inRHS.GetIndex()]->GetObjectLayer()]; });
 
 
 	BodyID *b_start = ioBodies, *b_end = ioBodies + inNumber;
 	BodyID *b_start = ioBodies, *b_end = ioBodies + inNumber;
 	while (b_start < b_end)
 	while (b_start < b_end)
@@ -173,7 +173,7 @@ BroadPhase::AddState BroadPhaseQuadTree::AddBodiesPrepare(BodyID *ioBodies, int
 		JPH_ASSERT(broadphase_layer < mNumLayers);
 		JPH_ASSERT(broadphase_layer < mNumLayers);
 
 
 		// Find first body with different layer
 		// Find first body with different layer
-		BodyID *b_mid = upper_bound(b_start, b_end, broadphase_layer, [bodies_ptr, object_to_broadphase](BroadPhaseLayer::Type inLayer, BodyID inBodyID) -> bool { return inLayer < (BroadPhaseLayer::Type)object_to_broadphase[bodies_ptr[inBodyID.GetIndex()]->GetObjectLayer()]; });
+		BodyID *b_mid = upper_bound(b_start, b_end, broadphase_layer, [bodies_ptr, object_to_broadphase](BroadPhaseLayer::Type inLayer, BodyID inBodyID) { return inLayer < (BroadPhaseLayer::Type)object_to_broadphase[bodies_ptr[inBodyID.GetIndex()]->GetObjectLayer()]; });
 
 
 		// Keep track of state for this layer
 		// Keep track of state for this layer
 		LayerState &layer_state = state[broadphase_layer];
 		LayerState &layer_state = state[broadphase_layer];
@@ -287,7 +287,7 @@ void BroadPhaseQuadTree::RemoveBodies(BodyID *ioBodies, int inNumber)
 
 
 	// Sort bodies on layer
 	// Sort bodies on layer
 	Tracking *tracking = mTracking.data(); // C pointer or else sort is incredibly slow in debug mode
 	Tracking *tracking = mTracking.data(); // C pointer or else sort is incredibly slow in debug mode
-	sort(ioBodies, ioBodies + inNumber, [tracking](BodyID inLHS, BodyID inRHS) -> bool { return tracking[inLHS.GetIndex()].mBroadPhaseLayer < tracking[inRHS.GetIndex()].mBroadPhaseLayer; });
+	sort(ioBodies, ioBodies + inNumber, [tracking](BodyID inLHS, BodyID inRHS) { return tracking[inLHS.GetIndex()].mBroadPhaseLayer < tracking[inRHS.GetIndex()].mBroadPhaseLayer; });
 
 
 	BodyID *b_start = ioBodies, *b_end = ioBodies + inNumber;
 	BodyID *b_start = ioBodies, *b_end = ioBodies + inNumber;
 	while (b_start < b_end)
 	while (b_start < b_end)
@@ -297,7 +297,7 @@ void BroadPhaseQuadTree::RemoveBodies(BodyID *ioBodies, int inNumber)
 		JPH_ASSERT(broadphase_layer != (BroadPhaseLayer::Type)cBroadPhaseLayerInvalid);
 		JPH_ASSERT(broadphase_layer != (BroadPhaseLayer::Type)cBroadPhaseLayerInvalid);
 
 
 		// Find first body with different layer
 		// Find first body with different layer
-		BodyID *b_mid = upper_bound(b_start, b_end, broadphase_layer, [tracking](BroadPhaseLayer::Type inLayer, BodyID inBodyID) -> bool { return inLayer < tracking[inBodyID.GetIndex()].mBroadPhaseLayer; });
+		BodyID *b_mid = upper_bound(b_start, b_end, broadphase_layer, [tracking](BroadPhaseLayer::Type inLayer, BodyID inBodyID) { return inLayer < tracking[inBodyID.GetIndex()].mBroadPhaseLayer; });
 
 
 		// Remove all bodies of the same layer
 		// Remove all bodies of the same layer
 		mLayers[broadphase_layer].RemoveBodies(bodies, mTracking, b_start, int(b_mid - b_start));
 		mLayers[broadphase_layer].RemoveBodies(bodies, mTracking, b_start, int(b_mid - b_start));
@@ -337,7 +337,7 @@ void BroadPhaseQuadTree::NotifyBodiesAABBChanged(BodyID *ioBodies, int inNumber,
 
 
 	// Sort bodies on layer
 	// Sort bodies on layer
 	Tracking *tracking = mTracking.data(); // C pointer or else sort is incredibly slow in debug mode
 	Tracking *tracking = mTracking.data(); // C pointer or else sort is incredibly slow in debug mode
-	sort(ioBodies, ioBodies + inNumber, [tracking](BodyID inLHS, BodyID inRHS) -> bool { return tracking[inLHS.GetIndex()].mBroadPhaseLayer < tracking[inRHS.GetIndex()].mBroadPhaseLayer; });
+	sort(ioBodies, ioBodies + inNumber, [tracking](BodyID inLHS, BodyID inRHS) { return tracking[inLHS.GetIndex()].mBroadPhaseLayer < tracking[inRHS.GetIndex()].mBroadPhaseLayer; });
 
 
 	BodyID *b_start = ioBodies, *b_end = ioBodies + inNumber;
 	BodyID *b_start = ioBodies, *b_end = ioBodies + inNumber;
 	while (b_start < b_end)
 	while (b_start < b_end)
@@ -347,7 +347,7 @@ void BroadPhaseQuadTree::NotifyBodiesAABBChanged(BodyID *ioBodies, int inNumber,
 		JPH_ASSERT(broadphase_layer != (BroadPhaseLayer::Type)cBroadPhaseLayerInvalid);
 		JPH_ASSERT(broadphase_layer != (BroadPhaseLayer::Type)cBroadPhaseLayerInvalid);
 
 
 		// Find first body with different layer
 		// Find first body with different layer
-		BodyID *b_mid = upper_bound(b_start, b_end, broadphase_layer, [tracking](BroadPhaseLayer::Type inLayer, BodyID inBodyID) -> bool { return inLayer < tracking[inBodyID.GetIndex()].mBroadPhaseLayer; });
+		BodyID *b_mid = upper_bound(b_start, b_end, broadphase_layer, [tracking](BroadPhaseLayer::Type inLayer, BodyID inBodyID) { return inLayer < tracking[inBodyID.GetIndex()].mBroadPhaseLayer; });
 
 
 		// Nodify all bodies of the same layer changed
 		// Nodify all bodies of the same layer changed
 		mLayers[broadphase_layer].NotifyBodiesAABBChanged(bodies, mTracking, b_start, int(b_mid - b_start));
 		mLayers[broadphase_layer].NotifyBodiesAABBChanged(bodies, mTracking, b_start, int(b_mid - b_start));
@@ -409,7 +409,7 @@ void BroadPhaseQuadTree::CastRay(const RayCast &inRay, RayCastBodyCollector &ioC
 	// Loop over all layers and test the ones that could hit
 	// Loop over all layers and test the ones that could hit
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	{
 	{
-		QuadTree &tree = mLayers[l];
+		const QuadTree &tree = mLayers[l];
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		{
 		{
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
@@ -432,7 +432,7 @@ void BroadPhaseQuadTree::CollideAABox(const AABox &inBox, CollideShapeBodyCollec
 	// Loop over all layers and test the ones that could hit
 	// Loop over all layers and test the ones that could hit
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	{
 	{
-		QuadTree &tree = mLayers[l];
+		const QuadTree &tree = mLayers[l];
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		{
 		{
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
@@ -455,7 +455,7 @@ void BroadPhaseQuadTree::CollideSphere(Vec3Arg inCenter, float inRadius, Collide
 	// Loop over all layers and test the ones that could hit
 	// Loop over all layers and test the ones that could hit
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	{
 	{
-		QuadTree &tree = mLayers[l];
+		const QuadTree &tree = mLayers[l];
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		{
 		{
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
@@ -478,7 +478,7 @@ void BroadPhaseQuadTree::CollidePoint(Vec3Arg inPoint, CollideShapeBodyCollector
 	// Loop over all layers and test the ones that could hit
 	// Loop over all layers and test the ones that could hit
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	{
 	{
-		QuadTree &tree = mLayers[l];
+		const QuadTree &tree = mLayers[l];
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		{
 		{
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
@@ -501,7 +501,7 @@ void BroadPhaseQuadTree::CollideOrientedBox(const OrientedBox &inBox, CollideSha
 	// Loop over all layers and test the ones that could hit
 	// Loop over all layers and test the ones that could hit
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	{
 	{
-		QuadTree &tree = mLayers[l];
+		const QuadTree &tree = mLayers[l];
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		{
 		{
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
@@ -524,7 +524,7 @@ void BroadPhaseQuadTree::CastAABox(const AABoxCast &inBox, CastShapeBodyCollecto
 	// Loop over all layers and test the ones that could hit
 	// Loop over all layers and test the ones that could hit
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 	{
 	{
-		QuadTree &tree = mLayers[l];
+		const QuadTree &tree = mLayers[l];
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		if (tree.HasBodies() && inBroadPhaseLayerFilter.ShouldCollide(BroadPhaseLayer(l)))
 		{
 		{
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
 			JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
@@ -546,7 +546,7 @@ void BroadPhaseQuadTree::FindCollidingPairs(BodyID *ioActiveBodies, int inNumAct
 
 
 	// Sort bodies on layer
 	// Sort bodies on layer
 	const Tracking *tracking = mTracking.data(); // C pointer or else sort is incredibly slow in debug mode
 	const Tracking *tracking = mTracking.data(); // C pointer or else sort is incredibly slow in debug mode
-	sort(ioActiveBodies, ioActiveBodies + inNumActiveBodies, [tracking](BodyID inLHS, BodyID inRHS) -> bool { return tracking[inLHS.GetIndex()].mObjectLayer < tracking[inRHS.GetIndex()].mObjectLayer; });
+	sort(ioActiveBodies, ioActiveBodies + inNumActiveBodies, [tracking](BodyID inLHS, BodyID inRHS) { return tracking[inLHS.GetIndex()].mObjectLayer < tracking[inRHS.GetIndex()].mObjectLayer; });
 
 
 	BodyID *b_start = ioActiveBodies, *b_end = ioActiveBodies + inNumActiveBodies;
 	BodyID *b_start = ioActiveBodies, *b_end = ioActiveBodies + inNumActiveBodies;
 	while (b_start < b_end)
 	while (b_start < b_end)
@@ -556,12 +556,12 @@ void BroadPhaseQuadTree::FindCollidingPairs(BodyID *ioActiveBodies, int inNumAct
 		JPH_ASSERT(object_layer != cObjectLayerInvalid);
 		JPH_ASSERT(object_layer != cObjectLayerInvalid);
 
 
 		// Find first body with different layer
 		// Find first body with different layer
-		BodyID *b_mid = upper_bound(b_start, b_end, object_layer, [tracking](ObjectLayer inLayer, BodyID inBodyID) -> bool { return inLayer < tracking[inBodyID.GetIndex()].mObjectLayer; });
+		BodyID *b_mid = upper_bound(b_start, b_end, object_layer, [tracking](ObjectLayer inLayer, BodyID inBodyID) { return inLayer < tracking[inBodyID.GetIndex()].mObjectLayer; });
 
 
 		// Loop over all layers and test the ones that could hit
 		// Loop over all layers and test the ones that could hit
 		for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 		for (BroadPhaseLayer::Type l = 0; l < mNumLayers; ++l)
 		{
 		{
-			QuadTree &tree = mLayers[l];
+			const QuadTree &tree = mLayers[l];
 			if (tree.HasBodies() && inObjectVsBroadPhaseLayerFilter(object_layer, BroadPhaseLayer(l)))
 			if (tree.HasBodies() && inObjectVsBroadPhaseLayerFilter(object_layer, BroadPhaseLayer(l)))
 			{
 			{
 				JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));
 				JPH_PROFILE(mBroadPhaseLayerToString(BroadPhaseLayer(l)));

+ 1 - 1
Jolt/Physics/Collision/CollisionCollector.h

@@ -55,7 +55,7 @@ public:
 	/// When running a query through the NarrowPhaseQuery class, this will be called for every body that is potentially colliding.
 	/// When running a query through the NarrowPhaseQuery class, this will be called for every body that is potentially colliding.
 	/// It allows collecting additional information needed by the collision collector implementation from the body under lock protection 
 	/// It allows collecting additional information needed by the collision collector implementation from the body under lock protection 
 	/// before AddHit is called (e.g. the user data pointer or the velocity of the body).
 	/// before AddHit is called (e.g. the user data pointer or the velocity of the body).
-	virtual void			OnBody(const Body &inBody)						{ }
+	virtual void			OnBody(const Body &inBody)						{ /* Collects nothing by default */ }
 
 
 	/// Set by the collision detection functions to the current TransformedShape that we're colliding against before calling the AddHit function
 	/// Set by the collision detection functions to the current TransformedShape that we're colliding against before calling the AddHit function
 	void					SetContext(const TransformedShape *inContext)	{ mContext = inContext; }
 	void					SetContext(const TransformedShape *inContext)	{ mContext = inContext; }

+ 1 - 1
Jolt/Physics/Constraints/SixDOFConstraint.cpp

@@ -75,7 +75,7 @@ void SixDOFConstraint::UpdateRotationLimits()
 {
 {
 	// Make values sensible
 	// Make values sensible
 	for (int i = 3; i < 6; ++i)
 	for (int i = 3; i < 6; ++i)
-		if (IsAxisFixed(((EAxis)i)))
+		if (IsAxisFixed((EAxis)i))
 			mLimitMin[i] = mLimitMax[i] = 0.0f;
 			mLimitMin[i] = mLimitMax[i] = 0.0f;
 		else
 		else
 		{
 		{