Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is b2Body::SetUserData deprecated

Tags:

c++

box2d

I'm setting up a box2d body, using some old code for reference, in my old code I have right at the end of setting up the body, this line

body->SetUserData(this);

and if I look at the box2d source code, I can find this function

inline void b2Body::SetUserData(void* data)
{
    m_userData = data;
}

however when I try set this user data in my new project (using possibly a more up-to-date version of box2d), the function just does not exist.

Has the function been deprecated? Or have I somehow managed to remove a function that should be there?

like image 952
Jay Avatar asked Sep 14 '25 13:09

Jay


1 Answers

After further investigation I found the function had been depracated, as the set up for user data had been changed to have a wrapper struct.

the old set up was as follows:

class b2Body
{
public:
    /// Get the user data pointer that was provided in the body definition.
    void* GetUserData() const;

    /// Set the user data. Use this to store your application specific data.
    void SetUserData(void* data);
 
private:
    void* m_userData;

};

inline void b2Body::SetUserData(void* data)
{
    m_userData = data;
}

inline void* b2Body::GetUserData() const
{
    return m_userData;
}

However this has now been changed to:

class B2_API b2Body
{
public:
    /// Get the user data pointer that was provided in the body definition.
    b2BodyUserData& GetUserData();

private:
    b2BodyUserData m_userData;

};

inline b2BodyUserData& b2Body::GetUserData()
{
    return m_userData;
}

Where this struct b2BodyUserData is defined as

struct B2_API b2BodyUserData
{
    b2BodyUserData()
    {
        pointer = 0;
    }

    /// For legacy compatibility
    uintptr_t pointer;
};

So the method to set user data no longer requires SetUserData(), as GetUserData() returns a non-const reference to this struct which can be modified, to give the same functionality.

like image 74
Jay Avatar answered Sep 16 '25 05:09

Jay