载入中...
搜索中...
未找到
World3D.cpp
浏览该文件的文档.
55eve::Result<std::unique_ptr<World3D>> World3D::createWithBackend(RigidBackend3D backend, float gravityX, float gravityY,
71 std::unique_ptr<World3D>(new World3D(gravityX, gravityY, gravityZ, sleep, instanceId, true, backend)));
78World3D::World3D(float gravityX, float gravityY, float gravityZ, bool sleep, eve::PersistentId instanceId)
81World3D::World3D(float gravityX, float gravityY, float gravityZ, bool sleep, eve::PersistentId instanceId,
95 throw eve::Exception("World3D: cannot select a simulation backend: %s", status.describe().c_str());
122bool World3D::isContinuousCollisionEnabled() const { return worldValue(rigidBackend_->isContinuousCollisionEnabled()); }
125void World3D::setRestitutionThreshold(float speed) { worldValue(rigidBackend_->setRestitutionThreshold(speed)); }
128float World3D::getRestitutionThreshold() const { return worldValue(rigidBackend_->getRestitutionThreshold()); }
141float World3D::getContactRecycleDistance() const { return worldValue(rigidBackend_->getContactRecycleDistance()); }
144void World3D::setMaximumLinearSpeed(float speed) { worldValue(rigidBackend_->setMaximumLinearSpeed(speed)); }
147float World3D::getMaximumLinearSpeed() const { return worldValue(rigidBackend_->getMaximumLinearSpeed()); }
150void World3D::setWarmStartingEnabled(bool enabled) { worldValue(rigidBackend_->setWarmStartingEnabled(enabled)); }
153bool World3D::isWarmStartingEnabled() const { return worldValue(rigidBackend_->isWarmStartingEnabled()); }
209int World3D::getAwakeContactCount() const { return worldValue(rigidBackend_->getAwakeContactCount()); }
211int World3D::getRecycledContactCount() const { return worldValue(rigidBackend_->getRecycledContactCount()); }
213int World3D::getStaticTreeHeight() const { return worldValue(rigidBackend_->getStaticTreeHeight()); }
215int World3D::getDynamicTreeHeight() const { return worldValue(rigidBackend_->getDynamicTreeHeight()); }
217int World3D::getMemoryByteCount() const { return worldValue(rigidBackend_->getMemoryByteCount()); }
220int World3D::getAwakeBodyCount() const { return worldValue(rigidBackend_->getAwakeBodyCount()); }
223float World3D::getProfileStepMs() const { return worldValue(rigidBackend_->getProfileStepMs()); }
225float World3D::getProfilePairsMs() const { return worldValue(rigidBackend_->getProfilePairsMs()); }
227float World3D::getProfileCollideMs() const { return worldValue(rigidBackend_->getProfileCollideMs()); }
229float World3D::getProfileSolveMs() const { return worldValue(rigidBackend_->getProfileSolveMs()); }
231float World3D::getProfileBulletsMs() const { return worldValue(rigidBackend_->getProfileBulletsMs()); }
233float World3D::getProfileSensorsMs() const { return worldValue(rigidBackend_->getProfileSensorsMs()); }
239bool World3D::isValid() const { return !destroyed_ && rigidBackend_ && rigidBackend_->isValid(); }
318void World3D::setGravity(float gx, float gy, float gz) { worldValue(rigidBackend_->setGravity(gx, gy, gz)); }
330void World3D::setHitEventThreshold(float speed) { worldValue(rigidBackend_->setHitEventThreshold(speed)); }
333float World3D::getHitEventThreshold() const { return worldValue(rigidBackend_->getHitEventThreshold()); }
569 auto *ev = eve::ModuleManager::getInstance<eve::platform_event::PlatformEvent>("PlatformEvent");
573 eve::platform_event::Variant::makeInt(a.bodyId), eve::platform_event::Variant::makeInt(b.bodyId),
574 eve::platform_event::Variant::makeInt(a.shapeId), eve::platform_event::Variant::makeInt(b.shapeId),
575 eve::platform_event::Variant::makeInt(a.shapeTag), eve::platform_event::Variant::makeInt(b.shapeTag)};
582 for (auto i = hitStart; i < hits_.size(); ++i) publishPair("hit3d", hits_[i].shapeA, hits_[i].shapeB);
590 eve::platform_event::Variant::makeInt(joint.jointId), eve::platform_event::Variant::makeInt(joint.bodyAId),
591 eve::platform_event::Variant::makeInt(joint.bodyBId), eve::platform_event::Variant::makeInt(joint.kind)};
const eve::script::BindingContractRegistry & registry
Definition ProjectIndexAutomatic.cpp:24
std::unordered_map< PhysicsWorldHandle::index_type, World3D * > worlds
Definition World3D.cpp:46
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:571
constexpr bool isValid() const noexcept
Returns whether both coordinates are usable handle values.
Definition RuntimeHandle.h:146
constexpr index_type index() const noexcept
Returns the owner-local slot index.
Definition RuntimeHandle.h:152
static constexpr index_type invalidIndex
Reserved index value shared by all invalid handles.
Definition RuntimeHandle.h:124
static constexpr RuntimeHandle invalid() noexcept
Returns the canonical invalid handle.
Definition RuntimeHandle.h:143
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
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
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
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
friend void registerCameraObstructionWorld(World3D *world)
Registers camera obstruction world.
Definition PhysicsWorldQueries.cpp:97
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
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
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
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
void setHitEventThreshold(float speed)
Minimum approach speed in m/s required for enabled Shape3D hit events.
Definition World3D.cpp:330
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
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
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 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 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
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.
Definition World3DContacts.cpp:14
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
A named event carrying an ordered list of Variant payloads. Pushed messages are heap-allocated; the q...
Definition PlatformEvent.h:77
const BindingContract * find(std::string_view key) const noexcept
Finds a binding contract.
Definition ScriptCompiler.cpp:423
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
PhysicsWorldHandle allocatePhysicsWorldHandle()
Allocates a process-local world handle from the physics owner.
Definition PhysicsHandles.cpp:10
eve::PersistentId makePhysicsWorldPersistentId(PhysicsWorldHandle runtimeHandle)
Creates a non-nil process-local generated identity for a world without an injected persistent ID.
Definition PhysicsHandles.cpp:26
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)
Definition World3DInternal.h:45
eve::RuntimeHandle< PhysicsShapeHandleTag > PhysicsShapeHandle
Generation-qualified runtime identity for a physics shape.
Definition PhysicsHandles.h:30
eve::Result< void > registerTargetingLineOfSightWorld(World3D *world)
Registers a borrowed live World3D with the targeting LOS adapter.
Definition PhysicsWorldQueries.cpp:100
RigidBackend3D
Solver identity fixed for the lifetime of one world; independent of CPU/GPU execution.
Definition WorldBackend3D.h:11
eve::RuntimeHandle< PhysicsJointHandleTag > PhysicsJointHandle
Generation-qualified runtime identity for a physics joint.
Definition PhysicsHandles.h:32
eve::RuntimeHandle< PhysicsBodyHandleTag > PhysicsBodyHandle
Generation-qualified runtime identity for a physics body.
Definition PhysicsHandles.h:28
@ InvalidArgument
@ Unsupported
@ Failed
Stable snapshot describing one side of a 3D collision event.
Definition World3D.h:50