World Rollbacks and Networking

Hey everyone,

Still new to Box2D and fiddling around with as an engine for my game. I'm curious if anyone had any experience with applying state-rollbacks for network sync correction as described in this article http://gafferongames.com/game-physics/networked-physics/ to a Box2D world. If so, how exactly do you handle the rollbacks? Do you completely destroy and recreate each body anytime you need to rollback to a previous state? Or do you store references to each in each state and adjust parameters? How do you deal with a previous state where a body exists in the world that has since been destroyed, or vice versa? I've seen posts on serializing states for storage in files and playback, but not one for on-the-fly world control. Any advice? Thanks!
Hi Derelict,

Did you make any progress on this since?

I had the same idea for networking box2d; just remember rollbacks are only necesary when 2 or more players interact with the same objects... So the rollback would only be necesary for the objects within a certain range of the out-of-sync objects (so it wouldnt be necesary to rollback the entire simulation)

-Martijn
I've always seen the network approach more at removing the whole client-side world aspect; the server does the calculations and sends the data (position, render shape, etc) to the clients.

-P
The same problem exists with a client/server model:

When player 1 interacted with object1 at time 2, server recieves it at time 4
Server goes one simulation step forward
When player 2 interacted with object1 at time 2, server recieves it at time 8

No the server should take into account the interaction from player 2 that also happend one simulation step back... so it should rollback to make it consistent at the current simulation step again
You could save only the changed parameters (position, angle, velocities) for each networked body. I haven't done that myself but recreation of bodies looks like overkill to me. And removing the whole simulation out of client side wouldn't be so good if it's an action game. Btw, you will need to interpolate between states anyway so you'll have to save the previous state of each networked body. 😉
snake5 wrote:
You could save only the changed parameters (position, angle, velocities) for each networked body. I haven't done that myself but recreation of bodies looks like overkill to me.


I think so too, also, I'll have to expiriment with creating an seperate simulation for the affected objects for the roll-back, and copy the resulting states back to the main simulation.

Does anyone know of an good solution to automate this state recording? Doing it yourself for each object seems silly...
Box2D is open-source. You can modify it to support automatic state saving for bodies with an "e_networkBody" flag.. then add Rollback() function in the world class and make it do miracles with the saved states. 🙂 It doesn't look too hard to me. 😉

Or.. find the HL2 source code and try to understand how they are handling networked bodies. 😉
I don't understand how you're getting two different times from two different players; the server should/would be running at a constant FPS. It would grab all the player movement data (ie, what buttons are pressed), apply it to the objects before stepping, then do the world step. That's how I handle it in PhyTers at least.

-P
snake5 wrote:
Box2D is open-source. You can modify it to support automatic state saving for bodies with an "e_networkBody" flag.. then add Rollback() function in the world class and make it do miracles with the saved states. 🙂 It doesn't look too hard to me. 😉

Or.. find the HL2 source code and try to understand how they are handling networked bodies. 😉


Yes, but hacking the box2d source wouldn't be that portable, I'd have to apply my changes each time a new version comes out 😕 Also a rollback in the world class wouldn't be efficient. Ideally you'd be able to just to do simulation steps for only those objects that need to be re-synced (within a certian area of interest), so you'd like to have them in an seperate world that can be synched with the full world. It might not be hard, but it would require a layer upon box2d. I found there are/have been some effords in that direction:

viewtopic.php?f=3&t=143
viewtopic.php?f=8&t=3131
viewtopic.php?f=5&t=120

ps: snake5, check your PM 😉

Paril wrote:
I don't understand how you're getting two different times from two different players; the server should/would be running at a constant FPS. It would grab all the player movement data (ie, what buttons are pressed), apply it to the objects before stepping, then do the world step. That's how I handle it in PhyTers at least.

-P


Yes, but the server can't wait forever before continuing to the next step. If a player has enough lag, input for a given step can arrive after the server has simulated that step...
Quote:
I'd have to apply my changes each time a new version comes out

You don't have to update it whenever a new version comes out. And the new version will be much different anyway.

Original thread: https://box2d.org/forum/viewtopic.php?t=3373