Okay, this is not an official release (I'm going to let it sit a couple days in case bugs turn up), bug at http://www.jbox2d.org/demos/Pendulum_src.zip you can grab the latest .zip of the JBox2D 1.4.3 update. Sorry about the Pendulum_src.zip name, it's auto-generated and I have to track down the right place to change that...
Networked Physics
General DiscussionI hope someone is still interested in that thread 😉
This seems tricky. Rolling back just a few objects could interfere with other objects that are not rolled back, while rolling back the entire simulation is perhaps too CPU expensive.
The two worlds would never be completly equal. Floating point operations are different on different CPUs. There's strictfp in Java, but even than you had problems with single objects that were rolled back, predicted computations based on player-input etc.
I would even suggest to send the player state in a regular interval, to avoid the consequences of package-loss.
That seems very CPU intensive to me, even if there are "only" two frames to simulate this would double the needed processing power by the server.
Do you have any suggestions or solutions to those "problems"? I'm trying to implement something for phys2D (also based on Box2D) and that are mostly the problems I am facing.
Apart from that, I would implement it the same way you suggest, but without rolling back the whole simulation on the server. With interpolating between the corrected position of an object (known from the server) and the client-position, the simulation could be smooth without the rollbacks. First tests with a simpler physics "engine" seemed to work pretty okay with that approach.
Anyway, interesting topic, would be glad if we could share our experiences 🙂
ewjordan wrote:
Client-side
1)
- Roll back 'dirty' objects to snapshot time and alter states as necessary
- Compute current 'real' time based on server timestamp and measured average latency
- Simulate dirty objects up to real time
- Either roll back other objects to 'real' time or simulate them forward - should be within a frame or two already, hopefully
1)
- Roll back 'dirty' objects to snapshot time and alter states as necessary
- Compute current 'real' time based on server timestamp and measured average latency
- Simulate dirty objects up to real time
- Either roll back other objects to 'real' time or simulate them forward - should be within a frame or two already, hopefully
This seems tricky. Rolling back just a few objects could interfere with other objects that are not rolled back, while rolling back the entire simulation is perhaps too CPU expensive.
ewjordan wrote:
- Maybe: every once in a while, compute a world hash and compare to server's, ask for a full snapshot if they differ
The two worlds would never be completly equal. Floating point operations are different on different CPUs. There's strictfp in Java, but even than you had problems with single objects that were rolled back, predicted computations based on player-input etc.
ewjordan wrote:
- If change in player state has occurred, send timestamped message to server.
I would even suggest to send the player state in a regular interval, to avoid the consequences of package-loss.
ewjordan wrote:
- Roll back to message time.
- Simulate up to next message time.
4) Simulate up to real time.
- Simulate up to next message time.
4) Simulate up to real time.
That seems very CPU intensive to me, even if there are "only" two frames to simulate this would double the needed processing power by the server.
Do you have any suggestions or solutions to those "problems"? I'm trying to implement something for phys2D (also based on Box2D) and that are mostly the problems I am facing.
Apart from that, I would implement it the same way you suggest, but without rolling back the whole simulation on the server. With interpolating between the corrected position of an object (known from the server) and the client-position, the simulation could be smooth without the rollbacks. First tests with a simpler physics "engine" seemed to work pretty okay with that approach.
Anyway, interesting topic, would be glad if we could share our experiences 🙂
What is the status of this project? I need to look at networking soon.
The project just began. A running demo with network capabilites should be up and running in one month (after christmas). If you wish, I could give feedback here 🙂
Yes, please. Did you get any response to your worries about CPU Intensity, because I worry too. I'm not making some LAN app, I'm making 1000+ user app.
Unfortunatelly I've no answer. In a discussion on gaffer.org Glenn Fiedler (the guy that did a GC talk on networked physics) says that in worlds with many objects it is likely to be too CPU intensive to resimulate... he's holding a GC talk in 2008 again, about physics in worlds with many objects. But the GC is still far away :p
By the way, happy xmas 🙂
By the way, happy xmas 🙂
I downloaded that Pendulum zip, but I can't find any code related to networking. Is that to be done, or am I missing something?
Nope, I've done no networking code myself, I didn't make that clear - that zip file is just the Java Box2D code, nothing to do with networking. COmmanderKeith had mentioned that a recent zip of the code would help his efforts, so I put the link up here in response. The page break disconnected his request from my response, hence the confusion. I think we'll probably have to wait a bit longer before any live demos of networked physics are up.
Who is working on the network demos? Are there any sourceforge projects up? Has anyone made any code yet to dump body positions and movements to send over a network?
COmmanderKeith was the only one that had anything to show, I think - he put a basic demo up earlier in the thread that showed his approach in a simple context, but I'm not sure if he ever did anything that actually uses Box2D (JBox2D in his case, as he's doing this in Java). To my knowledge there's no SF project or anything at this point.
As much as I would love to head up or at least participate actively in an effort in this direction, to be honest I don't see myself being able to do much right now - I'm up to my neck in unfinished but promised OSS code as it is, and I don't want to start promising more until I can tick a few outstanding things off my todo list. Maybe in a month or two I will be free to do something, but I've never dealt with networking in any language, so I'm not really comfortable taking charge here...
Having said that, I'm curious: does anyone know a good solution as far as server side handling goes? Even for testing purposes some sort of server will be needed, and most hosting services will only let you run basic PHP scripts and stuff, which I don't think will cut it for real time multiplayer stuff. My ISP cripples my connection to the point where I can't just set up a server at my house or anything like that, and from what I know P2P quickly turns into a nightmare for many reasons. Are there any decent solutions to this, short of actually buying a game server and a proper unrestricted connection?
As much as I would love to head up or at least participate actively in an effort in this direction, to be honest I don't see myself being able to do much right now - I'm up to my neck in unfinished but promised OSS code as it is, and I don't want to start promising more until I can tick a few outstanding things off my todo list. Maybe in a month or two I will be free to do something, but I've never dealt with networking in any language, so I'm not really comfortable taking charge here...
Having said that, I'm curious: does anyone know a good solution as far as server side handling goes? Even for testing purposes some sort of server will be needed, and most hosting services will only let you run basic PHP scripts and stuff, which I don't think will cut it for real time multiplayer stuff. My ISP cripples my connection to the point where I can't just set up a server at my house or anything like that, and from what I know P2P quickly turns into a nightmare for many reasons. Are there any decent solutions to this, short of actually buying a game server and a proper unrestricted connection?
Original thread: https://box2d.org/forum/viewtopic.php?t=143