Tiled game efficiency questions

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
diadem
Posts: 10
Joined: Sat Jan 17, 2009 4:19 am

Tiled game efficiency questions

Post by diadem »

My game world is based off a procedurally generated 2d map.Image

What is the best way to make my static world? Right now I'm adding all of the road tiles to a static group. If the tiles touch, the game grinds to a halt. If they have some space between them, the game runs full speed, even with hundreds of tiles.

What is the best way to add them? Should I group them into sets of convexhulls or a compound bodies? Since they never move, should I just make one massive glob and find out how to put it in a terrain? Should I just keep on doing what I'm doing and make sure there's no contact between them? Is making them contact fine if only a few dozens tiles exist at a time? Is adding and removing objects too rapidly counterproductive because of the GC?

Image
What about the ground? Right now I'm just using 400x400 boxes for the floor and tiling them. Is there a better way?

Finally, how bad is it to add static objects away form all the action? Do I need to make a thread that removes objects that are far from the player's view and re-adds them when he/she gets closer? Would putting the far objects to sleep be enough? Or does the engine take care of all of that on its own because it only cares about grids that have active objects in them?

edit: This is for the 360.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Tiled game efficiency questions

Post by Norbo »

Adding the tile entities to a StaticGroup and letting it manage them should work. When using a static group, make sure you don't also add the box entities to the space since the StaticGroup will add/remove boxes to the space as necessary. 400x400 (160,000) boxes is going to take quite a while to initialize no matter what, though. To make it work with boxes specifically, you might have to defer the box creation until needed (unlike the StaticGroup which has the entities already made and just adds them to the space when necessary).

I'm not really clear on the requirements of your game, but I would definitely look into the Terrain if you can use it or the StaticTriangleGroup. Instead of boxes, you could represent the tiles with two triangles each. These vertices/indices would then be handed to a StaticTriangleGroup which then creates and handles triangles as necessary (which will be much faster initialization wise than the StaticGroup with 160,000 boxes).
diadem
Posts: 10
Joined: Sat Jan 17, 2009 4:19 am

Re: Tiled game efficiency questions

Post by diadem »

Backstory:
I ended up actually just using a normal map. I used the demo's playground as an example for a statictrianglegroup. It took a few hours to get the model in the right format. I tried almost every setting with Truespace, Milk, etc, but the directX exports all had various issues with collision detection.

Eventually I installed SoftImage and exported as an FBX file and the world seemed relatively solid.

It gave me this:
Image
Image
Image

Problem:
The world's fine for the most part, but I'm still having a few issues I can't work out.
- If I drive my car to certain areas, the physics performance gets killed. For example, I can drive on the grass in the above image fine, but as soon as I reach the dirt everything stops to a few fps. If I drive towards a hospital, performance slows. As soon as I go under an archway (part of the hospital), performance is restored to almost perfect.

The only objects that exist are the world and the car.

The speed is not only effected by what I drive on, but how close I am to certain houses (all part of the same statictrainglegroup).

- There are still certain parts of the world that aren't solid. 99% of the area is fine (I can even drive up and down a parking garage), but there are a few places that look fine when drawn but if I drive over them I'll fall through the world.

Question:
Any idea how I can remedy these issues? For the record, the phyiscs engine is running in its own thread, using the PhyiscsThread exmaple.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Tiled game efficiency questions

Post by Norbo »

I recall having a great deal of trouble with that model in the past. If you haven't already, try to use a custom content processor to extract vertices/indices from the model rather than passing a loaded Model into the initializeData method. The vertices/indices you get from a model can be given directly to a StaticTriangleGroup through another initializeData method that does essentially no preprocessing, so it's far less error prone. An example processor can be found on the XNA website (picking with per triangle accuracy) at http://creators.xna.com/en-US/sample/pickingtriangle. An extension to get the indices can be found at http://www.bepu-games.com/forums/viewto ... +processor.

If I remember right, the slowdowns you're seeing are due to some bad geometry from somewhere in the pipeline. Triangles were being created on top of other triangles in the wrong spots amongst other issues. Hopefully, using the more robust content processor method will solve the issues.
diadem
Posts: 10
Joined: Sat Jan 17, 2009 4:19 am

Re: Tiled game efficiency questions

Post by diadem »

That did the trick. I spend over six hours messing with maps and you give me a solution that takes a matter of minutes.
Post Reply