What to do for lag?

Jan 26, 2011 at 4:50 AM

I have some reasonaby complex scenes set up in Farseer and I'm finding when collisions occur in the scene there is a lot of lag (on WP7 only).

For example I have a scene like this: http://i.imgur.com/eaBRc.png


And I drop something like a box on it, there is considerable lag until all the objects stop moving. This doesn't happen on the PC which has led me to believe it's a performance issue.

So I was wondering what I could do to improve performance in situations like this? As far as I can see other games like angry birds have scenes as complex as this if not more so set up fine and run fine...

Jan 26, 2011 at 11:07 AM

Most games that run on mobile devices are really, really simple. Take angry bird for example: It is a couple of circles (birds) and rectangle (obstacles). Precision is not in focus, and thus you can take some shortcuts.

Try the following in Settings.cs:

- Disable CCD
- Lower the number of iterations (VelocityIterations and PositionIterations)
- Try setting ConserveMemory to true - it is untested, so beware.

You also need to test performance in release mode and remember to set Setting.EnableDiagnostics to false when you release.

The only other thing you can do is to minimize the number of active bodies.

Jan 27, 2011 at 1:40 AM

Also be sure to set IsFixedTimeStep to false.

Jan 27, 2011 at 11:58 AM

Ah cool thanks for the advice guys. Seems like the biggest draw back has been the number of bodies (unfortunately). It might just be my crappy code but it doesn't look like the game can hold up scenes as complex as angry birds without lagging, still close though.

Jun 30, 2011 at 3:08 AM

Did you end up fixing this? I'm getting lag / frame rate drop in some situations that aren't overly complicated. 

Jun 30, 2011 at 12:07 PM

I didn't really ever manage to fully improve the fps but some things which helped were lowering the velocity iterations to 3 and physics iterations to 1 and doing two physics updates in the same frame. I also disabled continuosphysics (setting it to false in settings) and that helped quite a bit.

Then I went and started optimizing the crap out of everything else in the game including the way I was drawing sprites, switching to sprite sheets helped a lot. In the end what really helped was I improved the rest of the games performance so much that the slow downs in farseer weren't lowering the games fps to below 30.