14#include <unordered_map>
15#include <unordered_set>
24struct b2ContactImpulse;
56 float relativeNormalSpeed = 0.f;
57 float normalImpulse = 0.f;
58 float tangentImpulse = 0.f;
80 World(
float gravityX,
float gravityY,
bool sleep,
float meter,
88 void update(
float dt);
90 void updateFull(
float dt,
int velocityIterations,
int positionIterations);
99 [[nodiscard(
"check the physics step outcome or explicitly ignore it")]]
120 [[nodiscard]] std::weak_ptr<const void>
lifetimeToken() const noexcept {
return lifetime_; }
129 [[nodiscard(
"inspect backend selection diagnostics")]]
138 [[nodiscard(
"check or persist the physics snapshot")]]
151 [[nodiscard(
"check the physics snapshot restore outcome")]]
155 void setGravity(
float gx,
float gy);
156 float getGravityX()
const;
157 float getGravityY()
const;
160 void setMeter(
float pixelsPerMeter);
171 Body *newBody(
const std::string &bodyType,
float x,
float y);
175 [[nodiscard]]
Body *findBodyById(
int bodyId)
const;
189 Joint2D *newDistanceJoint(
Body *bodyA,
Body *bodyB,
float anchorAX,
float anchorAY,
190 float anchorBX,
float anchorBY,
float lengthPixels,
191 bool collideConnected =
false);
202 Joint2D *newRevoluteJoint(
Body *bodyA,
Body *bodyB,
float anchorX,
float anchorY,
203 bool collideConnected =
false);
215 float axisY,
bool collideConnected =
false);
226 Joint2D *newWeldJoint(
Body *bodyA,
Body *bodyB,
float anchorX,
float anchorY,
227 bool collideConnected =
false);
239 float axisY,
bool collideConnected =
false);
250 Joint2D *newMotorJoint(
Body *bodyA,
Body *bodyB,
bool collideConnected =
false);
273 bool collideConnected =
false);
285 float engagementTorque,
bool collideConnected =
false);
296 float crankAnchorX,
float crankAnchorY,
float crankPinX,
297 float crankPinY,
float sliderPinX,
float sliderPinY,
298 float slideAxisX,
float slideAxisY,
bool collideConnected =
false);
306 bool isValid()
const {
return !destroyed_ && world_ !=
nullptr; }
312 bool pointProbe(
float x,
float y,
float radius, ClothContact *out)
const;
321 int rayCast(
float x1,
float y1,
float x2,
float y2);
335 int queryAABB(
float x,
float y,
float w,
float h);
336 int getQueryCount()
const {
return static_cast<int>(queryBodyIds_.size()); }
337 int getQueryBodyId(
int index)
const;
340 int getBeginContactBodyAId(
int index)
const;
341 int getBeginContactBodyBId(
int index)
const;
342 std::string getBeginContactFixtureATag(
int index)
const;
343 std::string getBeginContactFixtureBTag(
int index)
const;
345 int getEndContactBodyAId(
int index)
const;
346 int getEndContactBodyBId(
int index)
const;
347 std::string getEndContactFixtureATag(
int index)
const;
348 std::string getEndContactFixtureBTag(
int index)
const;
351 int getImpactBodyAId(
int index)
const;
352 int getImpactBodyBId(
int index)
const;
353 std::string getImpactFixtureATag(
int index)
const;
354 std::string getImpactFixtureBTag(
int index)
const;
355 float getImpactPointX(
int index)
const;
356 float getImpactPointY(
int index)
const;
357 float getImpactNormalX(
int index)
const;
358 float getImpactNormalY(
int index)
const;
359 float getImpactRelativeNormalSpeed(
int index)
const;
360 float getImpactNormalImpulse(
int index)
const;
361 float getImpactTangentImpulse(
int index)
const;
363 void clearContactEvents();
366 float toMeters(
float pixels)
const;
368 float toPixels(
float meters)
const;
378 b2World *
raw() {
return world_; }
387 const b2World *
raw()
const {
return world_; }
389 void onBeginContact(b2Contact *contact);
390 void onEndContact(b2Contact *contact);
391 void onPreSolve(b2Contact *contact,
const b2Manifold *oldManifold);
392 void onPostSolve(b2Contact *contact,
const b2ContactImpulse *impulse);
395 void forgetFixture(
Fixture *fixture);
397 void forgetJoint(
Joint2D *joint);
408 int nextMechanismId();
425 b2World *world_ =
nullptr;
427 std::unique_ptr<ISimulationBackend> simulation_;
429 std::shared_ptr<const void> lifetime_ = std::make_shared<int>(0);
433 int nextJointId_ = 1;
434 int nextMechanismId_ = 1;
435 std::uint32_t nextBodyHandleIndex_ = 1u;
436 std::uint32_t nextJointHandleIndex_ = 1u;
437 bool destroyed_ =
false;
440 bool backendFallback_ =
false;
442 std::unordered_set<Body *> bodies_;
443 std::unordered_set<Fixture *> fixtures_;
444 std::unordered_set<Joint2D *> joints_;
445 std::unordered_set<Mechanism2D *> mechanisms_;
446 std::unordered_map<PhysicsJointHandle, Joint2D *> jointHandles_;
448 int rayHitBodyId_ = -1;
449 float rayHitX_ = 0.f;
450 float rayHitY_ = 0.f;
451 float rayHitNormalX_ = 0.f;
452 float rayHitNormalY_ = 0.f;
453 float rayHitFraction_ = 0.f;
455 std::vector<int> queryBodyIds_;
457 struct PreSolveData {
462 float relativeNormalSpeed = 0.f;
464 std::unordered_map<b2Contact *, PreSolveData> preSolve_;
465 std::vector<ContactEvent> beginContacts_;
466 std::vector<ContactEvent> endContacts_;
467 std::vector<ImpactEvent> impacts_;
470 void refreshRuntimeHandlesAfterRestore();
471 void adoptPreparedTopology(
World &prepared);
#define EVENGINE_API_WORLD
Process-local, generation-qualified handles owned by the physics domain.
Move-only, checked operation results for the common layer.
RoadLaneDirection direction
Backend-neutral, observable fixed-step contract for physics domains.
Versioned, integrity-checked persistence envelopes.
TerrainThermalSettings settings
Move-only operation result carrying either a value or Status.
Structured status and zero or more diagnostics for an operation.
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
static constexpr Id128 nil() noexcept
Returns the all-zero nil value.
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
2D rigid body (Box2D) in pixel-space coordinates. Owned by a World; create shapes with newRectangleFi...
2D fixture: a shape attached to a Body with material + filter settings. Also carries a string tag use...
Script-facing Box2D joint owned by a World.
Kind
Supported joint geometry.
Composed 2D mechanical assembly owned by a World.
Box2D world wrapper (2D physics) with pixel-space coordinates. Handles stepping, gravity,...
int getRayHitBodyId() const
std::weak_ptr< const void > lifetimeToken() const noexcept
Weak lifetime token for guarded cross-domain world observers.
World(const World &)=delete
int getQueryCount() const
eve::PersistentId persistentId() const noexcept
Stable non-nil identity written to snapshot envelopes.
int getImpactCount() const
float getRayHitFraction() const
Fraction along the segment [0,1] of the closest hit.
float getRayHitNormalY() const
b2World * raw()
Exposes the underlying Box2D world for tightly-scoped backend integration.
bool usedBackendFallback() const noexcept
Whether optional accelerator selection fell back to CPU.
int getBeginContactCount() const
PhysicsWorldHandle runtimeHandle() const noexcept
Process-local identity used by PhysicsLink; invalid after destruction.
World & operator=(const World &)=delete
float getRayHitNormalX() const
int getEndContactCount() const
const b2World * raw() const
Exposes the underlying Box2D world for read-only backend integration.
bool isValid() const
True while the underlying Box2D world is alive.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Optional physics backend for vehicle mobility and body attach.
SimulationBackendKind
Kind of implementation that owns a simulation step.
SimulationDeterminism
Determinism guarantee made by a simulation backend.
Build metadata (engine git commit, build time, third-party version).
std::function< Result< ContentId >(std::string_view canonicalInput)> SnapshotHashProvider
Injected content-digest implementation used by snapshots.
One deterministic fixed-step emitted by SimulationClock.
Stable outer format shared by persistence and cross-process snapshots.
Observable backend progress shared by CPU and accelerator providers.
Validated solver policy for one simulation step.