This project has moved and is read-only. For the latest updates, please go here.

Farseer & Network

Sep 10, 2009 at 7:10 AM


first sorry for my bad english.

can we make a Network Game wit Farseer ? if yes what is the best way ? fo example we have a game that each player control a Box. i think the best way is that server have a PhysicSimulator and Cients just get Positions from Server and draw the objects.



Sep 11, 2009 at 5:27 PM

I think your idea is probably best - providing you don't have too many objects to network. Have a look at the network samples on the creators club site - they limit bandwidth to about 8K/sec, which restricts your object count quite severley.. However, I suspect some games such as Half Life 2 Death Match would be running a physics simulation on the clients, allowing you to less frequently sync the sim client objects with the server objects. I'd also be interested to hear if anyone has any experience with networked physics simulations?

Sep 11, 2009 at 7:53 PM
Edited Sep 11, 2009 at 7:54 PM

is it posible to have a network game with 160 Phyiscs Objects but in SlowMotion Mode : PhysicsSimulator.Update(gameTime.ElapsedGameTime.Milliseconds * 0.00025f);  ?

is 8K/sec enough for this Physic game ?


Sep 13, 2009 at 4:50 PM

I don't know, but I doubt it. I got my 8K/sec information by downloading the network prediction creators club sample and reading the HTML help file. I'm still deciding on the best approach myself, but I think for 160 objects you'd need to be running the sim on the clients. Good luck and please report back if you find any more useful information on the subject :)

Sep 14, 2009 at 5:19 AM

If you're going to do all physics calculations on the server, then the minimum data you'd need to pass back for each object is:

object ID (1 byte (because 2^8 = 256 > 160))

x and y coordinates (2 * 4 bytes )

rotation angle (1 * 4 bytes)

(60 frames / sec) * (13 bytes / object) * (160 objects / frame) = 122 KB / sec

Even if you were to assume 30 fps, and went really skimpy on data (rotation angle could probably look good enough as 2 bytes, and x and y coordinates can be 2 bytes each, because 2^16 = 65535, which is greater than anyone's screen resolution).

30 * 7 * 160 = 33 KB / sec

Now I suppose the question is, what's with that 8K limit? Is it something to do with the sample or with something deeper?



Sep 14, 2009 at 12:47 PM
Edited Sep 14, 2009 at 12:55 PM

thanks Cowdozer.

but ... i have another idea.

at the first of the game we sned all of the informations (all the Positions and Angles). then each frame we just send the movement vector. not the positions vectors. i don't think that in a 30 fps when our game is in slow motion mode, each object  move more than (128,128).Lenght. to check that the positions and Angles are correct in all clients we can send the positions and Angles each 5 sec.

we can also use 4 bits of a byte for X  and another 4 bits for Y . ( if in each frame no object move more than (8,8).Lenght. we use 1 byte for Object ID. and we use 1 byte for Angle. ( we can send the Angle changes in 4 bits of that byte for Angle and then use 2 bits of it for X and another 2 bits of it for Y in adition to the first byte.) so we just use 3 bytes for each object.

(30 frames / sec) * (3 bytes / object) * (160 objects / frame) = 14.4 KB / sec

another problem :

we have 15 clients. the host should send data with this speed : (14.4 * 15) KB / sec  = 216 KB/ sec


sorry , my english is too bad.


Sep 14, 2009 at 1:18 PM

ohh ...

i read this in Network Prediction Sample :

"Every time we send a network packet, approximately 50 more bytes are used for the packet header (28 bytes for a standard UDP packet header, plus ~22 for LIVE and the XNA Framework)."

Sep 15, 2009 at 1:33 AM

Hi mahdibahrami, I have read elsewhere that 8KB/sec is indeed a limitation, although you should note that it's limited to 8KB each way (upload and download can each have 8KB/sec). You may wish to look at this blog posting by Shawn Hargreaves about dealing with the header size and making the most of your 8KB.

Note that if you are sending UDP packets, delivery is not guaranteed, so although it may be a good idea to send velocity data so that clients can interpolate between updates from the server, you need to make sure that if a packet is lost, a client will not become permantly out of synch with the rest of the players.

How about we try this. Every 1/4 second, we send current position and rotation data (~7 bytes) and movement data (~3 bytes) for every object.

(4 sends / sec) * (10 bytes / object) * (160 objects / send) = 6.25KB

So, that could possibly work. It's still too much to have a client/server model (for server, 6.25 * 15 is still too large), but realise that not all 160 objects will change velocity and rotation every .25 sec, right? If you only send the ones that change, you might be able to get below the limit. Even so, a P2P (peer to peer) model may be better on distributing the bandwidth than client/server, although it may be more of a challenge to make work.

By the way, don't worry about your english, I've been understanding you fine!

Sep 15, 2009 at 2:32 AM

Does anyone know if the Farseer engine is deterministic? If it is, then you only have to make sure that any random number generators are using the same seed and the physics simulator in each client should be running the exact same way, that way you only need to sync objects that change due to player interaction. This would reduce bandwidth usage a lot. You could probably use the extra bandwidth to double check a few objects every once in a while, just to make sure all clients a synced.

Sep 15, 2009 at 4:01 AM

Well, Farseer is made to run on multiple platforms, so I wouldn't bet on it working exactly the same on every platform. Someone like genbox would have a better idea of what to expect, but the reason I was supporting having the physics done on one server is so that you would not have to worry about whether it runs exactly the same on every machine.

Sep 15, 2009 at 12:12 PM

I know that, but even if Farseer is made for multiple platforms most games are made just for one, and even multiplatform games tend not to network with different versions. Besides aren't we trying to solve the 8kb limit that XNA versions of a game would have to work under? Wouldn't all the clients in the game be running the XNA version of the engine?

You can have a server in the sense that other clients sync to it when they need to. But having all client run a seeded simulation and only syncing when human interaction changes the way the simulation would have run if left alone would decrease bandwidth usage a lot more than just updating objects that move (which is very good on it self) when we only have 8kb/s of bandwidth to work with.

Of course this can only work if Farseer, or at least the XNA version, is deterministic. That is, if you seed it and leave it alone, it would run the exact same way time after time. That's why I ask if anyone knows if Farseer is deterministic.