Box2D Forums

It is currently Fri May 24, 2013 5:01 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Feb 12, 2008 1:53 pm 
Offline

Joined: Wed Jan 23, 2008 1:04 pm
Posts: 85
Location: Classified
In the project I am working on I was intending to use a rather large compound shape for a tile map... this object will always be asleep. However, it just occured to me that since in most cases a large portion of it will be out of screen, I might be better off having every tile an individual sleeping object... so that I could (somehow) get it to completely ignore the ones out of screen (I was going to have NPCs fall asleep at screen out). What would be the best way to handle a tile map? ... I felt I should ask before my code becomes committed.


Top
 Profile  
 
PostPosted: Tue Feb 12, 2008 2:11 pm 
Offline

Joined: Mon Dec 17, 2007 10:11 pm
Posts: 185
I am not an expert on the matter, but I think you would have to have a lot of static objects to really see a performance hit. The sweep and prune broadphase is very nice for this type of thing, because from what I understand it doesn't have to do any resorting for static objects. So unless there are dynamic objects present and overlapping their AABBs you will get very little performance hit from even 10s of thousands of these. I would personally just create a very simple loop to generate a ton of static boxes, have a dynamic object that can move around and see what performance is like. If your world is going to be enormous then I would highly recommend going with some type of system where you load/unload objects as they go a certain distance off-screen. I think this would be necessary just because of the time needed to create all of these objects upon loading.


Top
 Profile  
 
PostPosted: Tue Feb 12, 2008 4:02 pm 
Offline

Joined: Wed Jan 23, 2008 1:04 pm
Posts: 85
Location: Classified
While I will point out that the project has to run well on a platform with dual 200mhz ARM processors, as opposed to whatever a normal computer would have... what your saying is that you think I would be best off with a bunch of sleeping objects that are more or less destroyed and created when they are needed? Or perhaps (opposed to what your saying) I would be better off redefining an object's compound shape, defining the shape only where its needed.


Top
 Profile  
 
PostPosted: Wed Feb 13, 2008 7:24 am 
Offline

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1911
As far as I understand it, you should see pretty little performance difference between one static body with many shapes, and many static bodies with one shape; as far as the broad phase is concerned, this is no different.

Now that in 2.0 you can add and remove shapes to a body, there is really little reason to go one way or another. Having one body probably slightly better, but the overheads for adding and removing shapes might be worse for all I know.

Whether you need to dynamically add or remove shapes or can just put them all in at once does depend on your specs, but I think the sweep and prune thing means you have to have really quite large dimensions before it becomes a problem. I would second trying the naïve approach first to actually check there is a problem.

Another option is to rewrite the broadphase manager to treat your tiles as a special case. It is obviously much easier to determine which tiles an AABB is overlapping that it is for other arbitrary rectangles, and you can take advantage of that to have pretty much limitless amounts of static tiles inside the world.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group