mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Update userdata stuff to how new box2d wants it
This commit is contained in:
@@ -379,7 +379,7 @@ public:
|
|||||||
b2BodyUserData& GetUserData();
|
b2BodyUserData& GetUserData();
|
||||||
|
|
||||||
/// Set the user data. Use this to store your application specific data.
|
/// Set the user data. Use this to store your application specific data.
|
||||||
void SetUserData(b2BodyUserData& data);
|
void SetUserData(void* data);
|
||||||
|
|
||||||
/// Get the parent world of this body.
|
/// Get the parent world of this body.
|
||||||
b2World* GetWorld();
|
b2World* GetWorld();
|
||||||
@@ -736,11 +736,6 @@ inline b2BodyUserData& b2Body::GetUserData()
|
|||||||
return m_userData;
|
return m_userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void b2Body::SetUserData(b2BodyUserData& userData)
|
|
||||||
{
|
|
||||||
m_userData = userData;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void b2Body::ApplyForce(const b2Vec2& force, const b2Vec2& point, bool wake)
|
inline void b2Body::ApplyForce(const b2Vec2& force, const b2Vec2& point, bool wake)
|
||||||
{
|
{
|
||||||
if (m_type != b2_dynamicBody)
|
if (m_type != b2_dynamicBody)
|
||||||
|
|||||||
@@ -158,9 +158,6 @@ public:
|
|||||||
/// store your application specific data.
|
/// store your application specific data.
|
||||||
b2FixtureUserData& GetUserData();
|
b2FixtureUserData& GetUserData();
|
||||||
|
|
||||||
/// Set the user data. Use this to store your application specific data.
|
|
||||||
void SetUserData(b2FixtureUserData& userData);
|
|
||||||
|
|
||||||
/// Test a point for containment in this fixture.
|
/// Test a point for containment in this fixture.
|
||||||
/// @param p a point in world coordinates.
|
/// @param p a point in world coordinates.
|
||||||
bool TestPoint(const b2Vec2& p) const;
|
bool TestPoint(const b2Vec2& p) const;
|
||||||
@@ -283,11 +280,6 @@ inline b2FixtureUserData& b2Fixture::GetUserData()
|
|||||||
return m_userData;
|
return m_userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void b2Fixture::SetUserData(b2FixtureUserData& userData)
|
|
||||||
{
|
|
||||||
m_userData = userData;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline b2Body* b2Fixture::GetBody()
|
inline b2Body* b2Fixture::GetBody()
|
||||||
{
|
{
|
||||||
return m_body;
|
return m_body;
|
||||||
|
|||||||
@@ -139,9 +139,6 @@ public:
|
|||||||
/// Get the user data pointer.
|
/// Get the user data pointer.
|
||||||
b2JointUserData& GetUserData();
|
b2JointUserData& GetUserData();
|
||||||
|
|
||||||
/// Set the user data pointer.
|
|
||||||
void SetUserData(b2JointUserData& userData);
|
|
||||||
|
|
||||||
/// Short-cut function to determine if either body is enabled.
|
/// Short-cut function to determine if either body is enabled.
|
||||||
bool IsEnabled() const;
|
bool IsEnabled() const;
|
||||||
|
|
||||||
@@ -223,11 +220,6 @@ inline b2JointUserData& b2Joint::GetUserData()
|
|||||||
return m_userData;
|
return m_userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void b2Joint::SetUserData(b2JointUserData& userData)
|
|
||||||
{
|
|
||||||
m_userData = userData;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool b2Joint::GetCollideConnected() const
|
inline bool b2Joint::GetCollideConnected() const
|
||||||
{
|
{
|
||||||
return m_collideConnected;
|
return m_collideConnected;
|
||||||
|
|||||||
@@ -123,23 +123,8 @@ inline void b2Log(const char* string, ...)
|
|||||||
#endif // B2_USER_SETTINGS
|
#endif // B2_USER_SETTINGS
|
||||||
|
|
||||||
void loveAssert(bool test, const char* teststr);
|
void loveAssert(bool test, const char* teststr);
|
||||||
|
|
||||||
#define b2Assert(A) loveAssert((A), #A)
|
#define b2Assert(A) loveAssert((A), #A)
|
||||||
|
|
||||||
namespace love {
|
|
||||||
namespace physics {
|
|
||||||
namespace box2d {
|
|
||||||
struct bodyudata;
|
|
||||||
struct fixtureudata;
|
|
||||||
struct jointudata;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define b2BodyUserData love::physics::box2d::bodyudata*
|
|
||||||
#define b2FixtureUserData love::physics::box2d::fixtureudata*
|
|
||||||
#define b2JointUserData love::physics::box2d::jointudata*
|
|
||||||
|
|
||||||
#include "b2_common.h"
|
#include "b2_common.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ Body::Body(World *world, b2Vec2 p, Body::Type type)
|
|||||||
udata->ref = nullptr;
|
udata->ref = nullptr;
|
||||||
b2BodyDef def;
|
b2BodyDef def;
|
||||||
def.position = Physics::scaleDown(p);
|
def.position = Physics::scaleDown(p);
|
||||||
def.userData = udata;
|
def.userData.pointer = (uintptr_t)udata;
|
||||||
body = world->world->CreateBody(&def);
|
body = world->world->CreateBody(&def);
|
||||||
// Box2D body holds a reference to the love Body.
|
// Box2D body holds a reference to the love Body.
|
||||||
this->retain();
|
this->retain();
|
||||||
@@ -529,7 +529,7 @@ int Body::setUserData(lua_State *L)
|
|||||||
if (udata == nullptr)
|
if (udata == nullptr)
|
||||||
{
|
{
|
||||||
udata = new bodyudata();
|
udata = new bodyudata();
|
||||||
body->SetUserData(udata);
|
body->GetUserData().pointer = (uintptr_t)udata;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!udata->ref)
|
if(!udata->ref)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ Fixture::Fixture(Body *body, Shape *shape, float density)
|
|||||||
udata->ref = nullptr;
|
udata->ref = nullptr;
|
||||||
b2FixtureDef def;
|
b2FixtureDef def;
|
||||||
def.shape = shape->shape;
|
def.shape = shape->shape;
|
||||||
def.userData = udata;
|
def.userData.pointer = (uintptr_t)udata;
|
||||||
def.density = density;
|
def.density = density;
|
||||||
fixture = body->body->CreateFixture(&def);
|
fixture = body->body->CreateFixture(&def);
|
||||||
this->retain();
|
this->retain();
|
||||||
@@ -262,7 +262,7 @@ int Fixture::setUserData(lua_State *L)
|
|||||||
if (udata == nullptr)
|
if (udata == nullptr)
|
||||||
{
|
{
|
||||||
udata = new fixtureudata();
|
udata = new fixtureudata();
|
||||||
fixture->SetUserData(udata);
|
fixture->GetUserData().pointer = (uintptr_t)udata;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!udata->ref)
|
if(!udata->ref)
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ float Joint::getReactionTorque(float dt)
|
|||||||
|
|
||||||
b2Joint *Joint::createJoint(b2JointDef *def)
|
b2Joint *Joint::createJoint(b2JointDef *def)
|
||||||
{
|
{
|
||||||
def->userData = udata;
|
def->userData.pointer = (uintptr_t)udata;
|
||||||
joint = world->world->CreateJoint(def);
|
joint = world->world->CreateJoint(def);
|
||||||
world->registerObject(joint, this);
|
world->registerObject(joint, this);
|
||||||
// Box2D joint has a reference to this love Joint.
|
// Box2D joint has a reference to this love Joint.
|
||||||
@@ -202,7 +202,7 @@ int Joint::setUserData(lua_State *L)
|
|||||||
if (udata == nullptr)
|
if (udata == nullptr)
|
||||||
{
|
{
|
||||||
udata = new jointudata();
|
udata = new jointudata();
|
||||||
joint->SetUserData(udata);
|
joint->GetUserData().pointer = (uintptr_t)udata;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!udata->ref)
|
if(!udata->ref)
|
||||||
|
|||||||
Reference in New Issue
Block a user