RegisterTypes.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <Jolt/Jolt.h>
  5. #include <Jolt/RegisterTypes.h>
  6. #include <Jolt/Core/Factory.h>
  7. #include <Jolt/Core/RTTI.h>
  8. #include <Jolt/Physics/Collision/CollisionDispatch.h>
  9. #include <Jolt/Physics/Collision/Shape/TriangleShape.h>
  10. #include <Jolt/Physics/Collision/Shape/SphereShape.h>
  11. #include <Jolt/Physics/Collision/Shape/BoxShape.h>
  12. #include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
  13. #include <Jolt/Physics/Collision/Shape/TaperedCapsuleShape.h>
  14. #include <Jolt/Physics/Collision/Shape/CylinderShape.h>
  15. #include <Jolt/Physics/Collision/Shape/ScaledShape.h>
  16. #include <Jolt/Physics/Collision/Shape/MeshShape.h>
  17. #include <Jolt/Physics/Collision/Shape/ConvexHullShape.h>
  18. #include <Jolt/Physics/Collision/Shape/HeightFieldShape.h>
  19. #include <Jolt/Physics/Collision/Shape/RotatedTranslatedShape.h>
  20. #include <Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.h>
  21. #include <Jolt/Physics/Collision/Shape/MutableCompoundShape.h>
  22. #include <Jolt/Physics/Collision/Shape/StaticCompoundShape.h>
  23. #include <Jolt/Physics/Collision/PhysicsMaterialSimple.h>
  24. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, Skeleton)
  25. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, SkeletalAnimation)
  26. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, CompoundShapeSettings)
  27. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, StaticCompoundShapeSettings)
  28. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, MutableCompoundShapeSettings)
  29. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, TriangleShapeSettings)
  30. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, SphereShapeSettings)
  31. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, BoxShapeSettings)
  32. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, CapsuleShapeSettings)
  33. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, TaperedCapsuleShapeSettings)
  34. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, CylinderShapeSettings)
  35. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, ScaledShapeSettings)
  36. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, MeshShapeSettings)
  37. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, ConvexHullShapeSettings)
  38. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, HeightFieldShapeSettings)
  39. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, RotatedTranslatedShapeSettings)
  40. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, OffsetCenterOfMassShapeSettings)
  41. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, RagdollSettings)
  42. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PointConstraintSettings)
  43. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, SixDOFConstraintSettings)
  44. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, SliderConstraintSettings)
  45. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, SwingTwistConstraintSettings)
  46. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, DistanceConstraintSettings)
  47. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, HingeConstraintSettings)
  48. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, FixedConstraintSettings)
  49. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, ConeConstraintSettings)
  50. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PathConstraintSettings)
  51. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PathConstraintPath)
  52. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PathConstraintPathHermite)
  53. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, VehicleConstraintSettings)
  54. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, WheeledVehicleControllerSettings)
  55. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, RackAndPinionConstraintSettings)
  56. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, GearConstraintSettings)
  57. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PulleyConstraintSettings)
  58. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, MotorSettings)
  59. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PhysicsScene)
  60. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PhysicsMaterial)
  61. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, GroupFilter)
  62. JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, GroupFilterTable)
  63. JPH_NAMESPACE_BEGIN
  64. void RegisterTypes()
  65. {
  66. #ifndef JPH_DISABLE_CUSTOM_ALLOCATOR
  67. JPH_ASSERT(Allocate != nullptr && Free != nullptr && AlignedAllocate != nullptr && AlignedFree != nullptr, "Need to supply an allocator first or call RegisterDefaultAllocator()");
  68. #endif // !JPH_DISABLE_CUSTOM_ALLOCATOR
  69. JPH_ASSERT(Factory::sInstance != nullptr, "Need to create a factory first!");
  70. // Initialize dispatcher
  71. CollisionDispatch::sInit();
  72. // Register base classes first so that we can specialize them later
  73. CompoundShape::sRegister();
  74. ConvexShape::sRegister();
  75. // Register compounds before others so that we can specialize them later (register them in reverse order of collision complexity)
  76. MutableCompoundShape::sRegister();
  77. StaticCompoundShape::sRegister();
  78. // Leaf classes
  79. TriangleShape::sRegister();
  80. SphereShape::sRegister();
  81. BoxShape::sRegister();
  82. CapsuleShape::sRegister();
  83. TaperedCapsuleShape::sRegister();
  84. CylinderShape::sRegister();
  85. MeshShape::sRegister();
  86. ConvexHullShape::sRegister();
  87. HeightFieldShape::sRegister();
  88. // Register these last because their collision functions are simple so we want to execute them first (register them in reverse order of collision complexity)
  89. RotatedTranslatedShape::sRegister();
  90. OffsetCenterOfMassShape::sRegister();
  91. ScaledShape::sRegister();
  92. // Create list of all types
  93. const RTTI *types[] = {
  94. JPH_RTTI(SkeletalAnimation),
  95. JPH_RTTI(Skeleton),
  96. JPH_RTTI(CompoundShapeSettings),
  97. JPH_RTTI(StaticCompoundShapeSettings),
  98. JPH_RTTI(MutableCompoundShapeSettings),
  99. JPH_RTTI(TriangleShapeSettings),
  100. JPH_RTTI(SphereShapeSettings),
  101. JPH_RTTI(BoxShapeSettings),
  102. JPH_RTTI(CapsuleShapeSettings),
  103. JPH_RTTI(TaperedCapsuleShapeSettings),
  104. JPH_RTTI(CylinderShapeSettings),
  105. JPH_RTTI(ScaledShapeSettings),
  106. JPH_RTTI(MeshShapeSettings),
  107. JPH_RTTI(ConvexHullShapeSettings),
  108. JPH_RTTI(HeightFieldShapeSettings),
  109. JPH_RTTI(RotatedTranslatedShapeSettings),
  110. JPH_RTTI(OffsetCenterOfMassShapeSettings),
  111. JPH_RTTI(RagdollSettings),
  112. JPH_RTTI(PointConstraintSettings),
  113. JPH_RTTI(SixDOFConstraintSettings),
  114. JPH_RTTI(SliderConstraintSettings),
  115. JPH_RTTI(SwingTwistConstraintSettings),
  116. JPH_RTTI(DistanceConstraintSettings),
  117. JPH_RTTI(HingeConstraintSettings),
  118. JPH_RTTI(FixedConstraintSettings),
  119. JPH_RTTI(ConeConstraintSettings),
  120. JPH_RTTI(PathConstraintSettings),
  121. JPH_RTTI(VehicleConstraintSettings),
  122. JPH_RTTI(WheeledVehicleControllerSettings),
  123. JPH_RTTI(PathConstraintPath),
  124. JPH_RTTI(PathConstraintPathHermite),
  125. JPH_RTTI(RackAndPinionConstraintSettings),
  126. JPH_RTTI(GearConstraintSettings),
  127. JPH_RTTI(PulleyConstraintSettings),
  128. JPH_RTTI(MotorSettings),
  129. JPH_RTTI(PhysicsScene),
  130. JPH_RTTI(PhysicsMaterial),
  131. JPH_RTTI(PhysicsMaterialSimple),
  132. JPH_RTTI(GroupFilter),
  133. JPH_RTTI(GroupFilterTable)
  134. };
  135. // Register them all
  136. Factory::sInstance->Register(types, (uint)size(types));
  137. // Initialize default physics material
  138. if (PhysicsMaterial::sDefault == nullptr)
  139. PhysicsMaterial::sDefault = new PhysicsMaterialSimple("Default", Color::sGrey);
  140. }
  141. void UnregisterTypes()
  142. {
  143. // Unregister all types
  144. if (Factory::sInstance != nullptr)
  145. Factory::sInstance->Clear();
  146. // Delete default physics material
  147. PhysicsMaterial::sDefault = nullptr;
  148. }
  149. JPH_NAMESPACE_END