Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Farseer Physics Engine settings to improve performances

I have sucessfully used Farseer to develop one of my game using XNA. The game runs like a charm in Windows and WP7. I'm currently working on porting my game in IOS using Monotouch and Monogame. I've sucessfully compiled and used Farseer also over the first version of my game ported over Monotouch and Monogame. All works fine except for performances. The game runs much more slower on the iPhone device. I did some code investigations and it seems that the major bottleneck is Farseer. It become really slow when it has to manage more then 5-6 bodies with a single fixture attached (circle).

Reading the documentation I noticed that to tune Farseer I could change values from the Setting static class:

Performance

In order to get the most out of the engine, you should try and follow the guidelines below:

Enable sleeping Sleeping enables you to have large number of bodies in the world. It can also increase the stability of the engine since small movements in a stack of bodies don’t spread in the stack. A sleeping body has little overhead, so enabling it is recommended.

Disable CCD Continuous Collision Detection prevents tunneling but at the cost of performance. If you don’t have problems with tunneling, you should disable CCD all together.

Minimize the number of position and velocity iterations A high number of iterations makes the engine more stable at the cost of performance. You should tweak the values to fit your game.

The bad news is that if I change any value of that class, nothing seems to happen. I tried to change values as follow:

EnableDiagnostics = false
VelocityIterations = 6
PositionIterations = 2
ContinuousPhysics = false

I tried also with lower values like VelocityIterations = 1 but nothing seems to change....

Anyone have already changed Settings class values to improve performances?

like image 272
Francesco Avatar asked Nov 28 '11 09:11

Francesco


1 Answers

Ok,

I have managed this. The major bottlenek was not related to Farseer. Once I solved all performance issues related to my "bad code", tuning Farseer like described above works very well to gain 5-10% of performances.

My game is written in XNA, ported to iOS an Android with monotouch and mono4android sucessfully.

like image 55
Francesco Avatar answered Nov 12 '22 10:11

Francesco