ewjordan wrote:
That's great that you got something working, I'd love to see a demo when you feel comfortable enough to show it off! I recall Erin suggesting that embedding the networking code in the release version of the engine itself might not be the best idea because of all the additional application specific handling that needs to happen, but I think a patch would be great to have as a jumping off point. Anyone doing this type of game is going to be hacking around a lot anyways, so a little work on their part is to be expected. 🙂
Actually, I've managed to move the world serialization stuff entirely out of the existing Box2D code and into two new classses (b2ClientWorld and b2ServerWorld) and the dozen or so classes that they use internally. The biggest issue with portability is that developing a networked simulation requires that you stick to a particular model pretty tightly. For example, you have to provide a callback to resolve collisions, and the callback must be deterministic. (This is a restriction of any client-side prediction algorithm.) I also haven't worked with joints yet--it's just rigid bodies right now--and bodies, including their attached shapes, may not be modified once created. Both of these limitations could be relatively easily overcome with more work.
ewjordan wrote:
How bad are the performance issues you're running into with your added layer? Are they problems with respect to local computation or network latency/bandwidth? Also, are you working out a peer-to-peer or server based approach?
I haven't done any profiling. I'd guess the difference is not likely to get better than about an order of magnitude, just because of how client-side prediction works.
I chose a client-server model. Peer-to-peer distributed simulation is an entirely different topic, unfortunately, and becomes much more complex very quickly. Whose temporal viewpoint is correct, when latency makes conflicting things happen? Whose viewpoint is correct if one peer decides to tamper with the simulation to cheat?
The performance issues are due to the fact that I am using full checkpointing. I keep a history of some fixed length, and I store all dynamic properties of every object at each timestep. (I am sure that, by using some sort of preallocation scheme like Box2D proper does, I can significantly improve the performance of this stage.) What really kills is that when an update-in-the-past arrives from the server, the simulation must be rolled back and resimulated, often by multiple timesteps, as quickly as possible.
This is pretty much just how client-side prediction works. However, by either using more complex external data structures or by modifying Box2D internally a little bit, it should be possible to roll back the simulation and then move forward again, only resimulating "dirty" bodies. I think that I have figured out how to do this without modifying Box2D itself (but accessing all sorts of internals). I am trying to get a nice testbed/simulator and demo for the inefficient scheme going before I try this.