isTangible or remove from space

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

isTangible or remove from space

Post by imtrobin »

Hi

My game is using a memory pool to avoid memory fragmentation, which is preallocating few hundred objects, each with an Entity. When they are not active, they are disabled in the pool. Would you recommend using isTangible=false or removing them from space/adding it back in terms of performance/memory fragmentation?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: isTangible or remove from space

Post by Norbo »

It depends primarily on the frequency of entity addition and removal to the inactive pool and the size of the pool. Adding or removing entities from the space does have an overhead (a large part of that being in the broadphase add/remove which is called internally). If you're only adding/removing a few dozen entities per frame, that should be fine. If the pool is only intangible, they still undergo most of the same computations as a normal entity. This includes broadphase collision detection, but not narrow phase collision detection. If the pool has to be very large, this may start to have a performance impact. This impact may be less than that of adding/removing hundreds of entities from the space every frame.

Entity adding/removing is occasionally not allowed as well. If an 'immediate' event is used which is called directly from within the engine, trying to add/remove an entity can cause issues. You could buffer these adds/removes until the end of the space update, but it adds a bit more complexity. Setting the isTangible flag should be pretty much OK from any context.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: isTangible or remove from space

Post by imtrobin »

I see. It seems to be me now that the isTangible is a bit like kinematic property on PhysX. Perhaps there could be a isEnabled flag that will ignore broadphase calculations too.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: isTangible or remove from space

Post by Norbo »

As part of the planned modifications to the collision validation system, there should be some sort of control over whether an entity is managed by the broad phase or not.

Also, in my previous post, I neglected to mention that you can in fact force an entity into a deactivated state by using (Entity).deactivate(). Entities in this state will skip essentially all normal processing. The broadphase still takes into account these entities, however.

Settling objects will naturally enter a deactivated state to speed things up. If you move the entities out away from your simulation zone, set their tangibility to false, and turned off gravity for those entities, they would likely go to sleep by themselves.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: isTangible or remove from space

Post by imtrobin »

Thanks. I will do that then.
Post Reply