载入中...
搜索中...
未找到
JoltWorldOperations.cpp
浏览该文件的文档.
1// Jolt requires its platform header before any other native header.
2#include <Jolt/Jolt.h>
3
4// Provider implementation dependencies.
5#include <Jolt/Physics/Body/MotionProperties.h>
9namespace eve::physics::jolt {
11 if (!isValid()) return rejected<void>("World expired", eve::DiagnosticCode::StaleHandle);
12 state->continuousCollision = enabled;
13 for (const auto& [id, body] : state->bodies)
14 body->api().SetMotionQuality(
15 body->id, enabled && body->bullet ? JPH::EMotionQuality::LinearCast : JPH::EMotionQuality::Discrete);
16 return success();
17}
19 if (!isValid()) return rejected<bool>("World expired", eve::DiagnosticCode::StaleHandle);
20 return eve::Result<bool>::success(state->continuousCollision);
21}
23 using R [[maybe_unused]] = eve::Result<void>;
24 if (!isValid()) return rejected<void>("Object expired", eve::DiagnosticCode::StaleHandle);
25 if (!std::isfinite(speed) || speed < 0)
26 return rejected<void>("Invalid solver setting", eve::DiagnosticCode::InvalidArgument);
27 auto settings = state->system.GetPhysicsSettings();
28 settings.mMinVelocityForRestitution = speed;
29 state->system.SetPhysicsSettings(settings);
30 return success();
31}
33 using R [[maybe_unused]] = eve::Result<float>;
34 if (!isValid()) return rejected<float>("Object expired", eve::DiagnosticCode::StaleHandle);
35 return R::success(state->system.GetPhysicsSettings().mMinVelocityForRestitution);
36}
38 using R [[maybe_unused]] = eve::Result<void>;
39 return rejected<void>("setContactTuning is not supported");
40}
42 if (!isValid()) return rejected<void>("World expired", eve::DiagnosticCode::StaleHandle);
43 if (!std::isfinite(distance) || distance < 0 || double(distance) * distance > FLT_MAX)
44 return rejected<void>("Invalid contact persistence distance", eve::DiagnosticCode::InvalidArgument);
45 auto settings = state->system.GetPhysicsSettings();
46 settings.mContactPointPreserveLambdaMaxDistSq = distance * distance;
47 settings.mUseBodyPairContactCache = distance > 0;
48 state->system.SetPhysicsSettings(settings);
49 for (const auto& [id, body] : state->bodies) body->api().InvalidateContactCache(body->id);
50 return success();
51}
53 if (!isValid()) return rejected<float>("World expired", eve::DiagnosticCode::StaleHandle);
55 std::sqrt(state->system.GetPhysicsSettings().mContactPointPreserveLambdaMaxDistSq));
56}
58 if (!isValid()) return rejected<void>("World expired", eve::DiagnosticCode::StaleHandle);
59 if (!std::isfinite(speed) || speed <= 0)
60 return rejected<void>("Speed must be positive and finite", eve::DiagnosticCode::InvalidArgument);
61 for (const auto& [id, body] : state->bodies) {
62 auto* native = state->system.GetBodyLockInterfaceNoLock().TryGetBody(body->id);
63 native->GetMotionPropertiesUnchecked()->SetMaxLinearVelocity(speed);
64 }
65 state->maximumLinearSpeed = speed;
66 return success();
67}
69 if (!isValid()) return rejected<float>("World expired", eve::DiagnosticCode::StaleHandle);
70 return eve::Result<float>::success(state->maximumLinearSpeed);
71}
73 using R [[maybe_unused]] = eve::Result<void>;
74 if (!isValid()) return rejected<void>("Object expired", eve::DiagnosticCode::StaleHandle);
75 auto settings = state->system.GetPhysicsSettings();
76 settings.mConstraintWarmStart = enabled;
77 state->system.SetPhysicsSettings(settings);
78 return success();
79}
81 using R [[maybe_unused]] = eve::Result<bool>;
82 if (!isValid()) return rejected<bool>("Object expired", eve::DiagnosticCode::StaleHandle);
83 return R::success(state->system.GetPhysicsSettings().mConstraintWarmStart);
84}
86 if (!isValid()) return rejected<float>("World expired", eve::DiagnosticCode::StaleHandle);
87 const auto bounds = state->system.GetBroadPhaseQuery().GetBounds();
88 return eve::Result<float>::success(bounds.IsValid() ? bounds.mMin.GetX() : 0.f);
89}
91 if (!isValid()) return rejected<float>("World expired", eve::DiagnosticCode::StaleHandle);
92 const auto bounds = state->system.GetBroadPhaseQuery().GetBounds();
93 return eve::Result<float>::success(bounds.IsValid() ? bounds.mMin.GetY() : 0.f);
94}
96 if (!isValid()) return rejected<float>("World expired", eve::DiagnosticCode::StaleHandle);
97 const auto bounds = state->system.GetBroadPhaseQuery().GetBounds();
98 return eve::Result<float>::success(bounds.IsValid() ? bounds.mMin.GetZ() : 0.f);
99}
101 if (!isValid()) return rejected<float>("World expired", eve::DiagnosticCode::StaleHandle);
102 const auto bounds = state->system.GetBroadPhaseQuery().GetBounds();
103 return eve::Result<float>::success(bounds.IsValid() ? bounds.mMax.GetX() : 0.f);
104}
106 if (!isValid()) return rejected<float>("World expired", eve::DiagnosticCode::StaleHandle);
107 const auto bounds = state->system.GetBroadPhaseQuery().GetBounds();
108 return eve::Result<float>::success(bounds.IsValid() ? bounds.mMax.GetY() : 0.f);
109}
111 if (!isValid()) return rejected<float>("World expired", eve::DiagnosticCode::StaleHandle);
112 const auto bounds = state->system.GetBroadPhaseQuery().GetBounds();
113 return eve::Result<float>::success(bounds.IsValid() ? bounds.mMax.GetZ() : 0.f);
114}
116 using R [[maybe_unused]] = eve::Result<int>;
117 if (!isValid()) return rejected<int>("Object expired", eve::DiagnosticCode::StaleHandle);
118 return R::success(static_cast<int>(state->system.GetNumBodies()));
119}
121 using R [[maybe_unused]] = eve::Result<int>;
122 if (!isValid()) return rejected<int>("Object expired", eve::DiagnosticCode::StaleHandle);
123 int count = 0;
124 for (const auto& [id, body] : state->bodies) count += static_cast<int>(body->shapes.size());
125 return R::success(count);
126}
128 using R [[maybe_unused]] = eve::Result<int>;
129 if (!isValid()) return rejected<int>("Object expired", eve::DiagnosticCode::StaleHandle);
130 return R::success(static_cast<int>(state->listener->contacts.size()));
131}
133 using R [[maybe_unused]] = eve::Result<int>;
134 if (!isValid()) return rejected<int>("Object expired", eve::DiagnosticCode::StaleHandle);
135 int count = 0;
136 for (const auto& weak : state->joints)
137 if (auto joint = weak.lock(); joint && joint->alive) ++count;
138 return R::success(count);
139}
141 using R [[maybe_unused]] = eve::Result<int>;
142 return rejected<int>("getIslandCount is not supported");
143}
145 if (!isValid()) return rejected<int>("World expired", eve::DiagnosticCode::StaleHandle);
146 int count = 0;
147 for (const auto& [key, pair] : state->listener->contacts) {
148 const auto* a = state->system.GetBodyLockInterfaceNoLock().TryGetBody(key.GetBody1ID());
149 const auto* b = state->system.GetBodyLockInterfaceNoLock().TryGetBody(key.GetBody2ID());
150 if (!pair.sensorA && !pair.sensorB && a && b && (a->IsActive() || b->IsActive())) ++count;
151 }
153}
155 using R [[maybe_unused]] = eve::Result<int>;
156 return rejected<int>("getRecycledContactCount is not supported");
157}
159 using R [[maybe_unused]] = eve::Result<int>;
160 return rejected<int>("getStaticTreeHeight is not supported");
161}
163 using R [[maybe_unused]] = eve::Result<int>;
164 return rejected<int>("getDynamicTreeHeight is not supported");
165}
167 using R [[maybe_unused]] = eve::Result<int>;
168 return rejected<int>("getMemoryByteCount is not supported");
169}
171 using R [[maybe_unused]] = eve::Result<int>;
172 if (!isValid()) return rejected<int>("Object expired", eve::DiagnosticCode::StaleHandle);
173 return R::success(static_cast<int>(state->system.GetNumActiveBodies(JPH::EBodyType::RigidBody)));
174}
176 if (!isValid()) return rejected<float>("World expired", eve::DiagnosticCode::StaleHandle);
177 return eve::Result<float>::success(state->stepMilliseconds);
178}
180 using R [[maybe_unused]] = eve::Result<float>;
181 return rejected<float>("getProfilePairsMs is not supported");
182}
184 using R [[maybe_unused]] = eve::Result<float>;
185 return rejected<float>("getProfileCollideMs is not supported");
186}
188 using R [[maybe_unused]] = eve::Result<float>;
189 return rejected<float>("getProfileSolveMs is not supported");
190}
192 using R [[maybe_unused]] = eve::Result<float>;
193 return rejected<float>("getProfileBulletsMs is not supported");
194}
196 using R [[maybe_unused]] = eve::Result<float>;
197 return rejected<float>("getProfileSensorsMs is not supported");
198}
199eve::Result<void> WorldBackend::setGravity(float gx, float gy, float gz) {
200 using R [[maybe_unused]] = eve::Result<void>;
201 if (!isValid()) return rejected<void>("Object expired", eve::DiagnosticCode::StaleHandle);
202 if (!isFinite(gx, gy, gz)) return rejected<void>("Invalid gravity", eve::DiagnosticCode::InvalidArgument);
203 state->system.SetGravity({gx, gy, gz});
204 return success();
205}
207 using R [[maybe_unused]] = eve::Result<float>;
208 if (!isValid()) return rejected<float>("Object expired", eve::DiagnosticCode::StaleHandle);
209 return R::success(state->system.GetGravity().GetX());
210}
212 using R [[maybe_unused]] = eve::Result<float>;
213 if (!isValid()) return rejected<float>("Object expired", eve::DiagnosticCode::StaleHandle);
214 return R::success(state->system.GetGravity().GetY());
215}
217 using R [[maybe_unused]] = eve::Result<float>;
218 if (!isValid()) return rejected<float>("Object expired", eve::DiagnosticCode::StaleHandle);
219 return R::success(state->system.GetGravity().GetZ());
220}
222 if (!isValid()) return rejected<void>("World expired", eve::DiagnosticCode::StaleHandle);
223 if (!std::isfinite(speed) || speed < 0)
224 return rejected<void>("Invalid hit threshold", eve::DiagnosticCode::InvalidArgument);
225 state->hitThreshold = speed;
226 return success();
227}
229 if (!isValid()) return rejected<float>("World expired", eve::DiagnosticCode::StaleHandle);
230 return eve::Result<float>::success(state->hitThreshold);
231}
232} // namespace eve::physics::jolt
SQObjectPtr key
Definition ECS.cpp:155
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
OceanWakeSettings settings
std::string body
int count
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
eve::Result< void > setWarmStartingEnabled(bool enabled) override
setWarmStartingEnabled; uses the class ownership, thread and failure contract.
eve::Result< int > getAwakeContactCount() const override
getAwakeContactCount; uses the class ownership, thread and failure contract.
eve::Result< int > getIslandCount() const override
getIslandCount; uses the class ownership, thread and failure contract.
eve::Result< int > getStaticTreeHeight() const override
getStaticTreeHeight; uses the class ownership, thread and failure contract.
eve::Result< void > setContactRecycleDistance(float distance) override
setContactRecycleDistance; uses the class ownership, thread and failure contract.
eve::Result< float > getGravityZ() const override
getGravityZ; uses the class ownership, thread and failure contract.
eve::Result< void > setContinuousCollisionEnabled(bool enabled) override
setContinuousCollisionEnabled; uses the class ownership, thread and failure contract.
eve::Result< int > getAwakeBodyCount() const override
getAwakeBodyCount; uses the class ownership, thread and failure contract.
eve::Result< bool > isContinuousCollisionEnabled() const override
isContinuousCollisionEnabled; uses the class ownership, thread and failure contract.
eve::Result< float > getContactRecycleDistance() const override
getContactRecycleDistance; uses the class ownership, thread and failure contract.
eve::Result< void > setMaximumLinearSpeed(float speed) override
setMaximumLinearSpeed; uses the class ownership, thread and failure contract.
eve::Result< bool > isWarmStartingEnabled() const override
isWarmStartingEnabled; uses the class ownership, thread and failure contract.
eve::Result< float > getMaximumLinearSpeed() const override
getMaximumLinearSpeed; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMaxY() const override
getBoundsMaxY; uses the class ownership, thread and failure contract.
eve::Result< int > getDynamicTreeHeight() const override
getDynamicTreeHeight; uses the class ownership, thread and failure contract.
eve::Result< void > setRestitutionThreshold(float speed) override
setRestitutionThreshold; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMaxZ() const override
getBoundsMaxZ; uses the class ownership, thread and failure contract.
std::shared_ptr< State > state
Definition JoltWorld.h:17
eve::Result< float > getProfileBulletsMs() const override
getProfileBulletsMs; uses the class ownership, thread and failure contract.
eve::Result< void > setGravity(float gx, float gy, float gz) override
setGravity; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMinX() const override
getBoundsMinX; uses the class ownership, thread and failure contract.
eve::Result< float > getProfileCollideMs() const override
getProfileCollideMs; uses the class ownership, thread and failure contract.
eve::Result< float > getGravityY() const override
getGravityY; uses the class ownership, thread and failure contract.
eve::Result< float > getProfileStepMs() const override
getProfileStepMs; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMaxX() const override
getBoundsMaxX; uses the class ownership, thread and failure contract.
eve::Result< float > getProfilePairsMs() const override
getProfilePairsMs; uses the class ownership, thread and failure contract.
eve::Result< void > setContactTuning(float hertz, float dampingRatio, float pushOutSpeed) override
setContactTuning; uses the class ownership, thread and failure contract.
eve::Result< int > getRecycledContactCount() const override
getRecycledContactCount; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMinY() const override
getBoundsMinY; uses the class ownership, thread and failure contract.
eve::Result< float > getRestitutionThreshold() const override
getRestitutionThreshold; uses the class ownership, thread and failure contract.
bool isValid() const noexcept override
Native world liveness.
Definition JoltWorld.cpp:90
eve::Result< float > getHitEventThreshold() const override
getHitEventThreshold; uses the class ownership, thread and failure contract.
eve::Result< void > setHitEventThreshold(float speed) override
setHitEventThreshold; uses the class ownership, thread and failure contract.
eve::Result< int > getShapeCount() const override
getShapeCount; uses the class ownership, thread and failure contract.
eve::Result< int > getMemoryByteCount() const override
getMemoryByteCount; uses the class ownership, thread and failure contract.
eve::Result< int > getContactCount() const override
getContactCount; uses the class ownership, thread and failure contract.
eve::Result< float > getProfileSolveMs() const override
getProfileSolveMs; uses the class ownership, thread and failure contract.
eve::Result< int > getJointCount() const override
getJointCount; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMinZ() const override
getBoundsMinZ; uses the class ownership, thread and failure contract.
eve::Result< float > getProfileSensorsMs() const override
getProfileSensorsMs; uses the class ownership, thread and failure contract.
eve::Result< float > getGravityX() const override
getGravityX; uses the class ownership, thread and failure contract.
eve::Result< int > getBodyCount() const override
getBodyCount; uses the class ownership, thread and failure contract.
eve::Result< void > success()
bool isFinite(float x, float y, float z)
bool enabled
glm::vec4 bounds