Closed flarn2006 closed 3 years ago
Do you have a suggestion on how to offer the new feature for user data without breaking compatibility? Also fixing this in user code is likely to take about 5 minutes.
@erincatto this way seems more backwards compatible. https://github.com/erincatto/box2d/pull/635
Yes, I know, but it might not be as trivial for someone who's compiling someone else's inactive project but doesn't really know C++ themselves.
As for how I'd suggest doing it, I'm not entirely sure what the goal is, or
how it all works under the hood, but I'd suggest, first off, re-adding the
SetUserData(void*)
functions. Then, maybe define
b2BodyUserData::b2BodyUserData(void*)
and b2BodyUserData::operator void*()
to do the appropriate conversions, along with the same for
b2FixtureUserData
. Do you think that would be enough?
EDIT: This was in response to @erincatto, not thegrb93.
Sorry, I don't think that will work when people define their own user data type.
Unfortunately I have to break compatibility sometimes to support new features. Sometimes people want conflicting things. In this case someone wanted strongly typed user data. This conflicts with your desire to not break the API.
I have found strongly typed user data to be useful, so I'm inclined to keep this feature.
Setting
b2BodyDef::userData
directly to avoid*
pointer, and usingb2Body::SetUserData(void*)
, both worked in version 2.4.0 of the library. Now that that's been changed, code that was written for the older versions will no longer compile and/or link. Sometimes it's necessary to break backwards compatibility, of course, but ideally it should be avoided where possible, and it seems unlikely that this is the best option here.