Chipmunk and networking

Official forum for the Chipmunk2D Physics Library.
Post Reply
savior
Posts: 8
Joined: Tue Jan 01, 2008 5:24 pm
Contact:

Chipmunk and networking

Post 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?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Chipmunk and networking

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
savior
Posts: 8
Joined: Tue Jan 01, 2008 5:24 pm
Contact:

Re: Chipmunk and networking

Post 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.
savior
Posts: 8
Joined: Tue Jan 01, 2008 5:24 pm
Contact:

Re: Chipmunk and networking

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Chipmunk and networking

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
savior
Posts: 8
Joined: Tue Jan 01, 2008 5:24 pm
Contact:

Re: Chipmunk and networking

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Chipmunk and networking

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
savior
Posts: 8
Joined: Tue Jan 01, 2008 5:24 pm
Contact:

Re: Chipmunk and networking

Post 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.
supertommy
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm
Contact:

Re: Chipmunk and networking

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Chipmunk and networking

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests