Page 1 of 1

Chipmunk and networking

Posted: Sun May 11, 2008 5:25 pm
by savior
Hi, I'm planning a 2D top down vehicle shooter, and I'd like to include multiplayer support, using networking, over LAN (low latency, less worrying about bandwidth).

My question is if it's possible to use chipmunk as the physics library for this project, and I'm asking because from what I've seen, sometimes, the simulation is not always the same on my computer, when running the demos. Could this cause any problems with the game, like, one person sees one thing, and another sees another, just because of chipmunk?

Any troubles that may arrise from this unequal simulation? How should I handle this?

Re: Chipmunk and networking

Posted: Mon May 12, 2008 1:02 am
by slembcke
You are correct, given a different processor or compiler, the physics won't run exactly the same due to floating point errors. When writing your networking code you are going to have to keep that in mind.

I've never really written a complicated networking game, so I don't really have any experience to draw on. If I was implementing such a thing, I'd be continually sending out snapshots of the objects. If there's only a few objects, you could probably just send out a full snapshot on every packet. If you have a lot of objects, send out a few of the objects at a time.

On the other hand if you are assuming low latency, maybe only run the physics server side. The clients then just display objects using the last know positions and dead reckoning. Would certainly make writing the client code easier.

Re: Chipmunk and networking

Posted: Tue May 13, 2008 4:56 pm
by savior
Thank you very much for your help, that gave me some nice new ideas to have in mind.

To clarify, I don't plan to use multiple compilers, since I'm using only Delphi, so you can assume that all the versions running will be exactly the same. But the processors, no way.

Onto the new questions :mrgreen:

Does anyone knows how can I handle this floating point errors on the application?

If I send snapshots of objects, what would they contain? Forces? Heading? Can I set it directly in chipmunk, or should I do something like this:
Given the client's current position
And the desired position received from the server, do:
Calculate force so that current position becomes desired position. Apply.

Something like this?

I could also only send the snapshots that are "in range" of the client (like, distance less than 30 units), an easy optimization to reduce the snapshots.

I'm also considering doing the physics server side, I'm not sure however about the responsiveness client-side, that's something I should experiment to see it working. However, I'm not sure about the dead reckoning (heh, never did something like this, either).

Thank you for your help, and pleased to hear any other idea on this subject.

Re: Chipmunk and networking

Posted: Tue May 13, 2008 9:11 pm
by savior
I also have another question:

Is chipmunk deterministic, or non-deterministic?

From what I've googled, deterministic physics engines should be ideal for networked games.

Re: Chipmunk and networking

Posted: Tue May 13, 2008 10:53 pm
by slembcke
Chipmunk is deterministic, but not in a simple way. As long as collisions are processed in the same order, the simulation will be deterministic. Collisions are considered in the order that they are reported by iterating a hash. The hashing order is determined by shapeIDs (created specifically to deal with the determinism issue). Again, a different processor or compiler will also generate different floating point code that will produces slightly different simulations after many complex interactions.

The documentation for cpResetShapeIdCounter() is a bit vague, but you should start there. What's not clear in the documentation is that the shapeID counter is global, so you can't really be adding shapes to more than one space at a time.

Re: Chipmunk and networking

Posted: Wed May 14, 2008 10:22 am
by savior
Ok, thank you.

I'll try to make a client/server simulation, and see if it works. Otherwise, I'll go for the server only simulation.

Re: Chipmunk and networking

Posted: Wed May 14, 2008 12:05 pm
by slembcke
I had bookmarked a couple of good articles on the Quake 3 and Unreal networking models a while back. I'll see if I can dig up the links when I get home.

Re: Chipmunk and networking

Posted: Wed May 14, 2008 8:24 pm
by savior
Ok, thanks.

Meanwhile, I've been googling, and I've found this very interesting topic on the subject:
http://www.box2d.org/forum/viewtopic.ph ... &sk=t&sd=a

It's a good read, plus, follow the links there.

Re: Chipmunk and networking

Posted: Mon May 19, 2008 9:00 am
by supertommy
slembcke wrote:I had bookmarked a couple of good articles on the Quake 3 and Unreal networking models a while back. I'll see if I can dig up the links when I get home.
Maybe you mean the ones linked to in the sticky post in the networking section on the idevgames forum?

http://www.idevgames.com/forum/showthread.php?t=13402

Those three pages are definitely very interesting.

Re: Chipmunk and networking

Posted: Mon May 19, 2008 5:38 pm
by slembcke
Why yes in fact. I got them out of the iDevGames irc at some point. I had forgotten that they were on the forums.