载入中...
搜索中...
未找到
World3D.cpp
浏览该文件的文档.
1#include "physics/World3D.h"
2#include "physics/Body3D.h"
3#include "physics/Joint3D.h"
6#include "physics/Shape3D.h"
8#if EVENGINE_HAS_JOLT
10#endif
12
13#include "common/Exception.h"
14#include "common/Profile.h"
16
17
18#include <algorithm>
19#include <cfloat>
20#include <cmath>
21#include <mutex>
22#include <unordered_map>
23#include <unordered_set>
24#include <utility>
25
27
28namespace eve::physics {
29using namespace world3d_detail;
30namespace {
31
32uint64_t stablePairKey(int idA, int idB) {
33 const uint32_t low = static_cast<uint32_t>(std::min(idA, idB));
34 const uint32_t high = static_cast<uint32_t>(std::max(idA, idB));
35 return (static_cast<uint64_t>(high) << 32) | low;
36}
37
38bool pairContains(uint64_t key, int id) {
39 const uint32_t value = static_cast<uint32_t>(id);
40 return static_cast<uint32_t>(key) == value || static_cast<uint32_t>(key >> 32) == value;
41}
42
43
44struct WorldRegistry {
45 std::mutex mutex;
46 std::unordered_map<PhysicsWorldHandle::index_type, World3D*> worlds;
47};
48WorldRegistry& worldRegistry() {
49 static auto* registry = new WorldRegistry;
50 return *registry;
51}
52
53} // namespace
54
56 float gravityZ, bool sleep,
59#if EVENGINE_HAS_JOLT
61#endif
62 )
64 eve::DiagnosticCode::Unsupported, "Requested rigid backend is not available in this build",
65 "physics.world3d.backend"));
66 if (!std::isfinite(gravityX) || !std::isfinite(gravityY) || !std::isfinite(gravityZ))
68 eve::DiagnosticCode::InvalidArgument, "Gravity must be finite", "physics.world3d.gravity"));
69 try {
71 std::unique_ptr<World3D>(new World3D(gravityX, gravityY, gravityZ, sleep, instanceId, true, backend)));
72 } catch (const eve::Exception &error) {
74 eve::Diagnostic::error(eve::DiagnosticCode::Failed, error.what(), "physics.world3d.create"));
75 }
76}
77
78World3D::World3D(float gravityX, float gravityY, float gravityZ, bool sleep, eve::PersistentId instanceId)
79 : World3D(gravityX, gravityY, gravityZ, sleep, instanceId, true, RigidBackend3D::Box3D) {}
80
81World3D::World3D(float gravityX, float gravityY, float gravityZ, bool sleep, eve::PersistentId instanceId,
82 bool registerQueries, RigidBackend3D backend)
83 : rigidBackendKind_(backend), instanceId_(instanceId) {
84 runtimeHandle_ = detail::allocatePhysicsWorldHandle();
85 if (instanceId_.isNil()) instanceId_ = detail::makePhysicsWorldPersistentId(runtimeHandle_);
86#if EVENGINE_HAS_JOLT
88 rigidBackend_ = worldValue(jolt::makeWorld(*this, gravityX, gravityY, gravityZ, sleep));
89 else
90#endif
91 rigidBackend_ = worldValue(box3d::makeWorld(*this, gravityX, gravityY, gravityZ, sleep));
92 auto selection = rigidBackend_->selectSimulation();
93 if (!selection) {
94 const eve::Status status = selection.status();
95 throw eve::Exception("World3D: cannot select a simulation backend: %s", status.describe().c_str());
96 }
97 backendSelectionStatus_ = selection.status();
98 auto selected = std::move(selection).takeValue();
99 backendFallback_ = selected.usedFallback;
100 simulation_ = std::move(selected.backend);
101 if (registerQueries) registerCameraObstructionWorld(this);
102 auto targetingRegistration = registerQueries ? registerTargetingLineOfSightWorld(this)
103 : eve::Result<void>::success();
104 if (!registerQueries) {
105 targetingRegistration.ignore("detached topology candidate does not publish targeting queries");
106 } else if (!targetingRegistration) {
107 // Physics supports multiple worlds; targeting LOS deliberately exposes
108 // only one, so an explicitly consumed Conflict leaves this world valid
109 // without making its query context ambiguous.
110 targetingRegistration.ignore("another World3D is already the active targeting LOS world");
111 }
112 auto& registry = worldRegistry();
113 std::scoped_lock registryLock(registry.mutex);
114 registry.worlds[runtimeHandle_.index()] = this;
115}
116
118 worldValue(rigidBackend_->setContinuousCollisionEnabled(enabled));
119}
120
121
122bool World3D::isContinuousCollisionEnabled() const { return worldValue(rigidBackend_->isContinuousCollisionEnabled()); }
123
124
125void World3D::setRestitutionThreshold(float speed) { worldValue(rigidBackend_->setRestitutionThreshold(speed)); }
126
127
128float World3D::getRestitutionThreshold() const { return worldValue(rigidBackend_->getRestitutionThreshold()); }
129
130
131void World3D::setContactTuning(float hertz, float dampingRatio, float pushOutSpeed) {
132 worldValue(rigidBackend_->setContactTuning(hertz, dampingRatio, pushOutSpeed));
133}
134
135
137 worldValue(rigidBackend_->setContactRecycleDistance(distance));
138}
139
140
141float World3D::getContactRecycleDistance() const { return worldValue(rigidBackend_->getContactRecycleDistance()); }
142
143
144void World3D::setMaximumLinearSpeed(float speed) { worldValue(rigidBackend_->setMaximumLinearSpeed(speed)); }
145
146
147float World3D::getMaximumLinearSpeed() const { return worldValue(rigidBackend_->getMaximumLinearSpeed()); }
148
149
150void World3D::setWarmStartingEnabled(bool enabled) { worldValue(rigidBackend_->setWarmStartingEnabled(enabled)); }
151
152
153bool World3D::isWarmStartingEnabled() const { return worldValue(rigidBackend_->isWarmStartingEnabled()); }
154
155
156int World3D::explode(float x, float y, float z, float radius, float falloff,
157 float impulsePerArea, int maskBits) {
158 return worldValue(rigidBackend_->explode(x, y, z, radius, falloff, impulsePerArea, maskBits));
159}
160
161
162const World3D::ExplosionResult &World3D::explosionResultAt(int index,
163 const char *operation) const {
164 if (index < 0 || index >= static_cast<int>(explosionResults_.size()))
165 throw eve::Exception("World3D.%s: index out of range", operation);
166 return explosionResults_[static_cast<size_t>(index)];
167}
168
169#define EV_EXPLOSION_INT_GETTER(name, member) \
170 int World3D::name(int index) const { return explosionResultAt(index, #name).member; }
171
172EV_EXPLOSION_INT_GETTER(getExplosionResultBodyId, bodyId)
173#undef EV_EXPLOSION_INT_GETTER
174
175#define EV_EXPLOSION_FLOAT_GETTER(name, member) \
176 float World3D::name(int index) const { return explosionResultAt(index, #name).member; }
177
178EV_EXPLOSION_FLOAT_GETTER(getExplosionResultDeltaVelocityX, deltaVX)
179EV_EXPLOSION_FLOAT_GETTER(getExplosionResultDeltaVelocityY, deltaVY)
180EV_EXPLOSION_FLOAT_GETTER(getExplosionResultDeltaVelocityZ, deltaVZ)
181EV_EXPLOSION_FLOAT_GETTER(getExplosionResultDeltaAngularVelocityX, deltaWX)
182EV_EXPLOSION_FLOAT_GETTER(getExplosionResultDeltaAngularVelocityY, deltaWY)
183EV_EXPLOSION_FLOAT_GETTER(getExplosionResultDeltaAngularVelocityZ, deltaWZ)
184#undef EV_EXPLOSION_FLOAT_GETTER
185
186float World3D::getBoundsMinX() const { return worldValue(rigidBackend_->getBoundsMinX()); }
187
188float World3D::getBoundsMinY() const { return worldValue(rigidBackend_->getBoundsMinY()); }
189
190float World3D::getBoundsMinZ() const { return worldValue(rigidBackend_->getBoundsMinZ()); }
191
192float World3D::getBoundsMaxX() const { return worldValue(rigidBackend_->getBoundsMaxX()); }
193
194float World3D::getBoundsMaxY() const { return worldValue(rigidBackend_->getBoundsMaxY()); }
195
196float World3D::getBoundsMaxZ() const { return worldValue(rigidBackend_->getBoundsMaxZ()); }
197
198
199int World3D::getBodyCount() const { return worldValue(rigidBackend_->getBodyCount()); }
200
201int World3D::getShapeCount() const { return worldValue(rigidBackend_->getShapeCount()); }
202
203int World3D::getContactCount() const { return worldValue(rigidBackend_->getContactCount()); }
204
205int World3D::getJointCount() const { return worldValue(rigidBackend_->getJointCount()); }
206
207int World3D::getIslandCount() const { return worldValue(rigidBackend_->getIslandCount()); }
208
209int World3D::getAwakeContactCount() const { return worldValue(rigidBackend_->getAwakeContactCount()); }
210
211int World3D::getRecycledContactCount() const { return worldValue(rigidBackend_->getRecycledContactCount()); }
212
213int World3D::getStaticTreeHeight() const { return worldValue(rigidBackend_->getStaticTreeHeight()); }
214
215int World3D::getDynamicTreeHeight() const { return worldValue(rigidBackend_->getDynamicTreeHeight()); }
216
217int World3D::getMemoryByteCount() const { return worldValue(rigidBackend_->getMemoryByteCount()); }
218
219
220int World3D::getAwakeBodyCount() const { return worldValue(rigidBackend_->getAwakeBodyCount()); }
221
222
223float World3D::getProfileStepMs() const { return worldValue(rigidBackend_->getProfileStepMs()); }
224
225float World3D::getProfilePairsMs() const { return worldValue(rigidBackend_->getProfilePairsMs()); }
226
227float World3D::getProfileCollideMs() const { return worldValue(rigidBackend_->getProfileCollideMs()); }
228
229float World3D::getProfileSolveMs() const { return worldValue(rigidBackend_->getProfileSolveMs()); }
230
231float World3D::getProfileBulletsMs() const { return worldValue(rigidBackend_->getProfileBulletsMs()); }
232
233float World3D::getProfileSensorsMs() const { return worldValue(rigidBackend_->getProfileSensorsMs()); }
234
235
237
238
239bool World3D::isValid() const { return !destroyed_ && rigidBackend_ && rigidBackend_->isValid(); }
240
242 if (destroyed_) return;
243 cancelForceStep();
244 {
245 auto& registry = worldRegistry();
246 std::scoped_lock registryLock(registry.mutex);
247 auto found = registry.worlds.find(runtimeHandle_.index());
248 if (found != registry.worlds.end() && found->second == this) registry.worlds.erase(found);
249 }
250 invalidateCouplings3D();
251 restoredCouplings3D_.clear();
252 destroyed_ = true;
253 // Invalidate borrowed query registrations without touching any global
254 // registry. This keeps teardown safe for every static destruction order.
255 queryLifetime_.reset();
256
257 std::vector<Mechanism3D *> mechanisms(mechanisms_.begin(), mechanisms_.end());
258 for (Mechanism3D *mechanism : mechanisms) {
259 if (mechanism) mechanism->invalidate();
260 }
261 mechanisms_.clear();
262
263 std::vector<Joint3D *> joints(joints_.begin(), joints_.end());
264 for (Joint3D *joint : joints) {
265 if (joint) joint->invalidate();
266 }
267 joints_.clear();
268 restoredJoints_.clear();
269 disabledBodyPairs_.clear();
270 disabledShapePairs_.clear();
271
272 std::vector<Body3D *> bodies(bodies_.begin(), bodies_.end());
273 for (Body3D *b : bodies) {
274 if (b) b->invalidate();
275 }
276 bodies_.clear();
277
278 std::vector<Shape3D *> shapes(shapes_.begin(), shapes_.end());
279 for (Shape3D *s : shapes) {
280 if (s) s->invalidate();
281 }
282 shapes_.clear();
283 restoredShapes_.clear();
284 restoredBodies_.clear();
285
286 simulation_.reset();
287 if (rigidBackend_) rigidBackend_->destroy();
289 shapeRecords_.clear();
290 shapeHandles_.clear();
291 shapeRawHandles_.clear();
292 jointHandles_.clear();
293 runtimeHandle_ = PhysicsWorldHandle::invalid();
294}
295
297 if (handle.isInvalid()) return nullptr;
298 auto& registry = worldRegistry();
299 std::scoped_lock registryLock(registry.mutex);
300 auto found = registry.worlds.find(handle.index());
301 if (found == registry.worlds.end() || !found->second || found->second->runtimeHandle() != handle) return nullptr;
302 return found->second;
303}
304
306 if (!joint) return;
307 releaseCouplingsForJoint(joint->runtimeHandle());
308 joints_.erase(joint);
309 if (joint->runtimeHandle().isValid()) jointHandles_.erase(joint->runtimeHandle());
310 for (auto it = jointHandles_.begin(); it != jointHandles_.end();) {
311 if (it->second == joint)
312 it = jointHandles_.erase(it);
313 else
314 ++it;
315 }
316}
317
318void World3D::setGravity(float gx, float gy, float gz) { worldValue(rigidBackend_->setGravity(gx, gy, gz)); }
319
320
321float World3D::getGravityX() const { return worldValue(rigidBackend_->getGravityX()); }
322
323
324float World3D::getGravityY() const { return worldValue(rigidBackend_->getGravityY()); }
325
326
327float World3D::getGravityZ() const { return worldValue(rigidBackend_->getGravityZ()); }
328
329
330void World3D::setHitEventThreshold(float speed) { worldValue(rigidBackend_->setHitEventThreshold(speed)); }
331
332
333float World3D::getHitEventThreshold() const { return worldValue(rigidBackend_->getHitEventThreshold()); }
334
335
336void World3D::refreshContactFilter(Shape3D *shape) {
337 if (!shape || !shape->isValid()) return;
338 shape->setCategoryBits(shape->getCategoryBits());
339}
340
342 if (!bodyA || !bodyB || bodyA == bodyB || !bodyA->isValid() || !bodyB->isValid() ||
343 bodyA->getWorld() != this || bodyB->getWorld() != this)
344 throw eve::Exception(
345 "World3D.setBodyPairCollisionEnabled: distinct live bodies must belong to this world");
346 const uint64_t key = stablePairKey(bodyA->getId(), bodyB->getId());
347 for (Shape3D *shape : shapes_) {
348 if (shape && (shape->getBody() == bodyA || shape->getBody() == bodyB))
349 shape->enableContactOverrideFiltering();
350 }
351 if (enabled) disabledBodyPairs_.erase(key); else disabledBodyPairs_.insert(key);
352 for (Shape3D *shape : shapes_) {
353 if (shape && (shape->getBody() == bodyA || shape->getBody() == bodyB))
354 refreshContactFilter(shape);
355 }
356}
357
359 if (!bodyA || !bodyB || bodyA == bodyB || !bodyA->isValid() || !bodyB->isValid() ||
360 bodyA->getWorld() != this || bodyB->getWorld() != this)
361 throw eve::Exception(
362 "World3D.isBodyPairCollisionEnabled: distinct live bodies must belong to this world");
363 return disabledBodyPairs_.count(stablePairKey(bodyA->getId(), bodyB->getId())) == 0;
364}
365
367 if (!shapeA || !shapeB || shapeA == shapeB || !shapeA->isValid() || !shapeB->isValid() ||
368 !shapeA->getBody() || !shapeB->getBody() ||
369 shapeA->getBody()->getWorld() != this || shapeB->getBody()->getWorld() != this)
370 throw eve::Exception(
371 "World3D.setShapePairCollisionEnabled: distinct live shapes must belong to this world");
372 const uint64_t key = stablePairKey(shapeA->getId(), shapeB->getId());
373 shapeA->enableContactOverrideFiltering();
374 shapeB->enableContactOverrideFiltering();
375 if (enabled) disabledShapePairs_.erase(key); else disabledShapePairs_.insert(key);
376 refreshContactFilter(shapeA);
377 refreshContactFilter(shapeB);
378}
379
381 if (!shapeA || !shapeB || shapeA == shapeB || !shapeA->isValid() || !shapeB->isValid() ||
382 !shapeA->getBody() || !shapeB->getBody() ||
383 shapeA->getBody()->getWorld() != this || shapeB->getBody()->getWorld() != this)
384 throw eve::Exception(
385 "World3D.isShapePairCollisionEnabled: distinct live shapes must belong to this world");
386 return disabledShapePairs_.count(stablePairKey(shapeA->getId(), shapeB->getId())) == 0;
387}
388
389
390void World3D::removeCollisionOverridesForBody(int bodyId) {
391 for (auto it = disabledBodyPairs_.begin(); it != disabledBodyPairs_.end();) {
392 if (pairContains(*it, bodyId)) it = disabledBodyPairs_.erase(it); else ++it;
393 }
394}
395
396void World3D::removeCollisionOverridesForShape(int shapeId) {
397 for (auto it = disabledShapePairs_.begin(); it != disabledShapePairs_.end();) {
398 if (pairContains(*it, shapeId)) it = disabledShapePairs_.erase(it); else ++it;
399 }
400}
401
402int World3D::nextBodyId() { return nextId_++; }
403
405 if (nextBodyHandleIndex_ == PhysicsBodyHandle::invalidIndex)
406 throw eve::Exception("World3D.newBody: process-local body handle space exhausted");
407 return PhysicsBodyHandle(nextBodyHandleIndex_++, 1u);
408}
409
411 if (nextShapeHandleIndex_ == PhysicsShapeHandle::invalidIndex)
412 throw eve::Exception("Body3D.newShape: process-local shape handle space exhausted");
413 return PhysicsShapeHandle(nextShapeHandleIndex_++, 1u);
414}
415
417 if (nextJointHandleIndex_ == PhysicsJointHandle::invalidIndex)
418 throw eve::Exception("World3D.newJoint: process-local joint handle space exhausted");
419 return PhysicsJointHandle(nextJointHandleIndex_++, 1u);
420}
421
422Body3D *World3D::newBody(const std::string &bodyType, float x, float y, float z) {
423 if (!isValid()) throw eve::Exception("World3D.newBody: world destroyed");
424 const auto handle = nextBodyRuntimeHandle();
425 auto native = worldValue(rigidBackend_->createBody(bodyType, x, y, z));
426 auto body = std::make_unique<Body3D>(this, std::move(native), nextBodyId(), handle);
427 bodies_.insert(body.get());
428 return body.release();
429}
430
432 if (!isValid() || handle.isInvalid()) return nullptr;
433 for (Body3D *body : bodies_) {
434 if (body && body->isValid() && body->runtimeHandle() == handle) return body;
435 }
436 return nullptr;
437}
438
439Body3D *World3D::findBodyById(int bodyId) const {
440 if (!isValid() || bodyId < 0) return nullptr;
441 for (Body3D *body : bodies_) {
442 if (body && body->isValid() && body->getId() == bodyId) return body;
443 }
444 return nullptr;
445}
446
448 if (!isValid() || handle.isInvalid()) return nullptr;
449 const auto found = shapeHandles_.find(handle);
450 if (found == shapeHandles_.end() || !found->second || !found->second->isValid()) return nullptr;
451 return found->second;
452}
453
455 if (!isValid() || shapeId < 0) return nullptr;
456 for (Shape3D *shape : shapes_) {
457 if (shape && shape->isValid() && shape->getId() == shapeId) return shape;
458 }
459 return nullptr;
460}
461
463 if (!isValid() || handle.isInvalid()) return nullptr;
464 const auto found = jointHandles_.find(handle);
465 if (found == jointHandles_.end() || !found->second || !found->second->isValid()) return nullptr;
466 return found->second;
467}
468
469
470void World3D::setQueryFilter(int categoryBits, int maskBits) {
471 queryCategoryBits_ = static_cast<uint32_t>(categoryBits);
472 queryMaskBits_ = static_cast<uint32_t>(maskBits);
473}
474
476 queryCategoryBits_ = 0xFFFFFFFFu;
477 queryMaskBits_ = 0xFFFFFFFFu;
478}
479
481 if (bodyId == 0 || bodyId < -1)
482 throw eve::Exception("World3D.setQueryIgnoredBodyId: use a positive stable id or -1");
483 queryIgnoredBodyId_ = bodyId;
484}
485
487 if (shapeId == 0 || shapeId < -1)
488 throw eve::Exception("World3D.setQueryIgnoredShapeId: use a positive stable id or -1");
489 queryIgnoredShapeId_ = shapeId;
490}
491
493 queryIgnoredBodyId_ = -1;
494 queryIgnoredShapeId_ = -1;
495}
496
498 if (!body) return;
499 body->destroy();
500}
501
503 if (body) releaseCouplingsForBody(body->runtimeHandle());
504 if (body) removeCollisionOverridesForBody(body->getId());
505 bodies_.erase(body);
506}
508 if (!shape) return;
509 removeCollisionOverridesForShape(shape->getId());
510 shapes_.erase(shape);
511 const PhysicsShapeHandle handle = shape->runtimeHandle();
512 if (handle.isValid()) shapeHandles_.erase(handle);
513 for (auto it = shapeHandles_.begin(); it != shapeHandles_.end();) {
514 if (it->second == shape)
515 it = shapeHandles_.erase(it);
516 else
517 ++it;
518 }
519 for (auto it = shapeRawHandles_.begin(); it != shapeRawHandles_.end();) {
520 if (it->second == handle)
521 it = shapeRawHandles_.erase(it);
522 else
523 ++it;
524 }
525}
526
528 if (!shape || !shape->getBody() || !shape->isValid() || shape->runtimeHandle().isInvalid()) return;
529 const PhysicsShapeHandle handle = shape->runtimeHandle();
530 for (auto it = shapeHandles_.begin(); it != shapeHandles_.end();) {
531 if (it->second == shape || it->first == handle)
532 it = shapeHandles_.erase(it);
533 else
534 ++it;
535 }
536 for (auto it = shapeRawHandles_.begin(); it != shapeRawHandles_.end();) {
537 if (it->second == handle)
538 it = shapeRawHandles_.erase(it);
539 else
540 ++it;
541 }
542 indexShapeHandle(shape);
543}
544
545void World3D::indexShapeHandle(Shape3D *shape) {
546 const auto handle = shape->runtimeHandle();
547 const uint64_t rawKey = rigidBackend_->shapeKey(*shape);
548 shapeHandles_[handle] = shape;
549 shapeRawHandles_[rawKey] = handle;
550 shapeRecords_[rawKey] = EventShape{shape->getBody()->getId(), shape->getId(), shape->getTag()};
551}
552
553
555 if (!shape) return;
556 for (auto &[key, record] : shapeRecords_) {
557 (void)key;
558 if (record.shapeId == shape->getId()) record.shapeTag = shape->getTag();
559 }
560}
561
563 if (!isValid()) return;
564 const auto beginStart = beginContacts_.size(), endStart = endContacts_.size();
565 const auto triggerBeginStart = beginTriggers_.size(), triggerEndStart = endTriggers_.size();
566 const auto hitStart = hits_.size(), stressStart = jointStressEvents_.size();
567 worldValue(rigidBackend_->collectEvents());
568
569 auto *ev = eve::ModuleManager::getInstance<eve::platform_event::PlatformEvent>("PlatformEvent");
570 if (!ev) return;
571 const auto publishPair = [&](const char *name, const EventShape &a, const EventShape &b) {
572 std::vector<eve::platform_event::Variant> args = {
576 ev->push(new eve::platform_event::Message(name, args));
577 };
578 for (auto i = beginStart; i < beginContacts_.size(); ++i)
579 publishPair("begincontact3d", beginContacts_[i].shapeA, beginContacts_[i].shapeB);
580 for (auto i = endStart; i < endContacts_.size(); ++i)
581 publishPair("endcontact3d", endContacts_[i].shapeA, endContacts_[i].shapeB);
582 for (auto i = hitStart; i < hits_.size(); ++i) publishPair("hit3d", hits_[i].shapeA, hits_[i].shapeB);
583 for (auto i = triggerBeginStart; i < beginTriggers_.size(); ++i)
584 publishPair("begintrigger3d", beginTriggers_[i].sensor, beginTriggers_[i].visitor);
585 for (auto i = triggerEndStart; i < endTriggers_.size(); ++i)
586 publishPair("endtrigger3d", endTriggers_[i].sensor, endTriggers_[i].visitor);
587 for (auto i = stressStart; i < jointStressEvents_.size(); ++i) {
588 const auto &joint = jointStressEvents_[i];
589 std::vector<eve::platform_event::Variant> args = {
592 ev->push(new eve::platform_event::Message("jointstress3d", args));
593 }
594}
595
596} // namespace eve::physics
double z
double y
double x
ActionParameterOperation operation
std::string selected
const std::string & s
std::mutex mutex
SQObjectPtr key
Definition ECS.cpp:155
ScriptComponentRecord record
Definition ECS.cpp:228
std::string name
Definition ECS.cpp:154
int instanceId
ShaderImageInput shape
wgpu::PopErrorScopeStatus status
float dampingRatio
std::string id
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
OceanRenderBackend backend
std::string error
Definition Package.cpp:174
PrimitiveHandle handle
const eve::script::BindingContractRegistry & registry
std::string body
Object::Ptr value
bool found
uint32_t index
int shapeId
std::unordered_map< PhysicsWorldHandle::index_type, World3D * > worlds
Definition World3D.cpp:46
#define EV_EXPLOSION_FLOAT_GETTER(name, member)
Definition World3D.cpp:175
#define EV_EXPLOSION_INT_GETTER(name, member)
Definition World3D.cpp:169
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:571
Move-only operation result carrying either a value or Status.
Definition Result.h:176
constexpr bool isValid() const noexcept
Returns whether both coordinates are usable handle values.
constexpr index_type index() const noexcept
Returns the owner-local slot index.
static constexpr index_type invalidIndex
Reserved index value shared by all invalid handles.
static constexpr RuntimeHandle invalid() noexcept
Returns the canonical invalid handle.
Structured status and zero or more diagnostics for an operation.
Definition Status.h:70
Id128 public API.
Definition Identity.h:111
constexpr bool isNil() const noexcept
Returns whether this value is the all-zero nil ID.
Definition Identity.h:175
Backend-neutral 3D rigid body in meter-space coordinates (+Y up by convention). Owned by a World3D; c...
Definition Body3D.h:31
World3D * getWorld()
Returns the owning world, or null after invalidation.
Definition Body3D.h:345
bool isValid() const
True while the underlying Box3D body is still alive.
Definition Body3D.cpp:57
int getId() const
Stable id used by collision events.
Definition Body3D.h:42
Script-facing joint owned by a World3D. Legacy scalar/void methods adapt the checked backend contract...
Definition Joint3D.h:27
PhysicsJointHandle runtimeHandle() const noexcept
Process-local generation-qualified handle owned by World3D.
Definition Joint3D.h:47
Composed mechanical assembly owned by a World3D.
Definition Mechanism3D.h:25
3D shape (box/sphere/capsule) attached to a Body3D with material settings. Created via Body3D::new*Sh...
Definition Shape3D.h:34
int getId() const
Stable world-local id, preserved when sensor state recreates the backend shape.
Definition Shape3D.h:48
bool isValid() const
Native shape liveness through the selected backend.
Definition Shape3D.cpp:69
Body3D * getBody()
Returns the owning body, or null after invalidation.
Definition Shape3D.h:286
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:47
float getProfileStepMs() const
Latest complete physics step time in milliseconds.
Definition World3D.cpp:223
float getRestitutionThreshold() const
Current restitution speed threshold in m/s.
Definition World3D.cpp:128
void setGravity(float gx, float gy, float gz)
Gravity in m/s².
Definition World3D.cpp:318
int getDynamicTreeHeight() const
Dynamic broad-phase tree height.
Definition World3D.cpp:215
PhysicsJointHandle nextJointRuntimeHandle()
Internal: next generation-qualified joint handle.
Definition World3D.cpp:416
bool isWarmStartingEnabled() const
Whether constraint warm starting is enabled.
Definition World3D.cpp:153
float getMaximumLinearSpeed() const
Current world-wide maximum linear speed in m/s.
Definition World3D.cpp:147
int getAwakeBodyCount() const
Number of awake bodies.
Definition World3D.cpp:220
friend void registerCameraObstructionWorld(World3D *world)
Registers camera obstruction world.
static eve::Result< std::unique_ptr< World3D > > createWithBackend(RigidBackend3D backend, float gravityX, float gravityY, float gravityZ, bool sleep, eve::PersistentId instanceId=eve::PersistentId::nil())
Creates a world with an explicit solver; absent providers return Unsupported without fallback....
Definition World3D.cpp:55
Joint3D * findJoint(PhysicsJointHandle handle) const
Resolves a live joint handle; returns null when stale or foreign.
Definition World3D.cpp:462
int getJointCount() const
Current backend joint count.
Definition World3D.cpp:205
void updateShapeTag(Shape3D *shape)
Internal: refreshes the tag snapshot for a live shape handle.
Definition World3D.cpp:554
void registerShapeHandle(Shape3D *shape)
Internal: snapshots a backend handle for destruction-safe end events.
Definition World3D.cpp:527
Shape3D * findShapeById(int shapeId) const
Resolves a live shape by its world-local stable event/query id.
Definition World3D.cpp:454
float getBoundsMinZ() const
Minimum world-space Z covered by current broad-phase bounds.
Definition World3D.cpp:190
Shape3D * findShape(PhysicsShapeHandle handle) const
Resolves a live shape handle; returns null when stale or foreign.
Definition World3D.cpp:447
void forgetBody(Body3D *body)
Raw Box3D world id.
Definition World3D.cpp:502
float getGravityX() const
Definition World3D.cpp:321
int nextBodyId()
Internal: next stable body id.
Definition World3D.cpp:402
float getProfileBulletsMs() const
Latest continuous-collision bullet time in milliseconds.
Definition World3D.cpp:231
void setBodyPairCollisionEnabled(Body3D *bodyA, Body3D *bodyB, bool enabled)
Overrides collision for a live body pair without changing layer masks.
Definition World3D.cpp:341
void forgetJoint(Joint3D *joint)
Internal: removes a joint wrapper from ownership bookkeeping.
Definition World3D.cpp:305
World3D(float gravityX, float gravityY, float gravityZ, bool sleep, eve::PersistentId instanceId=eve::PersistentId::nil())
Creates a 3D physics world.
Definition World3D.cpp:78
float getProfileCollideMs() const
Latest narrow-phase collision time in milliseconds.
Definition World3D.cpp:227
void setContactTuning(float hertz, float dampingRatio, float pushOutSpeed)
Configures contact overlap recovery.
Definition World3D.cpp:131
bool isBodyPairCollisionEnabled(Body3D *bodyA, Body3D *bodyB) const
Whether a body pair is permitted by the runtime contact override.
Definition World3D.cpp:358
void setQueryIgnoredBodyId(int bodyId)
Ignores one stable Body3D ID in subsequent spatial queries; -1 disables.
Definition World3D.cpp:480
Body3D * findBody(PhysicsBodyHandle handle) const
Borrows a live body; null for stale/foreign handles. Never delete lookup results.
Definition World3D.cpp:431
bool isContinuousCollisionEnabled() const
Whether world-level continuous collision is enabled.
Definition World3D.cpp:122
void setWarmStartingEnabled(bool enabled)
Enables constraint warm starting for stable stacks and joints.
Definition World3D.cpp:150
float getGravityY() const
Definition World3D.cpp:324
PhysicsBodyHandle nextBodyRuntimeHandle()
Internal: next generation-qualified body handle.
Definition World3D.cpp:404
bool isShapePairCollisionEnabled(Shape3D *shapeA, Shape3D *shapeB) const
Whether a shape pair is permitted by the runtime contact override.
Definition World3D.cpp:380
int explode(float x, float y, float z, float radius, float falloff, float impulsePerArea, int maskBits=-1)
Applies a geometry-aware radial impulse to dynamic convex shapes.
Definition World3D.cpp:156
void setQueryFilter(int categoryBits, int maskBits)
Set category/mask bits for subsequent ray, overlap, cast and mover queries.
Definition World3D.cpp:470
float getBoundsMaxZ() const
Maximum world-space Z covered by current broad-phase bounds.
Definition World3D.cpp:196
int getIslandCount() const
Current solver-island count.
Definition World3D.cpp:207
void setHitEventThreshold(float speed)
Minimum approach speed in m/s required for enabled Shape3D hit events.
Definition World3D.cpp:330
int getStaticTreeHeight() const
Static broad-phase tree height.
Definition World3D.cpp:213
int getMemoryByteCount() const
Approximate Box3D world allocation in bytes.
Definition World3D.cpp:217
void setMaximumLinearSpeed(float speed)
Sets the finite positive world-wide linear velocity clamp in m/s.
Definition World3D.cpp:144
bool isValid() const
True while the underlying Box3D world is alive.
Definition World3D.cpp:239
float getBoundsMinY() const
Minimum world-space Y covered by current broad-phase bounds.
Definition World3D.cpp:188
static World3D * findWorld(PhysicsWorldHandle handle) noexcept
Resolve a live process-local world handle, or null after teardown. @thread Owning physics thread only...
Definition World3D.cpp:296
float getProfileSensorsMs() const
Latest sensor processing time in milliseconds.
Definition World3D.cpp:233
int getBodyCount() const
Current backend body count.
Definition World3D.cpp:199
float getBoundsMinX() const
Minimum world-space X covered by current broad-phase bounds.
Definition World3D.cpp:186
int getAwakeContactCount() const
Contacts processed by the latest collide pass.
Definition World3D.cpp:209
void setRestitutionThreshold(float speed)
Minimum impact speed that permits material restitution, in m/s.
Definition World3D.cpp:125
float getContactRecycleDistance() const
Current contact-point persistence distance in meters.
Definition World3D.cpp:141
void destroyBody(Body3D *body)
Destroys a body (null is ignored).
Definition World3D.cpp:497
void setContinuousCollisionEnabled(bool enabled)
Enables world-level continuous collision against static geometry.
Definition World3D.cpp:117
void setQueryIgnoredShapeId(int shapeId)
Ignores one stable Shape3D ID in subsequent spatial queries; -1 disables.
Definition World3D.cpp:486
void forgetShape(Shape3D *shape)
Definition World3D.cpp:507
void clearQueryIgnores()
Clears Body and Shape query exclusions without changing layer filtering.
Definition World3D.cpp:492
float getBoundsMaxX() const
Maximum world-space X covered by current broad-phase bounds.
Definition World3D.cpp:192
Body3D * findBodyById(int bodyId) const
Borrows a live body by stable event/query id; never delete lookup results.
Definition World3D.cpp:439
int getContactCount() const
Current backend contact count.
Definition World3D.cpp:203
float getGravityZ() const
Definition World3D.cpp:327
float getProfileSolveMs() const
Latest constraint solver time in milliseconds.
Definition World3D.cpp:229
void clearContactEvents()
Clears all contact and trigger buffers before the next step.
void destroy()
Destroys the world and invalidates all wrappers.
Definition World3D.cpp:241
float getProfilePairsMs() const
Latest broad-phase pair generation time in milliseconds.
Definition World3D.cpp:225
void resetQueryFilter()
Restore the query filter to accept all lower-32-bit categories.
Definition World3D.cpp:475
void setShapePairCollisionEnabled(Shape3D *shapeA, Shape3D *shapeB, bool enabled)
Overrides collision for one live shape pair.
Definition World3D.cpp:366
float getHitEventThreshold() const
Current significant-hit speed threshold in m/s.
Definition World3D.cpp:333
int getRecycledContactCount() const
Contact points recycled during the latest step.
Definition World3D.cpp:211
void emitContactEvents()
Internal: collects Box3D contact events into the event buffers.
Definition World3D.cpp:562
Body3D * newBody(const std::string &bodyType, float x, float y, float z)
Creates a body in meter-space units.
Definition World3D.cpp:422
float getBoundsMaxY() const
Maximum world-space Y covered by current broad-phase bounds.
Definition World3D.cpp:194
void setContactRecycleDistance(float distance)
Sets contact-point persistence distance in meters; zero disables recycling.
Definition World3D.cpp:136
PhysicsShapeHandle nextShapeRuntimeHandle()
Internal: next generation-qualified shape handle.
Definition World3D.cpp:410
int getShapeCount() const
Current backend shape count.
Definition World3D.cpp:201
A named event carrying an ordered list of Variant payloads. Pushed messages are heap-allocated; the q...
const BindingContract * find(std::string_view key) const noexcept
Finds a binding contract.
eve::Result< std::unique_ptr< IWorldBackend3D > > makeWorld(World3D &owner, float gx, float gy, float gz, bool sleep)
Native-world composition boundary; returns exclusive ownership or a structured failure....
PhysicsWorldHandle allocatePhysicsWorldHandle()
Allocates a process-local world handle from the physics owner.
eve::PersistentId makePhysicsWorldPersistentId(PhysicsWorldHandle runtimeHandle)
Creates a non-nil process-local generated identity for a world without an injected persistent ID.
eve::Result< std::unique_ptr< IWorldBackend3D > > makeWorld(World3D &owner, float x, float y, float z, bool sleep)
Creates the native Jolt provider; world owns it and calls it only on the simulation thread....
Definition JoltWorld.cpp:98
T worldValue(eve::Result< T > result)
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
eve::RuntimeHandle< PhysicsShapeHandleTag > PhysicsShapeHandle
Generation-qualified runtime identity for a physics shape.
eve::Result< void > registerTargetingLineOfSightWorld(World3D *world)
Registers a borrowed live World3D with the targeting LOS adapter.
RigidBackend3D
Solver identity fixed for the lifetime of one world; independent of CPU/GPU execution.
eve::RuntimeHandle< PhysicsJointHandleTag > PhysicsJointHandle
Generation-qualified runtime identity for a physics joint.
eve::RuntimeHandle< PhysicsBodyHandleTag > PhysicsBodyHandle
Generation-qualified runtime identity for a physics body.
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
bool enabled
Stable snapshot describing one side of a 3D collision event.
Definition World3D.h:50
static Variant makeInt(int64_t v)
Constructs an integer variant.