lots of circles - performance advice.

Topics: Developer Forum
Dec 10, 2007 at 9:54 PM
Hello all.

I am doing some experimenting whilst I play with ideas for my next game... and it involves lots of circles banging into each other.

From my brief experiments I have found I can happily have over 600 circles.. but if I get most of them colliding, then the fps comes down very very low.

I have tried dabbling with the following settings, but nothing gave it a massive boost (that I noticed)

CollisionGridCellSize (currently using default)
Edges (for my circle geometry, currently at 10)

I just wondered if I am trying to do something a bit odd (I would quite like to be able to have hundreds of circles in contact)

I have plenty of other plans I can do if this is too computationally expensive, so all I am looking for is a heads up if I am going down a dead end.

Thanks very much.

ps.. I should really soon be releasing a demo of my current game (which uses farseer now)
pps... Thanks again for creating Farseer, it's allowing me to dabble in some really fun stuff.
(and thanks to others who help out on this discussion board)

Dec 10, 2007 at 11:41 PM
update: I have had some success by adding an automatic repulsion... minimising the amount of collisions that actually occur, I can prevent the performance degradation that occurs when a lot of objects are touching.

(I seem to recall reading on this site that objects in contact are very expensive)
Dec 11, 2007 at 11:37 AM
siumlataneous contacts is a bottleneck in the engine.

Some settings you could mess with to maybe speed things up:

PhysicsSimulator.Iterations: if you reduce this things will become less accurate for things like stacking and such, but for some games this doesn't matter.
PhysicsSimulator.MaxCollisionsToDetect: this sets a max on how many collsisions will be detected between any two given bodies.

Dec 26, 2007 at 5:39 PM
If the application consist of mostly all circles, or a large number of circles... I wonder if the physics system could be modified to deal with circles as a special case? If I understand farseer correctly - those circles are currently being converted to polygons having n-segments and collision's are being handled using distant grids... this makes the narrow-phase more expensive than needed (knowing that the application is "circle" heavy)... it seems like you might get a big performance boost if you could hack in special support for circles as circle-collision testing should be very cheap by way of comparison... I haven't really delve into the code so it might not be a very practical change. Can anyone comment?
Dec 27, 2007 at 9:00 AM
That's a very good suggestion!

I am getting good enough performance at the moment from farseer (as I am writing the AI code at the moment, it is very processor heavy and easily a bigger bottleneck).

If I get to the point where the AI is lighter, I may well investigate how I could move to circle-circle testing.

(I will have some non-circles, for my terrain).

I will also be looking at removing all the rotation code (as I am probably going to completly ignore the farseer bodies rotation).

Happy Christmas all!