소스 검색

Added option to determine number of bits in ObjectLayer (#478)

Jorrit Rouwe 2 년 전
부모
커밋
3640711645
8개의 변경된 파일50개의 추가작업 그리고 37개의 파일을 삭제
  1. 3 0
      Build/CMakeLists.txt
  2. 3 3
      HelloWorld/HelloWorld.cpp
  3. 5 0
      Jolt/Jolt.cmake
  4. 5 9
      Jolt/Physics/Body/Body.h
  5. 11 2
      Jolt/Physics/Collision/ObjectLayer.h
  6. 3 3
      PerformanceTest/Layers.h
  7. 9 9
      Samples/Layers.h
  8. 11 11
      UnitTests/Layers.h

+ 3 - 0
Build/CMakeLists.txt

@@ -24,6 +24,9 @@ option(INTERPROCEDURAL_OPTIMIZATION "Enable interprocedural optimizations" ON)
 # Note that this currently only works using MSVC. Clang turns Float2 into a SIMD vector sometimes causing floating point exceptions (the option is ignored).
 # Note that this currently only works using MSVC. Clang turns Float2 into a SIMD vector sometimes causing floating point exceptions (the option is ignored).
 option(FLOATING_POINT_EXCEPTIONS_ENABLED "Enable floating point exceptions" ON)
 option(FLOATING_POINT_EXCEPTIONS_ENABLED "Enable floating point exceptions" ON)
 
 
+# Number of bits to use in ObjectLayer. Can be 16 or 32.
+option(OBJECT_LAYER_BITS "Number of bits in ObjectLayer" 16)
+
 # Select X86 processor features to use (if everything is off it will be SSE2 compatible)
 # Select X86 processor features to use (if everything is off it will be SSE2 compatible)
 option(USE_SSE4_1 "Enable SSE4.1" ON)
 option(USE_SSE4_1 "Enable SSE4.1" ON)
 option(USE_SSE4_2 "Enable SSE4.2" ON)
 option(USE_SSE4_2 "Enable SSE4.2" ON)

+ 3 - 3
HelloWorld/HelloWorld.cpp

@@ -69,9 +69,9 @@ static bool AssertFailedImpl(const char *inExpression, const char *inMessage, co
 // but only if you do collision testing).
 // but only if you do collision testing).
 namespace Layers
 namespace Layers
 {
 {
-	static constexpr uint8 NON_MOVING = 0;
-	static constexpr uint8 MOVING = 1;
-	static constexpr uint8 NUM_LAYERS = 2;
+	static constexpr ObjectLayer NON_MOVING = 0;
+	static constexpr ObjectLayer MOVING = 1;
+	static constexpr ObjectLayer NUM_LAYERS = 2;
 };
 };
 
 
 /// Class that determines if two object layers can collide
 /// Class that determines if two object layers can collide

+ 5 - 0
Jolt/Jolt.cmake

@@ -453,6 +453,11 @@ if (CROSS_PLATFORM_DETERMINISTIC)
 	target_compile_definitions(Jolt PUBLIC JPH_CROSS_PLATFORM_DETERMINISTIC)
 	target_compile_definitions(Jolt PUBLIC JPH_CROSS_PLATFORM_DETERMINISTIC)
 endif()
 endif()
 
 
+# Setting to determine number of bits in ObjectLayer
+if (OBJECT_LAYER_BITS)
+	target_compile_definitions(Jolt PUBLIC JPH_OBJECT_LAYER_BITS=${OBJECT_LAYER_BITS})
+endif()
+
 # Emit the instruction set definitions to ensure that child projects use the same settings even if they override the used instruction sets (a mismatch causes link errors)
 # Emit the instruction set definitions to ensure that child projects use the same settings even if they override the used instruction sets (a mismatch causes link errors)
 function(EMIT_X86_INSTRUCTION_SET_DEFINITIONS)
 function(EMIT_X86_INSTRUCTION_SET_DEFINITIONS)
 	if (USE_AVX512)
 	if (USE_AVX512)

+ 5 - 9
Jolt/Physics/Body/Body.h

@@ -29,7 +29,7 @@ class BodyCreationSettings;
 /// The functions that get/set the position of the body all indicate if they are relative to the center of mass or to the original position in which the shape was created.
 /// The functions that get/set the position of the body all indicate if they are relative to the center of mass or to the original position in which the shape was created.
 ///
 ///
 /// The linear velocity is also velocity of the center of mass, to correct for this: \f$VelocityCOM = Velocity - AngularVelocity \times ShapeCOM\f$.
 /// The linear velocity is also velocity of the center of mass, to correct for this: \f$VelocityCOM = Velocity - AngularVelocity \times ShapeCOM\f$.
-class Body : public NonCopyable
+class alignas(JPH_RVECTOR_ALIGNMENT) Body : public NonCopyable
 {
 {
 public:
 public:
 	JPH_OVERRIDE_NEW_DELETE
 	JPH_OVERRIDE_NEW_DELETE
@@ -319,7 +319,7 @@ private:
 	float					mRestitution;													///< Restitution of body (dimensionless number, usually between 0 and 1, 0 = completely inelastic collision response, 1 = completely elastic collision response)
 	float					mRestitution;													///< Restitution of body (dimensionless number, usually between 0 and 1, 0 = completely inelastic collision response, 1 = completely elastic collision response)
 	BodyID					mID;															///< ID of the body (index in the bodies array)
 	BodyID					mID;															///< ID of the body (index in the bodies array)
 
 
-	// 2 bytes aligned
+	// 2 or 4 bytes aligned
 	ObjectLayer				mObjectLayer;													///< The collision layer this body belongs to (determines if two objects can collide)
 	ObjectLayer				mObjectLayer;													///< The collision layer this body belongs to (determines if two objects can collide)
 
 
 	// 1 byte aligned
 	// 1 byte aligned
@@ -327,15 +327,11 @@ private:
 	EMotionType				mMotionType;													///< Type of motion (static, dynamic or kinematic)
 	EMotionType				mMotionType;													///< Type of motion (static, dynamic or kinematic)
 	atomic<uint8>			mFlags = 0;														///< See EFlags for possible flags
 	atomic<uint8>			mFlags = 0;														///< See EFlags for possible flags
 	
 	
-	// 121 bytes up to here (64-bit mode, single precision)
+	// 121 bytes up to here (64-bit mode, single precision, 16-bit ObjectLayer)
 
 
 #if JPH_CPU_ADDRESS_BITS == 32
 #if JPH_CPU_ADDRESS_BITS == 32
-	// Padding for 32 bit mode
-	char					mPadding[19];
-#endif
-#ifdef JPH_DOUBLE_PRECISION
-	// Padding to align to 256 bit
-	char					mPadding2[16];
+	// Padding for mShape, mMotionProperties, mCollisionGroup.mGroupFilter being 4 instead of 8 bytes in 32 bit mode
+	uint8					mPadding[12];
 #endif
 #endif
 };
 };
 
 

+ 11 - 2
Jolt/Physics/Collision/ObjectLayer.h

@@ -9,10 +9,19 @@
 JPH_NAMESPACE_BEGIN
 JPH_NAMESPACE_BEGIN
 
 
 /// Layer that objects can be in, determines which other objects it can collide with
 /// Layer that objects can be in, determines which other objects it can collide with
-using ObjectLayer = uint16;
+#ifndef JPH_OBJECT_LAYER_BITS
+	#define JPH_OBJECT_LAYER_BITS 16
+#endif // JPH_OBJECT_LAYER_BITS
+#if JPH_OBJECT_LAYER_BITS == 16
+	using ObjectLayer = uint16;
+#elif JPH_OBJECT_LAYER_BITS == 32
+	using ObjectLayer = uint32;
+#else
+	#error "JPH_OBJECT_LAYER_BITS must be 16 or 32"
+#endif
 
 
 /// Constant value used to indicate an invalid object layer
 /// Constant value used to indicate an invalid object layer
-static constexpr ObjectLayer cObjectLayerInvalid = 0xffff;
+static constexpr ObjectLayer cObjectLayerInvalid = ObjectLayer(~ObjectLayer(0U));
 
 
 /// Filter class for object layers
 /// Filter class for object layers
 class ObjectLayerFilter : public NonCopyable
 class ObjectLayerFilter : public NonCopyable

+ 3 - 3
PerformanceTest/Layers.h

@@ -10,9 +10,9 @@
 /// Layer that objects can be in, determines which other objects it can collide with
 /// Layer that objects can be in, determines which other objects it can collide with
 namespace Layers
 namespace Layers
 {
 {
-	static constexpr uint8 NON_MOVING = 0;
-	static constexpr uint8 MOVING = 1;
-	static constexpr uint8 NUM_LAYERS = 2;
+	static constexpr ObjectLayer NON_MOVING = 0;
+	static constexpr ObjectLayer MOVING = 1;
+	static constexpr ObjectLayer NUM_LAYERS = 2;
 };
 };
 
 
 /// Class that determines if two object layers can collide
 /// Class that determines if two object layers can collide

+ 9 - 9
Samples/Layers.h

@@ -10,15 +10,15 @@
 /// Layer that objects can be in, determines which other objects it can collide with
 /// Layer that objects can be in, determines which other objects it can collide with
 namespace Layers
 namespace Layers
 {
 {
-	static constexpr uint8 UNUSED1 = 0; // 4 unused values so that broadphase layers values don't match with object layer values (for testing purposes)
-	static constexpr uint8 UNUSED2 = 1;
-	static constexpr uint8 UNUSED3 = 2;
-	static constexpr uint8 UNUSED4 = 3;
-	static constexpr uint8 NON_MOVING = 4;
-	static constexpr uint8 MOVING = 5;
-	static constexpr uint8 DEBRIS = 6; // Example: Debris collides only with NON_MOVING
-	static constexpr uint8 SENSOR = 7; // Sensors only collide with MOVING objects
-	static constexpr uint8 NUM_LAYERS = 8;
+	static constexpr ObjectLayer UNUSED1 = 0; // 4 unused values so that broadphase layers values don't match with object layer values (for testing purposes)
+	static constexpr ObjectLayer UNUSED2 = 1;
+	static constexpr ObjectLayer UNUSED3 = 2;
+	static constexpr ObjectLayer UNUSED4 = 3;
+	static constexpr ObjectLayer NON_MOVING = 4;
+	static constexpr ObjectLayer MOVING = 5;
+	static constexpr ObjectLayer DEBRIS = 6; // Example: Debris collides only with NON_MOVING
+	static constexpr ObjectLayer SENSOR = 7; // Sensors only collide with MOVING objects
+	static constexpr ObjectLayer NUM_LAYERS = 8;
 };
 };
 
 
 /// Class that determines if two object layers can collide
 /// Class that determines if two object layers can collide

+ 11 - 11
UnitTests/Layers.h

@@ -10,17 +10,17 @@
 /// Layer that objects can be in, determines which other objects it can collide with
 /// Layer that objects can be in, determines which other objects it can collide with
 namespace Layers
 namespace Layers
 {
 {
-	static constexpr uint8 UNUSED1 = 0; // 5 unused values so that broadphase layers values don't match with object layer values (for testing purposes)
-	static constexpr uint8 UNUSED2 = 1;
-	static constexpr uint8 UNUSED3 = 2;
-	static constexpr uint8 UNUSED4 = 3;
-	static constexpr uint8 UNUSED5 = 4;
-	static constexpr uint8 NON_MOVING = 5;
-	static constexpr uint8 MOVING = 6;
-	static constexpr uint8 HQ_DEBRIS = 7; // High quality debris collides with MOVING and NON_MOVING but not with any debris
-	static constexpr uint8 LQ_DEBRIS = 8; // Low quality debris only collides with NON_MOVING
-	static constexpr uint8 SENSOR = 9; // Sensors only collide with MOVING objects
-	static constexpr uint8 NUM_LAYERS = 10;
+	static constexpr ObjectLayer UNUSED1 = 0; // 5 unused values so that broadphase layers values don't match with object layer values (for testing purposes)
+	static constexpr ObjectLayer UNUSED2 = 1;
+	static constexpr ObjectLayer UNUSED3 = 2;
+	static constexpr ObjectLayer UNUSED4 = 3;
+	static constexpr ObjectLayer UNUSED5 = 4;
+	static constexpr ObjectLayer NON_MOVING = 5;
+	static constexpr ObjectLayer MOVING = 6;
+	static constexpr ObjectLayer HQ_DEBRIS = 7; // High quality debris collides with MOVING and NON_MOVING but not with any debris
+	static constexpr ObjectLayer LQ_DEBRIS = 8; // Low quality debris only collides with NON_MOVING
+	static constexpr ObjectLayer SENSOR = 9; // Sensors only collide with MOVING objects
+	static constexpr ObjectLayer NUM_LAYERS = 10;
 };
 };
 
 
 /// Class that determines if two object layers can collide
 /// Class that determines if two object layers can collide