Performance issue in my game? Not sure, can someone test it and let me know?

Mar 1, 2011 at 4:26 AM
Edited Mar 1, 2011 at 1:06 PM

Hi Guys,

I made the game 'Chicks'n'Vixens' using Farseer for the physics engine. I'm still a bit concerned about performance, does anyone find performance issues with the game (it's free on WP7)? hardly anyone seems to complain about performance but when I play I occasionally find the game stuttering and sometimes just going into the low 20s. Anyone who has played Angry Birds on the iPhone know how it compares? I'm just sturggling with figuring out how to optimize it properly because if I turn of CCD I'm finding the various bodies are being ushed into one another and slowly push themselves out, if the weight on them is too great they might even fall through the object they're sitting on. Even with CCD off I still notice lag spikes when collisions happen between a certain number of bodies so yeah, it's a bit worrying :-\

My other question is, since Farseer is derived from the Box2D engine is its performance comparable or is it slower/faster than Box2D? What about the behaviour of the physics?

Oh and one more question, is it ok if I use the farseer physics logo in a 'credits' page in the game?


Thanks for any help!

Coordinator
Mar 4, 2011 at 8:48 PM

What range of density values are you using? What is your timestep? The engine works without CCD unless you are using insane values.

FPE 3.2 is actually faster than Box2D. The tests I've made includes the whole testbed framework and results may vary from platform to platform and with different compilers, but FPE is definitely not slower than Box2D. The behavior between the two engines are identical.

As for the logo; yes, you can use it.

Mar 5, 2011 at 2:42 AM

Hi. 
First, let me tell you that I really like Chicks'n'Vixens!

Now, Are you using the official 3.2 release?
The problem we had with our WP7 game is that farseer CCD generates garbage and causes the garbage collector to hit a couple of times every frame.
In your case it won't happed that ofter, it depends on the number of fixtures.

Hopefully, the problem was located in a single function, so I wrote a pool to reuse the objects.

The problem was fixed in a later farseer build by replacing the objects with structs and a new algorithm.
You might wanna grab the latest source and check it out. Make sure you keep an eye for bug fixes until the official 3.3.

 

 

Mar 6, 2011 at 8:41 AM
Edited Mar 6, 2011 at 8:44 AM

Genbox wrote:

What range of density values are you using? What is your timestep? The engine works without CCD unless you are using insane values.

FPE 3.2 is actually faster than Box2D. The tests I've made includes the whole testbed framework and results may vary from platform to platform and with different compilers, but FPE is definitely not slower than Box2D. The behavior between the two engines are identical.

As for the logo; yes, you can use it.

I update like so:

world.Step(Math.Min((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f,
                                        (1f / 30f)));

 

I don't change any density values (they're all set to 1), I do play around with the mass value but I don't have anything which ever really goes above 20. Ideally I only want the chickens to have CCD enabled because they can move very fast at points.

 

Really good to know farseer is faster than Box2D, at least I know I'm not at a disadvantage here :D

 

nkast wrote:

Hi. 
First, let me tell you that I really like Chicks'n'Vixens!

Now, Are you using the official 3.2 release?
The problem we had with our WP7 game is that farseer CCD generates garbage and causes the garbage collector to hit a couple of times every frame.
In your case it won't happed that ofter, it depends on the number of fixtures.

Hopefully, the problem was located in a single function, so I wrote a pool to reuse the objects.

The problem was fixed in a later farseer build by replacing the objects with structs and a new algorithm.
You might wanna grab the latest source and check it out. Make sure you keep an eye for bug fixes until the official 3.3.

 

 

 I use the 3.2 release, and yeah I don't like using CCD the way I do...

Mar 10, 2011 at 9:29 AM

Perhaps you can disable CCD and use tight timesteps.

Instead of calling word.Step(0.03333) once  every update, try to step multiple times, like:

word.Step(0.01666);
word.Step(0.01666);

or 

word.Step(0.01111);
word.Step(0.01111);
word.Step(0.01111);

or

word.Step(0.00833);
word.Step(0.00833);
word.Step(0.00833);
word.Step(0.00833); 

With small steps like those you might not need CCD. I am not sure at what point that aproach start to get slower that CCD.
In my game (one bullet and lots of static bodies) I manage to call farseer twice every frame with CCD on.

Another thought..
Have you profiled it? See the link bellow. Besides Update & Draw override EndDraw and put a ProfileMarker there as well.

http://blogs.msdn.com/b/shawnhar/archive/2009/07/07/profiling-with-stopwatch.aspx 


protected override void EndDraw()
{
            using (new ProfileMarker(endDrawProfiler)) {  base.EndDraw(); }
}

What are your readings? If draw & afterDraw takes more than 30%-40% you can consentrate on optimizing drawing.

 





 
 

Mar 16, 2011 at 9:13 AM

Your idea to have multiple but smaller timesteps seems to have helped, I've also found that if I reduce the velocityiteration/position iterations and couple it with two half updates per update cycle I don't lose much in stability but gain a little in performance.

So thanks for that suggestion!!