At the moment, each joint type is in core, i.e. it is an intrinsic part of the box2d engine. It is not possible to add more without editing files in the Box2D folder. This is undesirable if we want to allow contribution joints, and easy hackability. I know of two prospective joints: Jorrit Rouwe's FixedJoint (in SVN), and Mike Lewis's Top Down Dry Friction Joint. There are several more potential joints, some are described in the TODO list.
I propose the following simple changes, which I designed for use with controllers, but the same principle applies.
Basically, joints are currently constrained to a finite set because they are part of an enumeration. If all uses of this enumeration were eliminated, and virtual methods used instead, there would be no problem.
Fortunately, the enumeration is only used in one place: b2Joint::Create. I suggest refactoring this by adding the following method to b2JointDef.
Note this requires some forward declarations to work properly. It may be a good to provide an abstract interface to the allocator. At the least, it makes box2d's memory allocation a non-private detail. As only experienced users should be creating joints, and it is extending functionality rather than using functionality, I'd like to refer to allocators in box2d as of protected visibility (as opposed to public/private). They would not need to be documented to the extent of Box2D's public interface. The virtual methods of b2Joint should have a similar protected status.
Also note this makes b2JointDef a polymorphic class. I think this appropriate, as it already was in effect, using the mechanism of b2JointDef::type.
The joint enumeration values would remain, as they are useful for determining the type of a joint at runtime. For contributed joints, GetType should either return e_unknownJoint (forcing dynamic_cast, or userdata information to be used to safely downcast the joint), or the user is responsible for ensuring that it returns a unique value, and that the value makes sense. Joints added to contribution will be assigned GetType values in some special range.
The performance impact is an extra virtual function call on joint creation. I think that can safely be assumed to be negligible.
Compatibility issues are very low. It is unlikely any user code will be broken by this change. Thus, I do not think it necessary to block 2.1's release on this proposal.
I estimate the changes to be simple to make, but I have not prepared a sample patch.
Please post any comments, and if you think it a good idea. I shall post an issue to the tracker once I'm satisfied there is no further discussion being made here.
I propose the following simple changes, which I designed for use with controllers, but the same principle applies.
Basically, joints are currently constrained to a finite set because they are part of an enumeration. If all uses of this enumeration were eliminated, and virtual methods used instead, there would be no problem.
Fortunately, the enumeration is only used in one place: b2Joint::Create. I suggest refactoring this by adding the following method to b2JointDef.
Code:
virtual b2Joint* Create(b2BlockAllocator* allocator) const = 0;
Each class deriving from b2JointDef contains the corresponding bit of b2Joint::Create.Note this requires some forward declarations to work properly. It may be a good to provide an abstract interface to the allocator. At the least, it makes box2d's memory allocation a non-private detail. As only experienced users should be creating joints, and it is extending functionality rather than using functionality, I'd like to refer to allocators in box2d as of protected visibility (as opposed to public/private). They would not need to be documented to the extent of Box2D's public interface. The virtual methods of b2Joint should have a similar protected status.
Also note this makes b2JointDef a polymorphic class. I think this appropriate, as it already was in effect, using the mechanism of b2JointDef::type.
The joint enumeration values would remain, as they are useful for determining the type of a joint at runtime. For contributed joints, GetType should either return e_unknownJoint (forcing dynamic_cast, or userdata information to be used to safely downcast the joint), or the user is responsible for ensuring that it returns a unique value, and that the value makes sense. Joints added to contribution will be assigned GetType values in some special range.
The performance impact is an extra virtual function call on joint creation. I think that can safely be assumed to be negligible.
Compatibility issues are very low. It is unlikely any user code will be broken by this change. Thus, I do not think it necessary to block 2.1's release on this proposal.
I estimate the changes to be simple to make, but I have not prepared a sample patch.
Please post any comments, and if you think it a good idea. I shall post an issue to the tracker once I'm satisfied there is no further discussion being made here.