载入中...
搜索中...
未找到
Box3DWorld.cpp
浏览该文件的文档.
25float combineMaterialValue(float a, uint64_t materialA, float b, uint64_t materialB, int shift, bool friction) {
56 throw eve::Exception("World3D.newBody: unknown body type '%s' (use static|kinematic|dynamic)", type.c_str());
59void stepBox3D(void *context, const eve::SimulationStep &step, const SimulationSettings &settings) noexcept {
67WorldBackend::WorldBackend(World3D &owner, float gx, float gy, float gz, bool sleep) : owner_(&owner) {
98 eve::Diagnostic::error(eve::DiagnosticCode::Unsupported, "Cannot swap topology across rigid backends"));
106uint64_t WorldBackend::shapeKey(const Shape3D &shape) const { return b3StoreShapeId(Access::shapeId(shape)); }
107eve::Result<std::unique_ptr<IBodyBackend3D>> WorldBackend::createBody(std::string_view type, float x, float y,
112 return R::failure(eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "World is no longer valid"));
121 return R::failure(eve::Diagnostic::error(eve::DiagnosticCode::Failed, "Box3D rejected body creation"));
125eve::Result<std::unique_ptr<IWorldBackend3D>> makeWorld(World3D &owner, float gx, float gy, float gz, bool sleep) {
190eve::Result<void> WorldBackend::setContactTuning(float hertz, float dampingRatio, float pushOutSpeed) {
252bool WorldBackend::do_isWarmStartingEnabled() const { return isValid() && b3World_IsWarmStartingEnabled(worldId_); }
259int WorldBackend::do_explode(float x, float y, float z, float radius, float falloff, float impulsePerArea,
266 if (!std::isfinite(impulsePerArea)) throw eve::Exception("World3D.explode: impulsePerArea must be finite");
277 if (!body || !body->isValid() || b3Body_GetType(box3d::Access::bodyId(*body)) != b3_dynamicBody) continue;
304eve::Result<int> WorldBackend::explode(float x, float y, float z, float radius, float falloff, float impulsePerArea,
307 return eve::Result<int>::success(do_explode(x, y, z, radius, falloff, impulsePerArea, maskBits));
316 return checked("physics.world3d.getBoundsMinX", [&] { return eve::Result<float>::success(do_getBoundsMinX()); });
324 return checked("physics.world3d.getBoundsMinY", [&] { return eve::Result<float>::success(do_getBoundsMinY()); });
332 return checked("physics.world3d.getBoundsMinZ", [&] { return eve::Result<float>::success(do_getBoundsMinZ()); });
340 return checked("physics.world3d.getBoundsMaxX", [&] { return eve::Result<float>::success(do_getBoundsMaxX()); });
348 return checked("physics.world3d.getBoundsMaxY", [&] { return eve::Result<float>::success(do_getBoundsMaxY()); });
356 return checked("physics.world3d.getBoundsMaxZ", [&] { return eve::Result<float>::success(do_getBoundsMaxZ()); });
359int WorldBackend::do_getBodyCount() const { return isValid() ? b3World_GetCounters(worldId_).bodyCount : 0; }
362 return checked("physics.world3d.getBodyCount", [&] { return eve::Result<int>::success(do_getBodyCount()); });
365int WorldBackend::do_getShapeCount() const { return isValid() ? b3World_GetCounters(worldId_).shapeCount : 0; }
368 return checked("physics.world3d.getShapeCount", [&] { return eve::Result<int>::success(do_getShapeCount()); });
371int WorldBackend::do_getContactCount() const { return isValid() ? b3World_GetCounters(worldId_).contactCount : 0; }
374 return checked("physics.world3d.getContactCount", [&] { return eve::Result<int>::success(do_getContactCount()); });
377int WorldBackend::do_getJointCount() const { return isValid() ? b3World_GetCounters(worldId_).jointCount : 0; }
380 return checked("physics.world3d.getJointCount", [&] { return eve::Result<int>::success(do_getJointCount()); });
383int WorldBackend::do_getIslandCount() const { return isValid() ? b3World_GetCounters(worldId_).islandCount : 0; }
386 return checked("physics.world3d.getIslandCount", [&] { return eve::Result<int>::success(do_getIslandCount()); });
416int WorldBackend::do_getDynamicTreeHeight() const { return isValid() ? b3World_GetCounters(worldId_).treeHeight : 0; }
423int WorldBackend::do_getMemoryByteCount() const { return isValid() ? b3World_GetCounters(worldId_).byteCount : 0; }
430int WorldBackend::do_getAwakeBodyCount() const { return isValid() ? b3World_GetAwakeBodyCount(worldId_) : 0; }
437float WorldBackend::do_getProfileStepMs() const { return isValid() ? b3World_GetProfile(worldId_).step : 0; }
444float WorldBackend::do_getProfilePairsMs() const { return isValid() ? b3World_GetProfile(worldId_).pairs : 0; }
451float WorldBackend::do_getProfileCollideMs() const { return isValid() ? b3World_GetProfile(worldId_).collide : 0; }
458float WorldBackend::do_getProfileSolveMs() const { return isValid() ? b3World_GetProfile(worldId_).solve : 0; }
465float WorldBackend::do_getProfileBulletsMs() const { return isValid() ? b3World_GetProfile(worldId_).bullets : 0; }
472float WorldBackend::do_getProfileSensorsMs() const { return isValid() ? b3World_GetProfile(worldId_).sensors : 0; }
497 return checked("physics.world3d.getGravityX", [&] { return eve::Result<float>::success(do_getGravityX()); });
506 return checked("physics.world3d.getGravityY", [&] { return eve::Result<float>::success(do_getGravityY()); });
515 return checked("physics.world3d.getGravityZ", [&] { return eve::Result<float>::success(do_getGravityZ()); });
531float WorldBackend::do_getHitEventThreshold() const { return isValid() ? b3World_GetHitEventThreshold(worldId_) : 0.f; }
538bool WorldBackend::do_customFilterCallback(b3ShapeId shapeIdA, b3ShapeId shapeIdB, void *context) {
545 if (world->owner_->disabledBodyPairs_.count(stablePairKey(bodyA->getId(), bodyB->getId())) != 0) return false;
546 return world->owner_->disabledShapePairs_.count(stablePairKey(shapeA->getId(), shapeB->getId())) == 0;
560 return body->getId() == owner_->queryIgnoredBodyId_ || shape->getId() == owner_->queryIgnoredShapeId_;
563bool WorldBackend::do_preSolveCallback(b3ShapeId shapeIdA, b3ShapeId shapeIdB, b3Pos point, b3Vec3 normal,
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Backend-neutral 3D rigid body in meter-space coordinates (+Y up by convention). Owned by a World3D; c...
Definition Body3D.h:31
Complete rigid-world execution boundary, bound once to an owning World3D facade. @ownership Owns exac...
Definition WorldBackend3D.h:24
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
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:47
eve::Result< int > getBodyCount() const override
getBodyCount; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:361
eve::Result< void > setGravity(float gx, float gy, float gz) override
setGravity; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:484
eve::Result< float > getBoundsMaxZ() const override
getBoundsMaxZ; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:355
eve::Result< void > setMaximumLinearSpeed(float speed) override
setMaximumLinearSpeed; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:225
eve::Result< void > setContinuousCollisionEnabled(bool enabled) override
setContinuousCollisionEnabled; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:139
eve::Result< int > getStaticTreeHeight() const override
getStaticTreeHeight; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:411
eve::Result< float > getGravityY() const override
getGravityY; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:505
eve::Result< float > getProfilePairsMs() const override
getProfilePairsMs; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:446
eve::Result< float > getGravityX() const override
getGravityX; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:496
WorldBackend(World3D &owner, float gx, float gy, float gz, bool sleep)
Definition Box3DWorld.cpp:67
eve::Result< void > setWarmStartingEnabled(bool enabled) override
setWarmStartingEnabled; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:245
eve::Result< int > getAwakeContactCount() const override
getAwakeContactCount; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:393
eve::Result< float > getBoundsMinY() const override
getBoundsMinY; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:323
eve::Result< float > getHitEventThreshold() const override
getHitEventThreshold; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:533
eve::Result< float > getProfileSolveMs() const override
getProfileSolveMs; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:460
eve::Result< float > getBoundsMaxX() const override
getBoundsMaxX; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:339
eve::Result< float > getGravityZ() const override
getGravityZ; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:514
eve::Result< float > getMaximumLinearSpeed() const override
getMaximumLinearSpeed; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:236
eve::Result< float > getProfileBulletsMs() const override
getProfileBulletsMs; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:467
eve::Result< int > getContactCount() const override
getContactCount; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:373
eve::Result< float > getProfileStepMs() const override
getProfileStepMs; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:439
eve::Result< int > getRecycledContactCount() const override
getRecycledContactCount; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:402
eve::Result< void > setContactRecycleDistance(float distance) override
setContactRecycleDistance; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:203
eve::Result< float > getBoundsMinZ() const override
getBoundsMinZ; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:331
eve::Result< std::unique_ptr< IBodyBackend3D > > createBody(std::string_view type, float x, float y, float z) override
Creates an owning body backend without publishing an engine wrapper. @cost One native body allocation...
Definition Box3DWorld.cpp:107
eve::Result< void > setContactTuning(float hertz, float dampingRatio, float pushOutSpeed) override
setContactTuning; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:190
~WorldBackend() override
Definition Box3DWorld.cpp:81
void destroy() noexcept override
Idempotent native teardown after all facades have been invalidated.
Definition Box3DWorld.cpp:83
eve::Result< void > setHitEventThreshold(float speed) override
setHitEventThreshold; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:524
eve::Result< bool > isContinuousCollisionEnabled() const override
isContinuousCollisionEnabled; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:150
eve::Result< int > getDynamicTreeHeight() const override
getDynamicTreeHeight; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:418
eve::Result< float > getBoundsMinX() const override
getBoundsMinX; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:315
eve::Result< int > getShapeCount() const override
getShapeCount; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:367
eve::Result< float > getRestitutionThreshold() const override
getRestitutionThreshold; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:172
eve::Result< int > getJointCount() const override
getJointCount; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:379
eve::Result< int > explode(float x, float y, float z, float radius, float falloff, float impulsePerArea, int maskBits) override
explode; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:304
eve::Result< int > getIslandCount() const override
getIslandCount; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:385
eve::Result< float > getProfileCollideMs() const override
getProfileCollideMs; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:453
eve::Result< float > getContactRecycleDistance() const override
getContactRecycleDistance; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:214
eve::Result< int > getAwakeBodyCount() const override
getAwakeBodyCount; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:432
eve::Result< float > getProfileSensorsMs() const override
getProfileSensorsMs; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:474
eve::Result< bool > isWarmStartingEnabled() const override
isWarmStartingEnabled; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:254
eve::Result< void > setRestitutionThreshold(float speed) override
setRestitutionThreshold; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:161
eve::Result< void > swapTopology(IWorldBackend3D &prepared) override
Swaps prepared native topology while retaining stable step-driver contexts.
Definition Box3DWorld.cpp:94
eve::Result< SimulationBackendSelection > selectSimulation() override
Builds the separate CPU/accelerator step driver; driver borrows this world's stable state.
Definition Box3DWorld.cpp:87
uint64_t shapeKey(const Shape3D &shape) const override
Opaque native lookup key scoped to this world, used only by internal event history.
Definition Box3DWorld.cpp:106
eve::Result< int > getMemoryByteCount() const override
getMemoryByteCount; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:425
eve::Result< float > getBoundsMaxY() const override
getBoundsMaxY; uses the class ownership, thread and failure contract.
Definition Box3DWorld.cpp:347
Definition Body3D.h:17
std::unique_ptr< IBodyBackend3D > adoptBody(b3BodyId id)
Internal native ABI adoption boundary; transfers sole body ownership, simulation thread only.
Definition Box3DBody.cpp:648
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....
Definition Box3DWorld.cpp:125
Body3D * bodyFromShape(b3ShapeId shapeId)
Resolves a native Box3D user-data observer for an immediate internal call.
Definition Box3DWorldInternal.h:12
Shape3D * shapeFromShape(b3ShapeId shapeId)
Resolves a native Box3D user-data observer for an immediate internal call.
Definition Box3DWorldInternal.h:24
@ ToleranceBounded
Results are equivalent within a documented numeric tolerance.
@ InvalidArgument
@ Unsupported
@ Failed
@ StaleHandle
Definition Container.h:602
static b3BodyId bodyId(const Body3D &body)
Borrows the native identifier synchronously; facade must belong to a Box3D world.
Definition Box3DBody.cpp:649
static b3WorldId worldId(const World3D &world)
Internal checked Box3D world ID; fails for another backend.
Definition Box3DWorld.cpp:13
static b3ShapeId shapeId(const Shape3D &shape)
Borrows a Box3D shape identifier for a synchronous native operation.
Definition Box3DShape.cpp:328