Repository navigation
Replies: 6 comments
|
A revision, after working through clients that hold only part of the world (area of interest for multiplayer games). With interest management a client's world contains the bodies near its player, and that set changes on the network's schedule: remote bodies are created when they enter range and destroyed when they leave. So the structure at save time and at restore time is often not the same, and a whole-world restore that refuses on mismatch would refuse on every rollback that straddles such a change. It would also save far more than the client resimulates, which is only its predicted bodies plus whatever is physically coupled to them. The fix is to make the island the unit instead of the world. The state that // Save every island containing at least one seed body, with its contacts and joints
// (including those against static bodies). Buffer lists the ids it holds (index + generation).
B3_API int b3World_GetIslandStateSize( b3WorldId worldId, const b3BodyId* seeds, int seedCount );
B3_API int b3World_SaveIslandState( b3WorldId worldId, const b3BodyId* seeds, int seedCount,
void* buffer, int capacity ); // bytes written
typedef struct b3RestoreResult
{
int bodiesRestored, bodiesSkipped; // skipped: id no longer valid
int contactsRestored, contactsDropped; // dropped: a shape on either side is gone
int jointsRestored, jointsSkipped;
} b3RestoreResult;
// Restore in place: transform, velocities, sleep state and island membership per body;
// manifold, impulses and colour per contact; warm-start impulses per joint. A missing body
// is skipped, a contact with a missing counterpart is dropped and re-found cold next step.
// Bodies the buffer does not mention are untouched.
B3_API b3RestoreResult b3World_RestoreIslandState( b3WorldId worldId, const void* buffer, int size );Seeds are the bodies the peer predicts; the engine expands them to whatever is coupled to them right now. Skipped and dropped are the tolerance for a body that left range between save and restore. On the common rollback the counts are zero. The guarantee this asks for: after restore, What this needs that does not exist today: a writer for a contact's manifold and accumulated impulses, placement of a contact into a specific colour, and a joint warm-start writer. The island arrays already exist. The test is save at frame k, step ahead, restore, step once, hash-compare against the original k+1. |
|
Islands can change each step. So if body A is not touching any thing and is saved, it may generate a contact the next step. Rolling back that single body will leave the fresh contact hanging. Also critical is the order in the dynamic tree. This determines the collision pair order and then the constraint graph order. How important is size? Are you planning to use the state for join in progress? |
|
My game has max rollback of 1 second, so if that's exceeded it just resets the full state. So if a user joined an in progress game, they would just receive the current full state of the world and start simulating from there. Its more so for the actual deterministic rollback support. And size being configurable is a benefit for games involving Area of interest, these games may have thousands of players but rolling back each networked object every tick is unfeasible, with AOI we are able to rollback only the interested subset gaining both better Network utilization and CPU Utilization. I'm not sure how fast it would be to restore the full world state if Box3d has thousands of objects. If its fast i think it would not be a problem to rollback the full world. |
|
I think for the island thing to work, island splitting needs to be blocked until certain sync points. It is also important to know that Box3D does not split islands until a body in the islands wants to sleep. It is a lazy system. I'm also considering a dynamic tree setup where the awake bodies get their own tree. Then a snapshot could contain just the awake tree and the related data. I will probably try this in Box2D first. |
|
That makes sense, take your time and thank you |
|
Didn't notice this thread. Have done some investigations along the same lines and you can probably find something of value in them. This document collates the facts from my investigation. Working on a bit-exact history ring + journal approach for whole-world. It faces the same issues with tree traversal order, I'm working on adding a sort which makes the order of things the same after a rollback. Will have some tests demonstrating the issue to post shortly. |
Uh oh!
There was an error while loading. Please reload this page.
Im looking for rollback support also, and checked with fable on potential low cost support. Basically it suggests splitting the state from structure:
Structure is what the world is made of: which bodies exist, their shapes and sizes, the collision meshes (a terrain or a hull can be thousands of triangles), the joints and which bodies they connect, and the ids of all of them. It changes only when your game creates or destroys something. Between two ticks of a match, it is almost always identical.
State is where everything is right now: each body's transform and velocities, whether it is asleep, and the solver's memory of the current contacts, their manifold points, accumulated impulses, and their slots in the constraint graph. It changes every step. This is the part a rollback needs to put back.
With the assumption that when a rollback is happening the structure is not usually recreated.
Would it be possible to support that?
We would use this for rollback netcode (Netick, 60 Hz, up to ~13 ticks of resimulation after a misprediction), so here is the shape that would work for us, and it addresses the size concern directly.
Split structure from state. A rollback user never changes the world's structure between snapshot and restore: bodies, shapes, joints and their collision meshes are created and destroyed on the game's own tick schedule, so both sides of a restore already hold the same set with the same ids. The snapshot therefore does not need to embed meshes, shape definitions or body definitions at all. What it needs is the per-step dynamic state that b3Body_SetTransform and the velocity setters cannot reach:
per body: transform, linear and angular velocity, sleep time / awake, island membership;
per contact: the manifold (anchors, normal, separation, feature keys, accumulated normal, tangent and rolling/twist impulses), the touching flags, and its slot in the constraint graph — the colour decides solve order, so without it a restored world can converge to a different last bit than the original run;
per joint: warm-start impulses and any accumulated state;
anything else the step reads that persists across steps (contact recycling distances, event queues can be dropped).
That is
O(bodies + contacts), a few hundred bytes each, and it is the same data the replay player's keyframe ring already snapshots and restores in place.Proposed API
If a structural mismatch is cheap to detect (body/shape/joint counts and id ranges), refusing is enough; we would rather get false than a partially restored world.
The guarantee we depend on: after RestoreState, b3World_Step with the same inputs and worker count reproduces the original run's next state bit-for-bit — the property the keyframe seek already relies on. Stating it in the header, and covering it with a test that snapshots at frame k, restores into a stepped-ahead world and hash-compares k+1, would make it something we can build on.
Two things that would make the netcode side easy
A save per tick into a ring of ~64 with no allocation: GetStateSize stable while structure is unchanged, so buffers can be preallocated.
Restore not clearing the contact/graph state before rebuilding, so a restore followed by a step costs one step, not a broadphase rebuild. Without this we would have to destroy and recreate dynamic bodies on every rollback and run with warm starting off to stay deterministic, which works but throws away exactly the convergence warm starting buys.
If it helps, the ~580-function Unity binding maintained at Suvitruf/box3d-unity is what we consume, so three flat functions with a plain byte buffer is the friendliest shape for that layer.
All reactions