Hi,
I've made a small patch file (attached) which contains the modifications required for b2Joint, b2Body and b2Fixture to hold an any_ptr instead of void* to user data. The changes are really tiny (Just 18 lines of code modified, and any_ptr.h added to Box2D\Common). If you deem it worthy, I think it would be a nice addition to your already lovely library. It would save many a programmer from the headaches of debugging undefined behavior due to inadvertent incorrect casts.
Best Regards,
Francis Xavier
More info from the request posted at the box2d google code page:
Request
It would be nice to be able to set/retrieve user data in a type-safe manner. If user data were of type any_ptr instead of void*, a bad cast would yield a null pointer which the user can check for.
Article on any_ptr
http://www.gamedev.net/reference/programming/features/TypeSafeGenPtr/
Performance
Assuming that casting from any_ptr is not done in a tight loop, there should be no noticeable overhead in a C++ game which uses box2D. Being extremely lightweight, any_ptr does not require RTTI or exceptions to be enabled. However, the strong type-safety which any_ptr provides is sure to save some users the headache of debugging incorrectly cast void pointers.
The time/space overhead caused by the use of any_ptr is extremely tiny if not insignificant:
Edit: Please use the updated patch attached with my latest post in this thread.
I've made a small patch file (attached) which contains the modifications required for b2Joint, b2Body and b2Fixture to hold an any_ptr instead of void* to user data. The changes are really tiny (Just 18 lines of code modified, and any_ptr.h added to Box2D\Common). If you deem it worthy, I think it would be a nice addition to your already lovely library. It would save many a programmer from the headaches of debugging undefined behavior due to inadvertent incorrect casts.
Best Regards,
Francis Xavier
More info from the request posted at the box2d google code page:
Request
It would be nice to be able to set/retrieve user data in a type-safe manner. If user data were of type any_ptr instead of void*, a bad cast would yield a null pointer which the user can check for.
Article on any_ptr
http://www.gamedev.net/reference/programming/features/TypeSafeGenPtr/
Performance
Assuming that casting from any_ptr is not done in a tight loop, there should be no noticeable overhead in a C++ game which uses box2D. Being extremely lightweight, any_ptr does not require RTTI or exceptions to be enabled. However, the strong type-safety which any_ptr provides is sure to save some users the headache of debugging incorrectly cast void pointers.
The time/space overhead caused by the use of any_ptr is extremely tiny if not insignificant:
- Size of any_ptr: 1 void pointer + 1 integer (~4 bytes bigger than a void*)
- any_ptr casting overhead:
- Cast to non-const object pointer: min/max: ~1 conditional check
- Cast to const object pointer: min: ~1 conditional check, max: ~2 conditional checks
Edit: Please use the updated patch attached with my latest post in this thread.