Debian Codegraph @

thirdparty/jolt_physics/Jolt/RegisterTypes.cpp

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #include <Jolt/Jolt.h>
6
7 #include <Jolt/RegisterTypes.h>
8 #include <Jolt/Core/Factory.h>
9 #include <Jolt/Core/RTTI.h>
10 #include <Jolt/Core/TickCounter.h>
11 #include <Jolt/Physics/Collision/CollisionDispatch.h>
12 #include <Jolt/Physics/Collision/Shape/TriangleShape.h>
13 #include <Jolt/Physics/Collision/Shape/PlaneShape.h>
14 #include <Jolt/Physics/Collision/Shape/SphereShape.h>
15 #include <Jolt/Physics/Collision/Shape/BoxShape.h>
16 #include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
17 #include <Jolt/Physics/Collision/Shape/TaperedCapsuleShape.h>
18 #include <Jolt/Physics/Collision/Shape/CylinderShape.h>
19 #include <Jolt/Physics/Collision/Shape/TaperedCylinderShape.h>
20 #include <Jolt/Physics/Collision/Shape/ScaledShape.h>
21 #include <Jolt/Physics/Collision/Shape/MeshShape.h>
22 #include <Jolt/Physics/Collision/Shape/ConvexHullShape.h>
23 #include <Jolt/Physics/Collision/Shape/HeightFieldShape.h>
24 #include <Jolt/Physics/Collision/Shape/RotatedTranslatedShape.h>
25 #include <Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.h>
26 #include <Jolt/Physics/Collision/Shape/MutableCompoundShape.h>
27 #include <Jolt/Physics/Collision/Shape/StaticCompoundShape.h>
28 #include <Jolt/Physics/Collision/Shape/EmptyShape.h>
29 #include <Jolt/Physics/Collision/PhysicsMaterialSimple.h>
30 #include <Jolt/Physics/SoftBody/SoftBodyShape.h>
31
32 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, Skeleton)
33 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, SkeletalAnimation)
34 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, RagdollSettings)
35 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PointConstraintSettings)
36 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, SixDOFConstraintSettings)
37 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, SliderConstraintSettings)
38 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, SwingTwistConstraintSettings)
39 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, DistanceConstraintSettings)
40 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, HingeConstraintSettings)
41 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, FixedConstraintSettings)
42 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, ConeConstraintSettings)
43 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PathConstraintSettings)
44 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PathConstraintPath)
45 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PathConstraintPathHermite)
46 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, VehicleConstraintSettings)
47 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, WheeledVehicleControllerSettings)
48 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, WheelSettingsWV)
49 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, TrackedVehicleControllerSettings)
50 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, WheelSettingsTV)
51 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, MotorcycleControllerSettings)
52 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, RackAndPinionConstraintSettings)
53 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, GearConstraintSettings)
54 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PulleyConstraintSettings)
55 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, MotorSettings)
56 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PhysicsScene)
57 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, PhysicsMaterial)
58 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, GroupFilter)
59 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, GroupFilterTable)
60 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, BodyCreationSettings)
61 JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, SoftBodyCreationSettings)
62
63 JPH_NAMESPACE_BEGIN
64
65 bool VerifyJoltVersionIDInternal(uint64 inVersionID)
66 {
67 return inVersionID == JPH_VERSION_ID;
68 }
69
70 void RegisterTypesInternal(uint64 inVersionID)
71 {
72 // Version check
73 if (!VerifyJoltVersionIDInternal(inVersionID))
74 {
75 Trace("Version mismatch, make sure you compile the client code with the same Jolt version and compiler definitions!");
76 uint64 mismatch = JPH_VERSION_ID ^ inVersionID;
77 if (mismatch & 0xffffff)
78 Trace("Client reported version %d.%d.%d, library version is %d.%d.%d.",
79 (inVersionID >> 16) & 0xff, (inVersionID >> 8) & 0xff, inVersionID & 0xff,
80 JPH_VERSION_MAJOR, JPH_VERSION_MINOR, JPH_VERSION_PATCH);
81 auto check_bit = [mismatch](int inBit, const char *inLabel) { if (mismatch & (uint64(1) << (inBit + 23))) Trace("Mismatching define %s.", inLabel); };
82 check_bit(1, "JPH_DOUBLE_PRECISION");
83 check_bit(2, "JPH_CROSS_PLATFORM_DETERMINISTIC");
84 check_bit(3, "JPH_FLOATING_POINT_EXCEPTIONS_ENABLED");
85 check_bit(4, "JPH_PROFILE_ENABLED");
86 check_bit(5, "JPH_EXTERNAL_PROFILE");
87 check_bit(6, "JPH_DEBUG_RENDERER");
88 check_bit(7, "JPH_DISABLE_TEMP_ALLOCATOR");
89 check_bit(8, "JPH_DISABLE_CUSTOM_ALLOCATOR");
90 check_bit(9, "JPH_OBJECT_LAYER_BITS");
91 check_bit(10, "JPH_ENABLE_ASSERTS");
92 check_bit(11, "JPH_OBJECT_STREAM");
93 std::abort();
94 }
95
96 #ifndef JPH_DISABLE_CUSTOM_ALLOCATOR
97 JPH_ASSERT(Allocate != nullptr && Reallocate != nullptr && Free != nullptr && AlignedAllocate != nullptr && AlignedFree != nullptr, "Need to supply an allocator first or call RegisterDefaultAllocator()");
98 #endif // !JPH_DISABLE_CUSTOM_ALLOCATOR
99
100 JPH_ASSERT(Factory::sInstance != nullptr, "Need to create a factory first!");
101
102 // Initialize dispatcher
103 CollisionDispatch::sInit();
104
105 // Register base classes first so that we can specialize them later
106 CompoundShape::sRegister();
107 ConvexShape::sRegister();
108
109 // Register compounds before others so that we can specialize them later (register them in reverse order of collision complexity)
110 MutableCompoundShape::sRegister();
111 StaticCompoundShape::sRegister();
112
113 // Leaf classes
114 TriangleShape::sRegister();
115 PlaneShape::sRegister();
116 SphereShape::sRegister();
117 BoxShape::sRegister();
118 CapsuleShape::sRegister();
119 TaperedCapsuleShape::sRegister();
120 CylinderShape::sRegister();
121 TaperedCylinderShape::sRegister();
122 MeshShape::sRegister();
123 ConvexHullShape::sRegister();
124 HeightFieldShape::sRegister();
125 SoftBodyShape::sRegister();
126
127 // Register these last because their collision functions are simple so we want to execute them first (register them in reverse order of collision complexity)
128 RotatedTranslatedShape::sRegister();
129 OffsetCenterOfMassShape::sRegister();
130 ScaledShape::sRegister();
131 EmptyShape::sRegister();
132
133 // Create list of all types
134 const RTTI *types[] = {
135 JPH_RTTI(SkeletalAnimation),
136 JPH_RTTI(Skeleton),
137 JPH_RTTI(CompoundShapeSettings),
138 JPH_RTTI(StaticCompoundShapeSettings),
139 JPH_RTTI(MutableCompoundShapeSettings),
140 JPH_RTTI(TriangleShapeSettings),
141 JPH_RTTI(PlaneShapeSettings),
142 JPH_RTTI(SphereShapeSettings),
143 JPH_RTTI(BoxShapeSettings),
144 JPH_RTTI(CapsuleShapeSettings),
145 JPH_RTTI(TaperedCapsuleShapeSettings),
146 JPH_RTTI(CylinderShapeSettings),
147 JPH_RTTI(TaperedCylinderShapeSettings),
148 JPH_RTTI(ScaledShapeSettings),
149 JPH_RTTI(MeshShapeSettings),
150 JPH_RTTI(ConvexHullShapeSettings),
151 JPH_RTTI(HeightFieldShapeSettings),
152 JPH_RTTI(RotatedTranslatedShapeSettings),
153 JPH_RTTI(OffsetCenterOfMassShapeSettings),
154 JPH_RTTI(EmptyShapeSettings),
155 JPH_RTTI(RagdollSettings),
156 JPH_RTTI(PointConstraintSettings),
157 JPH_RTTI(SixDOFConstraintSettings),
158 JPH_RTTI(SliderConstraintSettings),
159 JPH_RTTI(SwingTwistConstraintSettings),
160 JPH_RTTI(DistanceConstraintSettings),
161 JPH_RTTI(HingeConstraintSettings),
162 JPH_RTTI(FixedConstraintSettings),
163 JPH_RTTI(ConeConstraintSettings),
164 JPH_RTTI(PathConstraintSettings),
165 JPH_RTTI(VehicleConstraintSettings),
166 JPH_RTTI(WheeledVehicleControllerSettings),
167 JPH_RTTI(WheelSettingsWV),
168 JPH_RTTI(TrackedVehicleControllerSettings),
169 JPH_RTTI(WheelSettingsTV),
170 JPH_RTTI(MotorcycleControllerSettings),
171 JPH_RTTI(PathConstraintPath),
172 JPH_RTTI(PathConstraintPathHermite),
173 JPH_RTTI(RackAndPinionConstraintSettings),
174 JPH_RTTI(GearConstraintSettings),
175 JPH_RTTI(PulleyConstraintSettings),
176 JPH_RTTI(MotorSettings),
177 JPH_RTTI(PhysicsScene),
178 JPH_RTTI(PhysicsMaterial),
179 JPH_RTTI(PhysicsMaterialSimple),
180 JPH_RTTI(GroupFilter),
181 JPH_RTTI(GroupFilterTable),
182 JPH_RTTI(BodyCreationSettings),
183 JPH_RTTI(SoftBodyCreationSettings)
184 };
185
186 // Register them all
187 Factory::sInstance->Register(types, (uint)std::size(types));
188
189 // Initialize default physics material
190 if (PhysicsMaterial::sDefault == nullptr)
191 PhysicsMaterial::sDefault = new PhysicsMaterialSimple("Default", Color::sGrey);
192 }
193
194 void UnregisterTypes()
195 {
196 // Unregister all types
197 if (Factory::sInstance != nullptr)
198 Factory::sInstance->Clear();
199
200 // Delete default physics material
201 PhysicsMaterial::sDefault = nullptr;
202 }
203
204 JPH_NAMESPACE_END