Different callbacks for different (conceptual) body types

Discuss topics related to BEPUphysics or physics engine development.
Post Reply
Maci
Posts: 3
Joined: Mon Jul 15, 2019 8:30 am

Different callbacks for different (conceptual) body types

Post by Maci »

Hi everyone,
let's say (for simplicity) that in my game there are two types of objects that a player can provide input to, a humanoid figure and a car.
what would be the best strategy for managing different callbacks for the two object types?
If I were to "merge" the character demo callback and the car demo callbacks, what would be the easiest way to proceed?

Thanks in advance
Maci
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Different callbacks for different (conceptual) body types

Post by Norbo »

Since the callback provided CollidableReference can't contain metadata, there's going to be some form of lookup from collidable reference to custom data which can be used to choose the appropriate callback.

The 'best' form of this lookup depends on the use case- one simple option is to have an array large enough to span all handles. Each slot in that array contains information about the object either directly (if the data is small enough that having an entry for every handle isn't a problem) or through an index that points somewhere else. The custom data can contain information about the type of the object, type-specific information, and which callback should be invoked for it.

The BodyProperty<T> is used in the demos for this purpose. The RagdollDemo looks up collision filters stored in a BodyProperty to determine how to allow collisions. If you wanted different collision filter behavior for ragdolls versus vehicles, you could expand the metadata stored in the BodyProperty to match.

For simulations with sparse callback requirements, you could also use a direct conditional or perhaps a small dictionary/list to map from handle to callback data.
Post Reply