This project is read-only.

Safe dynamic object count?

Aug 10, 2010 at 1:00 PM

Hi - 

 

I've been playing around with Box2D.XNA for a couple months now, and first off I'd like to thank everyone involved in this project! Everything has worked so great so far.

Now, on to business...  

 

I've built a project that runs flawlessly on PC (even older slow PCs) however when I deploy to xbox I'm starting to have performance issues. I'm currently running a scene with one static body and up to 80 dynamic bodies. I've run a profiler and it looks that the slowness I'm experiencing is coming from PhysicsWorld.Step(). I've tried lowering the iterations (2,2) and allowed bodies to go to sleep which has helped a little, but really just made everything more bouncy. Before I continue on and try to make this work I wanted to make sure that I'm not trying to overcome a known limitation. 

I tried searching ye ol' google, and the discussions here and can't seem to find an answer. What would be a safe number of dynamic Bodies that would give good performance on xbox? 

Aug 23, 2010 at 10:08 PM

Hello,

 

I currently have a game with up to 100 dynamic bodies -- it runs at 60 fps on the 360.

 

What I would do is run your game on the PC with a CPU time profiler (Red Gate ANTS performance profiler, for instance). This will give you more accurate results. When profiling, you should disable rendering and disregard idle time (because I assume your PC is faster). The percentage of time spent in each method should be consistent between PC and XBox.

This can tell you what parts of the Step call are giving you problems. Depending on the results, you may want to optimize parts of your code. For instance, if you learn that callbacks (BeginContact, etc) are the issue, you might want to optimize that logic and/or fix up your collision filtering to minimize callbacks.

 

Hope this helps

Aug 24, 2010 at 10:54 PM

Thank you for the response :)

 

Before I was just wondering if what I was doing was even possible with the physics system since I really couldn't find a rough object count anywhere or any detailed case stories. Given, I know that the number can change dramatically if using constraints and complex bodies and shapes, but was just looking for some of the results others have had.

I ended up putting together a basic app with the same objects I was using however I took all logic and drawing code out and had interesting results! I used (1) Fixed Body with (4) box fixtures to make up a main container. With all the settings I mentioned previously I was able to get anywhere from 160 to 220 bodies without dropping below the fixed 60FPS, which I thought was a big difference in tests when there is no other logic to slow it down, the hardware isn't changing, any nothing else (that I know of) is happening on the XBOX. So then I went to drawing them using instancing and saw something interesting. The more bodies that shared a contact with the fixed body, the less overall bodies it would run! This made me wonder that maybe things are slowing due to the large number of contacts on the large fixed body? The next thing I was going to try to test this theory was either more bodies and/or more fixtures to make up that fixed container to see if that would either speed it up or give a little more constant result. However I haven't gotten around to testing that quite yet, but I'll post my results when I do if anyone is interested.

Yeah, I've gone back through every bit of my code and I'm squeezing everything I can out by minimizing floating point calcs, offloading processing to the GPU, using model instancing, etc. to give the physics system more of the CPU. I've made great strides and I think I will have a totally different result next time I get to deploy to my xbox.