Define Ymir as the Box3D service boundary
This commit is contained in:
parent
0ffad2a4f0
commit
30a391ba31
4 changed files with 214 additions and 125 deletions
22
AGENTS.md
22
AGENTS.md
|
|
@ -1,7 +1,9 @@
|
|||
# Ymir Agent Instructions
|
||||
|
||||
Ymir owns physics truth. Treat Unity, renderers, editor tools, and dashboards as
|
||||
clients or adapters unless a document explicitly transfers authority.
|
||||
Ymir owns authoritative physics sessions and their GameCult contracts. Box3D
|
||||
owns the physics algorithms inside those sessions. Treat Unity, products,
|
||||
renderers, editor tools, and dashboards as clients or adapters unless a
|
||||
document explicitly transfers authority.
|
||||
|
||||
Before substantial implementation, state:
|
||||
|
||||
|
|
@ -15,10 +17,18 @@ Before substantial implementation, state:
|
|||
|
||||
Architecture constraints:
|
||||
|
||||
- Build physics primitives in `Ymir.Core` first. Daemon, Unity, and future Rust
|
||||
or CultMesh surfaces are presentation/transport clients.
|
||||
- Use CultMath for numeric work. Do not copy Unity.Mathematics helpers into
|
||||
Ymir.
|
||||
- Do not reimplement Box3D integration, collision geometry, broadphase,
|
||||
queries, solver behavior, contact lifecycle, or numeric tolerances.
|
||||
Physics edge cases follow the pinned Box3D release and executable parity
|
||||
tests.
|
||||
- `Ymir.Core` owns typed contracts, stable-id projection, session commands,
|
||||
deterministic ordering, persistence reconstruction, and publication. The
|
||||
native Ymir wrapper owns Box3D ABI isolation. Daemon, Unity, and future Rust
|
||||
or CultMesh surfaces consume those boundaries without importing Box3D
|
||||
internals.
|
||||
- Use CultMath for GameCult-side numeric projections and force preparation. It
|
||||
must not become a second integration or collision engine. Do not copy
|
||||
Unity.Mathematics helpers into Ymir.
|
||||
- JSON is allowed at HTTP/CLI compatibility boundaries. It is not durable truth.
|
||||
Durable state should move toward CultCache `.cc` documents and CultMesh
|
||||
publication.
|
||||
|
|
|
|||
114
README.md
114
README.md
|
|
@ -1,75 +1,79 @@
|
|||
# Ymir
|
||||
|
||||
Ymir is the GameCult physics/world substrate engine for Aetheria and future
|
||||
world-bearing projects.
|
||||
Ymir is the GameCult Box3D wrapper and authoritative physics daemon for
|
||||
Aetheria and future world-bearing projects. The name means **Not Invented
|
||||
Here**. We are taking the hint.
|
||||
|
||||
Unity made the first playable body move. It does not get to keep physics truth.
|
||||
Ymir owns simulation state: bodies, fields, projectiles, collision, contact
|
||||
events, integration, and deterministic queries. Renderers and engines lower
|
||||
Ymir state into visible worlds; they do not become the world.
|
||||
Box3D owns physics algorithms. Ymir owns the service boundary that makes those
|
||||
algorithms usable as durable, typed GameCult world truth. Unity, renderers, and
|
||||
game products consume Ymir state and contact facts; they do not become physics
|
||||
authorities.
|
||||
|
||||
## Authority
|
||||
## Ownership
|
||||
|
||||
- Ymir owns physics simulation truth, step semantics, contact generation,
|
||||
collision queries, and physics debug/operator state.
|
||||
- CultMath owns the numeric substrate Ymir uses for vector math and shared
|
||||
shader-shaped primitives.
|
||||
- Aetheria owns gameplay policy: damage, faction meaning, weapon selection,
|
||||
ship fitting, and player-visible consequence.
|
||||
- Unity owns rendering, authoring affordances, GameObject presentation, VFX,
|
||||
audio, and temporary adapter code during cutover.
|
||||
- Brokkr may expose Unity editor state to the Verse, but it does not own Ymir
|
||||
simulation truth.
|
||||
- Odin discovers Ymir as a Verse provider; Odin does not own Ymir state.
|
||||
- CultCache is the target durable state substrate. Current JSON surfaces are
|
||||
compatibility witnesses for Aetheria cutover and HTTP inspection.
|
||||
- Box3D owns rigid-body integration, collision geometry, broadphase, solver
|
||||
behavior, continuous collision, overlap and cast semantics, contact
|
||||
lifecycle, force and torque lifetime, tolerances, and deterministic step
|
||||
behavior for identical recorded inputs.
|
||||
- Ymir owns the pinned Box3D version, stable GameCult entity ids, native ABI
|
||||
isolation, long-lived world sessions, typed commands and facts,
|
||||
deterministic result ordering, checkpoint reconstruction, CultCache state,
|
||||
CultMesh publication, and daemon lifecycle.
|
||||
- Aetheria owns gameplay policy and supplies typed physical intent: bodies,
|
||||
fields, tractor targets, forces, projectiles, filters, and the gameplay
|
||||
consequences of Ymir contact facts.
|
||||
- CultMath remains available for GameCult-side numeric projections and force
|
||||
preparation. It is not a second collision or integration engine.
|
||||
- Unity and Eve lowerers render world state and submit commands. They never
|
||||
repair, override, or independently simulate authoritative physics.
|
||||
|
||||
## First Body
|
||||
Box3D opaque handles are process-local derived state. They are never durable
|
||||
entity ids and never cross the public contract boundary.
|
||||
|
||||
`Ymir.Core` targets `net8.0` to stay compatible with CultMath and likely
|
||||
Aetheria integration paths. The daemon and tests target `net10.0` because this
|
||||
machine currently has the .NET 10 runtime installed.
|
||||
## Current Cutover State
|
||||
|
||||
The MVP is deliberately small:
|
||||
Box3D v0.1.0 is pinned at commit
|
||||
`8441b4a06d6d09dcfb0b0f704df4d847d1437b92`. A Ymir-owned native shim and
|
||||
parity suite already witness released Box3D behavior for:
|
||||
|
||||
- circle bodies in a 2D physics plane
|
||||
- radial fields for Aetheria-style gravity wells
|
||||
- semi-implicit Euler integration
|
||||
- circle collision detection and simple impulse response
|
||||
- SoA world buffers as the simulation authority
|
||||
- CultCache MessagePack persistence for `gamecult.ymir.world_state.v0`, using
|
||||
the directory store to avoid rewriting cold records
|
||||
- CultMath `BatchMath` SIMD kernels for radial field acceleration and
|
||||
semi-implicit Euler integration
|
||||
- deterministic contact events
|
||||
- CLI smoke commands
|
||||
- local HTTP daemon with `/simulate/step`
|
||||
- sphere overlap and shape casts
|
||||
- tractor capsule membership and rounded caps
|
||||
- numeric overlap and cast slop
|
||||
- planar sphere-world stepping
|
||||
- contact-begin facts
|
||||
- restitution mixing
|
||||
- transient torque lifetime
|
||||
|
||||
This is not pretending to be a finished physics engine. It is the first clean
|
||||
owner, and therefore already better than collider callbacks wearing a crown.
|
||||
The legacy managed Ymir solver remains temporarily live while retained Box3D
|
||||
world sessions, end-contact lifecycle, continuous collision, replay, and
|
||||
checkpoint reconstruction are connected. It is compatibility scaffolding, not
|
||||
the target architecture. It will be deleted, along with Ymir's custom geometry
|
||||
and spatial indexes, once the Box3D-backed path proves the public contract.
|
||||
|
||||
## Smoke
|
||||
See [the architecture map](docs/architecture.md) and
|
||||
[the executable parity contract](docs/box3d-parity.md).
|
||||
|
||||
## Build And Test
|
||||
|
||||
Initialize the pinned dependency and run the solution:
|
||||
|
||||
```powershell
|
||||
dotnet test
|
||||
dotnet run --project src\ymir-daemon -- step-sample
|
||||
dotnet run --project src\ymir-daemon -- provider
|
||||
dotnet run --project src\ymir-daemon -- serve --port 8877
|
||||
git submodule update --init --recursive
|
||||
dotnet test Ymir.slnx
|
||||
```
|
||||
|
||||
HTTP endpoints:
|
||||
The parity project builds the native shim from source and requires CMake plus a
|
||||
C17 compiler:
|
||||
|
||||
- `GET /health`
|
||||
- `GET /provider-advertisement`
|
||||
- `GET /operator-state`
|
||||
- `GET /eve/operator`
|
||||
- `POST /simulate/step`
|
||||
```powershell
|
||||
dotnet test tests\Ymir.Box3D.Parity\Ymir.Box3D.Parity.csproj
|
||||
```
|
||||
|
||||
`POST /simulate/step` accepts the same shape emitted by `step-sample`.
|
||||
Box3D is MIT licensed. Its license is retained in `extern/box3d`.
|
||||
|
||||
## Cutover Rule
|
||||
|
||||
Aetheria should first route projectile travel and hit discovery through Ymir
|
||||
while keeping Unity as renderer/presenter. The old Unity collider path becomes a
|
||||
visual witness and adapter path only. If manual collision callbacks can still
|
||||
decide gameplay damage after the cutover, the cutover is not done.
|
||||
A Ymir cutover is complete only when all runtime stepping, collision queries,
|
||||
and contact facts come from a retained Box3D world through one Ymir session
|
||||
primitive. Manual Unity callbacks, Aetheria geometry tests, and the managed
|
||||
Ymir solver must be structurally unable to decide the result.
|
||||
|
|
|
|||
|
|
@ -2,78 +2,153 @@
|
|||
|
||||
## Objective
|
||||
|
||||
Own physics for Aetheria outside Unity so projectiles, fields, bodies, and
|
||||
contacts share one simulation truth across game runtime, server logic, tools,
|
||||
and future Verse surfaces.
|
||||
Expose Box3D as authoritative, typed, persistent GameCult physics without
|
||||
leaking an alpha native API into products, clients, or durable state.
|
||||
|
||||
## Current Mechanism
|
||||
|
||||
The MVP has one pure core and one daemon:
|
||||
|
||||
- `Ymir.Core` receives a `YmirSoAWorld` and a fixed `deltaTime`.
|
||||
- Compatibility callers may still submit a `YmirWorld`, but it is immediately
|
||||
lowered into SoA buffers before simulation.
|
||||
- The core computes radial field acceleration with CultMath `BatchMath`, uses
|
||||
vectorized semi-implicit Euler integration over SoA arrays, tests circle
|
||||
overlaps, resolves simple collision response, and emits contact events.
|
||||
- `ymir-daemon` publishes provider/operator state and exposes the core through a
|
||||
small HTTP compatibility surface.
|
||||
- `YmirWorldStateDocument` persists the same SoA world as
|
||||
`gamecult.ymir.world_state.v0` through CultCache MessagePack.
|
||||
Ymir is a wrapper and daemon, not an independent physics-engine research
|
||||
project. Box3D supplies the physics mind. Ymir supplies the memory, nerves,
|
||||
names, and service boundary.
|
||||
|
||||
## Owner
|
||||
|
||||
Ymir owns the decision: given world state plus a time step, what is the next
|
||||
physics state and which contacts occurred.
|
||||
A long-lived Box3D `b3World` owns the physical decision: given the current
|
||||
world plus commands for a fixed step, what transforms, velocities, overlaps,
|
||||
casts, and contact transitions are true.
|
||||
|
||||
Ymir owns the enclosing session and contract:
|
||||
|
||||
- pin and build the accepted Box3D release;
|
||||
- map stable GameCult ids to transient Box3D handles;
|
||||
- accept typed body, shape, filter, force, torque, field, query, and step
|
||||
commands;
|
||||
- project Box3D outputs into typed, deterministically ordered Ymir facts;
|
||||
- reconstruct sessions from CultCache checkpoints;
|
||||
- publish provider, operator, command, receipt, and Eve surfaces through
|
||||
CultMesh;
|
||||
- supervise world lifetime, failure, replay, and observability.
|
||||
|
||||
## Inputs
|
||||
|
||||
- SoA body columns: id, position x/y, velocity x/y, radius, mass, dynamic mask,
|
||||
restitution
|
||||
- SoA radial field columns: id, position x/y, strength, radius
|
||||
- fixed `deltaTime`
|
||||
- stable body and shape definitions
|
||||
- fixed time step and explicit substep count
|
||||
- transient forces, torques, impulses, and target transforms
|
||||
- collision filters and material definitions
|
||||
- overlap, ray, and shape-cast queries
|
||||
- product-owned selections such as which pickup ids a tractor may affect
|
||||
|
||||
Aetheria chooses physical intent and gameplay eligibility. Box3D decides
|
||||
geometry membership and contact. Ymir carries the typed handoff.
|
||||
|
||||
## Outputs
|
||||
|
||||
- next world time
|
||||
- next body positions and velocities
|
||||
- contact events with body ids, point, normal, penetration, and relative speed
|
||||
- body transforms and linear/angular velocities
|
||||
- begin, end, and hit contact facts with stable Ymir ids
|
||||
- overlap and cast results sorted by distance and stable id
|
||||
- step receipts and replay/checkpoint provenance
|
||||
- provider-owned operator and debug projections
|
||||
|
||||
Box3D callback order is not a public contract. Ymir may sort facts, but it may
|
||||
not alter their membership or invent missing contacts.
|
||||
|
||||
## Derived State
|
||||
|
||||
- `YmirWorld` DTO records are compatibility views over `YmirSoAWorld`.
|
||||
- HTTP health, provider advertisement, operator state, and Eve surface are
|
||||
derived compatibility views.
|
||||
- Unity GameObjects are derived render/adapter state.
|
||||
- Damage events in Aetheria should become derived from Ymir contacts plus
|
||||
Aetheria gameplay policy.
|
||||
- Box3D world, body, shape, contact, and joint handles are transient session
|
||||
state derived from stable Ymir definitions.
|
||||
- CultCache checkpoints are reconstruction inputs and publication records; they
|
||||
are not a second live solver.
|
||||
- SoA body documents are transport and inspection projections over the live
|
||||
session.
|
||||
- Eve surfaces are presentation projections over Ymir state and receipts.
|
||||
- Unity GameObjects and Electron objects are render state only.
|
||||
- Aetheria damage, loot, capacity, faction, and scoring consequences are
|
||||
derived from Ymir facts plus Aetheria policy.
|
||||
|
||||
## Dimensional Compatibility
|
||||
|
||||
The fossil Aetheria simulation uses a two-dimensional gameplay plane. During
|
||||
cutover, Ymir maps that plane into Box3D X/Z with translation on Y locked and
|
||||
rotation constrained to the plane normal. This is an explicit compatibility
|
||||
projection. It does not make Ymir a second 2D physics engine.
|
||||
|
||||
Sphere friction and inertia are not identical to planar disk behavior. Any
|
||||
mechanic that depends on that difference must be witnessed against the fossil
|
||||
and then expressed through Box3D configuration, not repaired by a parallel
|
||||
solver.
|
||||
|
||||
## Forbidden Writers
|
||||
|
||||
- Unity `OnCollisionEnter` and collider callbacks must stop deciding projectile
|
||||
hit truth once a cutover path exists.
|
||||
- Renderer transforms must not push hidden physics corrections back into Ymir.
|
||||
- HTTP compatibility witnesses must not become durable state owners.
|
||||
- managed integration, impulse resolution, collision geometry, or broadphase
|
||||
code in Ymir;
|
||||
- persisted force or torque replayed as if it were continuing authority;
|
||||
- Aetheria rectangle, capsule, overlap, or contact tests deciding gameplay
|
||||
physics;
|
||||
- Unity collision callbacks deciding hits, destruction, or pickup collection;
|
||||
- renderer transforms pushing hidden corrections into the world;
|
||||
- transport endpoints or dashboards owning world state;
|
||||
- Box3D opaque ids stored as durable GameCult identity.
|
||||
|
||||
## Shared Paths
|
||||
|
||||
Direct user actions, weapon firing, programmatic spawns, reloads, server ticks,
|
||||
and replay/import paths should all create or modify Ymir world state through the
|
||||
same command/step primitive. Manual Unity interaction may author inputs; it does
|
||||
not become a second simulation.
|
||||
Direct player commands, agent commands, programmatic spawns, server ticks,
|
||||
imports, reconnects, replay, and checkpoint recovery all enter one Ymir world
|
||||
session primitive. DTO compatibility methods may lower into that primitive;
|
||||
they may not run an alternate step.
|
||||
|
||||
Radial gravity and tractor attraction are typed force-generation inputs. They
|
||||
are applied to Box3D before stepping. Pickup collection remains an Aetheria
|
||||
transaction triggered exactly once by a Ymir/Box3D contact fact.
|
||||
|
||||
## Native Boundary
|
||||
|
||||
`extern/box3d` pins the accepted upstream source. `native/Ymir.Box3D` owns a
|
||||
small stable C ABI facade. Managed Ymir code binds only to that facade; it does
|
||||
not scatter hundreds of direct P/Invokes across the daemon.
|
||||
|
||||
The native facade must remain boring:
|
||||
|
||||
- caller-owned blittable buffers;
|
||||
- explicit version and precision facts;
|
||||
- no GameCult gameplay policy;
|
||||
- no JSON state boundary;
|
||||
- no public exposure of Box3D internal handles;
|
||||
- first-class RID packaging before production consumers depend on it.
|
||||
|
||||
## Persistence
|
||||
|
||||
The canonical checkpoint schema must contain enough typed definitions and
|
||||
state to reconstruct the accepted Box3D world: stable ids, 3D transforms,
|
||||
linear and angular velocity, body/shape/material/filter definitions, session
|
||||
tuning, and provenance.
|
||||
|
||||
Transient forces and torques are commands, not durable body state. Derived
|
||||
mass and inertia are published only when useful for inspection. Old checkpoint
|
||||
versions must migrate explicitly or fail closed; they may not silently decode
|
||||
under a reassigned MessagePack layout.
|
||||
|
||||
## Cut Line
|
||||
|
||||
The old Aetheria projectile GameObject/collider path is demoted first to a
|
||||
renderer and diagnostic witness. New damage or hit policy must consume Ymir
|
||||
contact events. Only after that path is proven should Unity collider callbacks
|
||||
be deleted.
|
||||
The managed Ymir solver, `YmirQueryPrimitives`, and `YmirSpatialIndex` are
|
||||
deleted when retained Box3D sessions prove:
|
||||
|
||||
## Verification Layer
|
||||
1. fixed-step body state projection;
|
||||
2. begin/end/hit contact lifecycle;
|
||||
3. overlap and shape-cast lowering;
|
||||
4. continuous collision and projectile witnesses;
|
||||
5. transient force and torque application;
|
||||
6. checkpoint reconstruction and replay;
|
||||
7. Aetheria gravity, tractor, pickup, and payload smokes.
|
||||
|
||||
- Unit tests prove core integration, gravity field acceleration, deterministic
|
||||
ordering, and contact generation.
|
||||
- CLI smoke proves the daemon can execute a step without booting Unity.
|
||||
- Aetheria cutover needs a Unity-side timeline probe that compares visible
|
||||
projectile positions and hit events against Ymir snapshots during travel, not
|
||||
only after impact.
|
||||
There is no managed fallback after that cut. A native load or compatibility
|
||||
failure fails closed and reports the missing capability.
|
||||
|
||||
## Verification
|
||||
|
||||
- Box3D parity tests record released upstream law at the native boundary.
|
||||
- Ymir differential tests compare public projections with the same Box3D
|
||||
session facts.
|
||||
- Negative source checks prove custom solver and spatial-index authorities are
|
||||
absent after cutover.
|
||||
- Aetheria smokes prove gravity, contact-gated destruction loot, tractor
|
||||
attraction, pickup collection, and fast payload hits.
|
||||
- Released-client witnesses prove generic Eve clients only observe Ymir and
|
||||
Aetheria provider contracts, never native implementation details.
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
## Authority
|
||||
|
||||
Box3D v0.1.0 is Ymir's collision-semantics oracle while the native cutover is
|
||||
under construction. The exact upstream source is pinned as the
|
||||
Box3D v0.1.0 is Ymir's physics implementation and executable semantics oracle.
|
||||
The production session cutover is still under construction. The exact upstream source is pinned as the
|
||||
`extern/box3d` submodule at commit
|
||||
`8441b4a06d6d09dcfb0b0f704df4d847d1437b92`.
|
||||
|
||||
The oracle does not own GameCult entity ids, gameplay policy, persistence, or
|
||||
result ordering. Ymir projects Box3D facts into those contracts. Box3D owns
|
||||
Box3D does not own GameCult entity ids, gameplay policy, persistence, or result
|
||||
ordering. Ymir projects Box3D facts into those contracts. Box3D owns
|
||||
shape overlap, shape cast, solver, broadphase, contact lifecycle, force and
|
||||
torque lifetime, and numeric tolerances.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue